|
16 | 16 | TICKET_COUNT=$(echo "$TICKETS_JSON" | jq '. | length') |
17 | 17 | echo "Updating status for $TICKET_COUNT tickets..." |
18 | 18 |
|
19 | | -# First, we need to get the "Done" workflow state ID from Linear |
20 | | -# We'll fetch workflow states and find the one named "Done" |
21 | | -WORKFLOW_QUERY=$(cat <<'EOF' |
22 | | -{ |
23 | | - "query": "query { workflowStates { nodes { id name } } }" |
24 | | -} |
25 | | -EOF |
26 | | -) |
27 | | - |
28 | | -WORKFLOW_RESPONSE=$(curl -s -X POST \ |
29 | | - -H "Content-Type: application/json" \ |
30 | | - -H "Authorization: ${LINEAR_API_KEY}" \ |
31 | | - -d "$WORKFLOW_QUERY" \ |
32 | | - https://api.linear.app/graphql) |
33 | | - |
34 | | -DONE_STATE_ID=$(echo "$WORKFLOW_RESPONSE" | jq -r '.data.workflowStates.nodes[] | select(.name == "Done") | .id' | head -n1) |
35 | | - |
36 | | -if [ -z "$DONE_STATE_ID" ]; then |
37 | | - echo "Error: Could not find 'Done' workflow state in Linear." |
38 | | - echo "Available states:" |
39 | | - echo "$WORKFLOW_RESPONSE" | jq -r '.data.workflowStates.nodes[] | " - \(.name)"' |
40 | | - exit 1 |
41 | | -fi |
42 | | - |
43 | | -echo "Found 'Done' state ID: $DONE_STATE_ID" |
44 | | - |
45 | 19 | # Update each ticket |
46 | 20 | UPDATED_COUNT=0 |
47 | 21 | FAILED_COUNT=0 |
48 | 22 |
|
49 | 23 | for i in $(seq 0 $((TICKET_COUNT - 1))); do |
50 | 24 | TICKET_ID=$(echo "$TICKETS_JSON" | jq -r ".[$i]") |
51 | 25 |
|
52 | | - # First, get the issue ID (not the identifier like "DEV-123") |
| 26 | + # Get the issue ID, current state, and team's Done state in one query |
53 | 27 | ISSUE_QUERY=$(cat <<EOF |
54 | 28 | { |
55 | | - "query": "query { issue(id: \"$TICKET_ID\") { id identifier state { name } } }" |
| 29 | + "query": "query { issue(id: \"$TICKET_ID\") { id identifier state { name } team { states { nodes { id name } } } } }" |
56 | 30 | } |
57 | 31 | EOF |
58 | 32 | ) |
|
78 | 52 | continue |
79 | 53 | fi |
80 | 54 |
|
| 55 | + # Get the Done state ID for this issue's team |
| 56 | + DONE_STATE_ID=$(echo "$ISSUE_RESPONSE" | jq -r '.data.issue.team.states.nodes[] | select(.name == "Done") | .id' | head -n1) |
| 57 | + |
| 58 | + if [ -z "$DONE_STATE_ID" ]; then |
| 59 | + echo " [FAIL] ${TICKET_ID} - Could not find 'Done' state for issue's team" |
| 60 | + ((FAILED_COUNT++)) |
| 61 | + continue |
| 62 | + fi |
| 63 | + |
81 | 64 | # Update the issue state |
82 | 65 | UPDATE_QUERY=$(cat <<EOF |
83 | 66 | { |
|
0 commit comments