|
| 1 | +name: 'Project Board Automation' |
| 2 | +description: 'Automate GitHub Projects with ease' |
| 3 | +inputs: |
| 4 | + project: |
| 5 | + description: Project board number |
| 6 | + required: true |
| 7 | + default: 1 |
| 8 | + token: |
| 9 | + description: GitHub PAT with org:write |
| 10 | + required: true |
| 11 | + org: |
| 12 | + description: Organization that owns the project |
| 13 | + required: false |
| 14 | + default: ${{ github.repository_owner }} |
| 15 | + label: |
| 16 | + description: Initial label for new issues/PRs |
| 17 | + required: false |
| 18 | + default: "needs triage" |
| 19 | +runs: |
| 20 | + using: "composite" |
| 21 | + steps: |
| 22 | + - name: Initial labeling |
| 23 | + uses: andymckay/labeler@e6c4322d0397f3240f0e7e30a33b5c5df2d39e90 |
| 24 | + with: |
| 25 | + add-labels: "${{ inputs.label }}" |
| 26 | + ignore-if-assigned: true |
| 27 | + ignore-if-labeled: true |
| 28 | + |
| 29 | + - name: Fetch project data |
| 30 | + run: | |
| 31 | + gh api graphql -f query=' |
| 32 | + query($org: String!, $num: Int!) { |
| 33 | + organization(login: $org){ |
| 34 | + projectNext(number: $num) { |
| 35 | + id |
| 36 | + fields(first: 20) { |
| 37 | + nodes { |
| 38 | + id |
| 39 | + name |
| 40 | + settings |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + }' -f org=$ORG -F num=${{ inputs.project }} > project_data.json |
| 46 | +
|
| 47 | + echo 'PROJECT_ID='$(jq -r '.data.organization.projectNext.id' project_data.json) >> $GITHUB_ENV |
| 48 | + echo 'STATUS_FIELD_ID='$(jq -r '.data.organization.projectNext.fields.nodes[] | select(.name == "Status").id' project_data.json) >> $GITHUB_ENV |
| 49 | + echo 'TODO_OPTION_ID='$(jq -r '.data.organization.projectNext.fields.nodes[] | select(.name == "Status").settings | fromjson.options[] | select(.name=="Todo").id' project_data.json) >> $GITHUB_ENV |
| 50 | + env: |
| 51 | + GITHUB_TOKEN: ${{ inputs.token }} |
| 52 | + ORG: ${{ inputs.org }} |
| 53 | + shell: bash |
| 54 | + |
| 55 | + - name: Get issue/PR ID |
| 56 | + run: | |
| 57 | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then |
| 58 | + echo 'ISSUE_PR_ID='${{ github.event.pull_request.node_id }} >> $GITHUB_ENV |
| 59 | + elif [[ "${{ github.event_name }}" == "issues" ]]; then |
| 60 | + echo 'ISSUE_PR_ID='${{ github.event.issue.node_id }} >> $GITHUB_ENV |
| 61 | + fi |
| 62 | + shell: bash |
| 63 | + |
| 64 | + - name: Move issue/PR to project |
| 65 | + run: | |
| 66 | + item_id="$( gh api graphql -f query=' |
| 67 | + mutation($project: ID!, $id: ID!) { |
| 68 | + addProjectNextItem(input: { |
| 69 | + projectId: $project, |
| 70 | + contentId: $id, |
| 71 | + }) { |
| 72 | + projectNextItem { |
| 73 | + id |
| 74 | + } |
| 75 | + } |
| 76 | + }' -f project=$PROJECT_ID -f id=$ISSUE_PR_ID --jq '.data.addProjectNextItem.projectNextItem.id')" |
| 77 | +
|
| 78 | + echo 'ITEM_ID='$item_id >> $GITHUB_ENV |
| 79 | + env: |
| 80 | + GITHUB_TOKEN: ${{ inputs.token }} |
| 81 | + shell: bash |
| 82 | + |
| 83 | + - name: Set fields on project ticket |
| 84 | + run: | |
| 85 | + gh api graphql -f query=' |
| 86 | + mutation ( |
| 87 | + $project: ID! |
| 88 | + $item: ID! |
| 89 | + $status_field: ID! |
| 90 | + $status_value: String! |
| 91 | + ) { |
| 92 | + updateProjectNextItemField(input: { |
| 93 | + projectId: $project |
| 94 | + itemId: $item |
| 95 | + fieldId: $status_field |
| 96 | + value: $status_value |
| 97 | + }) { |
| 98 | + projectNextItem { |
| 99 | + id |
| 100 | + } |
| 101 | + } |
| 102 | + }' -f project=$PROJECT_ID -f item=$ITEM_ID -f status_field=$STATUS_FIELD_ID -f status_value=$TODO_OPTION_ID |
| 103 | + env: |
| 104 | + GITHUB_TOKEN: ${{ inputs.token }} |
| 105 | + shell: bash |
0 commit comments