Skip to content

Commit 49fb277

Browse files
committed
Fix workflow to close project column issues.
1 parent 06bc891 commit 49fb277

1 file changed

Lines changed: 44 additions & 26 deletions

File tree

.github/workflows/close-project-issues.yml

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: Close Project Issues
22

3+
# https://docs.github.com/en/issues/planning-and-tracking-with-projects/automating-your-project/automating-projects-using-actions
4+
35
on:
46
workflow_dispatch:
57
inputs:
@@ -14,24 +16,28 @@ on:
1416
description: 'The name of the fix label to apply (fixed-SU2025.0)'
1517
required: true
1618
dry_run:
17-
description: 'Set to true to perform a dry run without making any changes'
19+
description: 'Dry Run. Set to true to perform a dry run without making any changes'
1820
required: false
1921
default: true
2022
type: boolean
2123

2224
jobs:
23-
manage_issues:
25+
close_issues:
2426
runs-on: ubuntu-latest
27+
env:
28+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2529

2630
steps:
31+
- name: Generate token
32+
id: generate-token
33+
uses: actions/create-github-app-token@v1
34+
with:
35+
app-id: ${{ vars.APP_ID }}
36+
private-key: ${{ secrets.APP_PEM }}
37+
2738
- name: Checkout repository
2839
uses: actions/checkout@v2
2940

30-
- name: Set up GitHub CLI
31-
uses: actions/setup-gh@v2
32-
with:
33-
token: ${{ secrets.GITHUB_TOKEN }}
34-
3541
- name: Get organization name
3642
id: get_org_name
3743
run: |
@@ -40,6 +46,8 @@ jobs:
4046
4147
- name: Get project node ID and title
4248
id: get_project_info
49+
env:
50+
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
4351
run: |
4452
org_name=${{ env.org_name }}
4553
project_number=${{ github.event.inputs.project_number }}
@@ -61,25 +69,25 @@ jobs:
6169
6270
- name: Get issues in the specified column
6371
id: get_issues
72+
env:
73+
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
6474
run: |
65-
project_id=${{ env.project_id }}
75+
org_name=${{ env.org_name }}
76+
project_number=${{ github.event.inputs.project_number }}
6677
column_name=${{ github.event.inputs.column_name }}
6778
issues=$(gh api graphql -f query='
68-
query($project_id: ID!, $column_name: String!) {
69-
node(id: $project_id) {
70-
... on ProjectV2 {
71-
items(first: 100) {
72-
nodes {
73-
id
74-
content {
75-
... on Issue {
76-
number
79+
query ($org: String!, $number: Int!) {
80+
organization(login: $org) {
81+
projectV2(number: $number) {
82+
items(first: 100) {
83+
nodes {
84+
content {
85+
... on Issue {
86+
number
87+
}
7788
}
78-
}
79-
fieldValues(first: 100) {
80-
nodes {
81-
value
82-
projectField {
89+
fieldValueByName(name: "Status") {
90+
... on ProjectV2ItemFieldSingleSelectValue {
8391
name
8492
}
8593
}
@@ -88,15 +96,23 @@ jobs:
8896
}
8997
}
9098
}
91-
}' -f project_id=$project_id -f column_name=$column_name --jq '.data.node.items.nodes[] | select(.fieldValues.nodes[] | select(.projectField.name == "Status" and .value == $column_name)) | .content.number')
92-
99+
}' -f org=$org_name -F number=$project_number --jq '
100+
[
101+
.data.organization.projectV2.items.nodes[]
102+
| select(.fieldValueByName.name == "'"$column_name"'")
103+
| .content.number
104+
] | join(" ")
105+
')
106+
93107
echo "issues=$issues" >> $GITHUB_ENV
94108
echo "Issues: $issues"
95109
96110
- name: Create label if it does not exist
111+
env:
112+
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
97113
run: |
98114
project_title=${{ env.project_title }}
99-
label=${{ env.fix_label }}
115+
label=${{ github.event.inputs.fix_label }}
100116
dry_run=${{ github.event.inputs.dry_run }}
101117
echo "Label to create: $label"
102118
if [ "$dry_run" = "false" ]; then
@@ -106,9 +122,11 @@ jobs:
106122
fi
107123
108124
- name: Add label to issues
125+
env:
126+
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
109127
run: |
110128
project_title=${{ env.project_title }}
111-
label=${{ env.fix_label }}
129+
label=${{ github.event.inputs.fix_label }}
112130
dry_run=${{ github.event.inputs.dry_run }}
113131
for issue in ${{ env.issues }}; do
114132
echo "Would add label $label to issue $issue"

0 commit comments

Comments
 (0)