|
| 1 | +# Directly move the closed PR to a close status in the PODAAC project |
| 2 | +# to avoid unnecessary clutter and manual triage in the "needs:triage" column. |
| 3 | +name: Update Closed PR Status in PODAAC project |
| 4 | + |
| 5 | +on: |
| 6 | + pull_request: |
| 7 | + types: [closed] |
| 8 | + |
| 9 | +jobs: |
| 10 | + update-pr-status: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Set status to closed |
| 14 | + uses: actions/github-script@v7 |
| 15 | + with: |
| 16 | + github-token: ${{ secrets.PROJECTS_PAT }} |
| 17 | + script: | |
| 18 | + const projectNumber = 75; |
| 19 | + const org = 'podaac'; |
| 20 | + const prNumber = context.payload.pull_request.number; |
| 21 | + const isMerged = context.payload.pull_request.merged; |
| 22 | +
|
| 23 | + console.log(`PR #${prNumber} was ${isMerged ? 'merged' : 'closed without merging'}`); |
| 24 | +
|
| 25 | + // Get the project ID and status field information |
| 26 | + const projectQuery = ` |
| 27 | + query($org: String!, $number: Int!) { |
| 28 | + organization(login: $org) { |
| 29 | + projectV2(number: $number) { |
| 30 | + id |
| 31 | + fields(first: 20) { |
| 32 | + nodes { |
| 33 | + ... on ProjectV2SingleSelectField { |
| 34 | + id |
| 35 | + name |
| 36 | + options { |
| 37 | + id |
| 38 | + name |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + `; |
| 47 | +
|
| 48 | + const projectData = await github.graphql(projectQuery, { |
| 49 | + org: org, |
| 50 | + number: projectNumber |
| 51 | + }); |
| 52 | +
|
| 53 | + const project = projectData.organization.projectV2; |
| 54 | + const statusField = project.fields.nodes.find(field => field.name === 'Status'); |
| 55 | + const closedOption = statusField?.options.find(option => option.name === 'closed'); |
| 56 | +
|
| 57 | + if (!closedOption) { |
| 58 | + core.warning('Could not find "closed" status option in project'); |
| 59 | + return; |
| 60 | + } |
| 61 | +
|
| 62 | + // Get the PR's project item |
| 63 | + const itemQuery = ` |
| 64 | + query($org: String!, $repo: String!, $number: Int!) { |
| 65 | + repository(owner: $org, name: $repo) { |
| 66 | + pullRequest(number: $number) { |
| 67 | + projectItems(first: 10) { |
| 68 | + nodes { |
| 69 | + id |
| 70 | + project { |
| 71 | + id |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + `; |
| 79 | +
|
| 80 | + const itemData = await github.graphql(itemQuery, { |
| 81 | + org: org, |
| 82 | + repo: context.repo.repo, |
| 83 | + number: prNumber |
| 84 | + }); |
| 85 | +
|
| 86 | + const items = itemData.repository.pullRequest.projectItems.nodes; |
| 87 | + const projectItem = items.find(item => item.project.id === project.id); |
| 88 | +
|
| 89 | + if (!projectItem) { |
| 90 | + console.log('PR is not in the project, skipping status update'); |
| 91 | + return; |
| 92 | + } |
| 93 | +
|
| 94 | + // Update the status field to "closed" |
| 95 | + const updateMutation = ` |
| 96 | + mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $value: String!) { |
| 97 | + updateProjectV2ItemFieldValue( |
| 98 | + input: { |
| 99 | + projectId: $projectId |
| 100 | + itemId: $itemId |
| 101 | + fieldId: $fieldId |
| 102 | + value: { singleSelectOptionId: $value } |
| 103 | + } |
| 104 | + ) { |
| 105 | + projectV2Item { |
| 106 | + id |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + `; |
| 111 | +
|
| 112 | + await github.graphql(updateMutation, { |
| 113 | + projectId: project.id, |
| 114 | + itemId: projectItem.id, |
| 115 | + fieldId: statusField.id, |
| 116 | + value: closedOption.id |
| 117 | + }); |
| 118 | +
|
| 119 | + console.log(`✅ Successfully set status to "closed" for PR #${prNumber}`); |
| 120 | +
|
| 121 | + core.summary |
| 122 | + .addHeading(`PR Status Updated`) |
| 123 | + .addList([ |
| 124 | + `PR #${prNumber} was ${isMerged ? 'merged' : 'closed'}`, |
| 125 | + `Project status updated to "closed"` |
| 126 | + ]) |
| 127 | + .write(); |
0 commit comments