|
| 1 | +name: Disclaim Issue |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + |
| 7 | +jobs: |
| 8 | + disclaim_issue: |
| 9 | + if: github.event.issue.pull_request == null && github.event.comment.body == 'disclaim' |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Get issue details |
| 14 | + id: issue |
| 15 | + run: | |
| 16 | + curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 17 | + https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }} > issue.json |
| 18 | + cat issue.json |
| 19 | + continue-on-error: true |
| 20 | + |
| 21 | + - name: Check if the commenter is assigned to the issue |
| 22 | + id: check_assignee |
| 23 | + run: | |
| 24 | + COMMENTER="${{ github.event.comment.user.login }}" |
| 25 | + ASSIGNED=$(jq --arg user "$COMMENTER" '.assignees[]?.login | select(. == $user)' issue.json) |
| 26 | + if [ -z "$ASSIGNED" ]; then |
| 27 | + echo "not_assigned=true" >> $GITHUB_ENV |
| 28 | + else |
| 29 | + echo "not_assigned=false" >> $GITHUB_ENV |
| 30 | + fi |
| 31 | +
|
| 32 | + - name: Remove the user from the assignees |
| 33 | + if: env.not_assigned == 'false' |
| 34 | + run: | |
| 35 | + curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 36 | + -d '{"assignees":["${{ github.event.comment.user.login }}"]}' \ |
| 37 | + https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/assignees |
| 38 | +
|
| 39 | + - name: Log the unassignment result |
| 40 | + if: env.not_assigned == 'false' |
| 41 | + run: echo "User ${{ github.event.comment.user.login }} has been unassigned from the issue." |
| 42 | + |
| 43 | + - name: Retrieve the project ITEM_ID |
| 44 | + id: get_item_id |
| 45 | + run: | |
| 46 | + QUERY=$(cat <<EOF |
| 47 | + { |
| 48 | + "query": "{ repository(owner: \\"${{ github.repository_owner }}\\", name: \\"${{ github.event.repository.name }}\\") { issue(number: ${{ github.event.issue.number }}) { projectItems(first: 10) { nodes { id } } } } }" |
| 49 | + } |
| 50 | + EOF |
| 51 | + ) |
| 52 | + echo "Sending query: $QUERY" |
| 53 | +
|
| 54 | + RESPONSE=$(curl -X POST -H "Authorization: Bearer ${{ secrets.PAT_TOKEN }}" \ |
| 55 | + -H "Content-Type: application/json" \ |
| 56 | + --data "$QUERY" https://api.github.com/graphql) |
| 57 | +
|
| 58 | + echo "GraphQL Response: $RESPONSE" |
| 59 | + ITEM_ID=$(echo "$RESPONSE" | jq -r '.data.repository.issue.projectItems.nodes[0].id') |
| 60 | +
|
| 61 | + if [ -z "$ITEM_ID" ]; then |
| 62 | + echo "Error: Could not retrieve ITEM_ID" |
| 63 | + exit 1 |
| 64 | + else |
| 65 | + echo "ITEM_ID=$ITEM_ID" >> $GITHUB_ENV |
| 66 | + fi |
| 67 | +
|
| 68 | + - name: Retrieve the project FIELD_ID for "Status" |
| 69 | + id: get_field_id |
| 70 | + run: | |
| 71 | + QUERY=$(cat <<EOF |
| 72 | + { |
| 73 | + "query": "{ node(id: \\"PVT_kwHOAeZDs84ApSkY\\") { ... on ProjectV2 { fields(first: 10) { nodes { ... on ProjectV2SingleSelectField { name id } ... on ProjectV2IterationField { name id } } } } } }" |
| 74 | + } |
| 75 | + EOF |
| 76 | + ) |
| 77 | + echo "Sending query: $QUERY" |
| 78 | +
|
| 79 | + RESPONSE=$(curl -X POST -H "Authorization: Bearer ${{ secrets.PAT_TOKEN }}" \ |
| 80 | + -H "Content-Type: application/json" \ |
| 81 | + --data "$QUERY" https://api.github.com/graphql) |
| 82 | +
|
| 83 | + echo "GraphQL Response: $RESPONSE" |
| 84 | + FIELD_ID=$(echo "$RESPONSE" | jq -r '.data.node.fields.nodes[] | select(.name == "Status").id') |
| 85 | +
|
| 86 | + if [ -z "$FIELD_ID" ]; then |
| 87 | + echo "Error: Could not retrieve FIELD_ID for Status" |
| 88 | + exit 1 |
| 89 | + else |
| 90 | + echo "FIELD_ID=$FIELD_ID" >> $GITHUB_ENV |
| 91 | + fi |
| 92 | +
|
| 93 | + - name: Retrieve the "Unclaimed" option ID |
| 94 | + id: find_unclaimed_tasks_id |
| 95 | + run: | |
| 96 | + QUERY=$(cat <<EOF |
| 97 | + { |
| 98 | + "query": "{ node(id: \\"PVT_kwHOAeZDs84ApSkY\\") { ... on ProjectV2 { fields(first: 10) { nodes { ... on ProjectV2SingleSelectField { name options { id name } } } } } } }" |
| 99 | + } |
| 100 | + EOF |
| 101 | + ) |
| 102 | + echo "Sending query: $QUERY" |
| 103 | +
|
| 104 | + RESPONSE=$(curl -X POST -H "Authorization: Bearer ${{ secrets.PAT_TOKEN }}" \ |
| 105 | + -H "Content-Type: application/json" \ |
| 106 | + --data "$QUERY" https://api.github.com/graphql) |
| 107 | +
|
| 108 | + echo "GraphQL Response: $RESPONSE" |
| 109 | + UNCLAIMED_TASKS_ID=$(echo "$RESPONSE" | jq -r '.data.node.fields.nodes[] | select(.name == "Status") | .options[] | select(.name == "Unclaimed").id') |
| 110 | +
|
| 111 | + if [ -z "$UNCLAIMED_TASKS_ID" ]; then |
| 112 | + echo "Error: Could not retrieve 'Unclaimed' ID" |
| 113 | + exit 1 |
| 114 | + else |
| 115 | + echo "UNCLAIMED_TASKS_ID=$UNCLAIMED_TASKS_ID" >> $GITHUB_ENV |
| 116 | + fi |
| 117 | +
|
| 118 | + - name: Move task to "Unclaimed" column |
| 119 | + run: | |
| 120 | + QUERY=$(cat <<EOF |
| 121 | + { |
| 122 | + "query": "mutation { updateProjectV2ItemFieldValue(input: { projectId: \\"PVT_kwHOAeZDs84ApSkY\\", itemId: \\"$ITEM_ID\\", fieldId: \\"$FIELD_ID\\", value: { singleSelectOptionId: \\"$UNCLAIMED_TASKS_ID\\" } }) { projectV2Item { id } } }" |
| 123 | + } |
| 124 | + EOF |
| 125 | + ) |
| 126 | + curl -X POST -H "Authorization: Bearer ${{ secrets.PAT_TOKEN }}" \ |
| 127 | + -H "Content-Type: application/json" \ |
| 128 | + --data "$QUERY" \ |
| 129 | + https://api.github.com/graphql |
| 130 | +
|
| 131 | + - name: Log the project card movement result |
| 132 | + run: echo "Task successfully moved to 'Unclaimed' column." |
0 commit comments