Close Project Issues #37
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Close Project Issues | |
# https://docs.github.com/en/issues/planning-and-tracking-with-projects/automating-your-project/automating-projects-using-actions | |
on: | |
workflow_dispatch: | |
inputs: | |
project_number: | |
description: 'The number of the project' | |
required: true | |
column_name: | |
description: 'The name of the column' | |
required: false | |
default: 'Closed' | |
fix_label: | |
description: 'The name of the fix label to apply (fixed-SU2025.0)' | |
required: true | |
dry_run: | |
description: 'Dry Run. Set to true to perform a dry run without making any changes' | |
required: false | |
default: true | |
type: boolean | |
jobs: | |
close_issues: | |
runs-on: ubuntu-latest | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
steps: | |
- name: Generate token | |
id: generate-token | |
uses: actions/create-github-app-token@v1 | |
with: | |
app-id: ${{ vars.APP_ID }} | |
private-key: ${{ secrets.APP_PEM }} | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Get organization name | |
id: get_org_name | |
run: | | |
org_name=$(echo $GITHUB_REPOSITORY | cut -d'/' -f1) | |
echo "org_name=$org_name" >> $GITHUB_ENV | |
- name: Get project node ID and title | |
id: get_project_info | |
env: | |
GH_TOKEN: ${{ steps.generate-token.outputs.token }} | |
run: | | |
org_name=${{ env.org_name }} | |
project_number=${{ github.event.inputs.project_number }} | |
project_info=$(gh api graphql -f query=' | |
query($org_name: String!, $project_number: Int!) { | |
organization(login: $org_name) { | |
projectV2(number: $project_number) { | |
id | |
title | |
} | |
} | |
}' -f org_name=$org_name -F project_number=$project_number --jq '.data.organization.projectV2') | |
project_id=$(echo $project_info | jq -r '.id') | |
project_title=$(echo $project_info | jq -r '.title') | |
echo "project_id=$project_id" >> $GITHUB_ENV | |
echo "project_title=$project_title" >> $GITHUB_ENV | |
echo "Project ID: $project_id" | |
echo "Project Title: $project_title" | |
- name: Get issues in the specified column | |
id: get_issues | |
env: | |
GH_TOKEN: ${{ steps.generate-token.outputs.token }} | |
run: | | |
org_name=${{ env.org_name }} | |
project_number=${{ github.event.inputs.project_number }} | |
column_name="${{ github.event.inputs.column_name }}" | |
issues=$(gh api graphql -f query=' | |
query ($org: String!, $number: Int!) { | |
organization(login: $org) { | |
projectV2(number: $number) { | |
items(first: 100) { | |
nodes { | |
content { | |
... on Issue { | |
number | |
} | |
} | |
fieldValueByName(name: "Status") { | |
... on ProjectV2ItemFieldSingleSelectValue { | |
name | |
} | |
} | |
} | |
} | |
} | |
} | |
}' -f org=$org_name -F number=$project_number --jq ' | |
[ | |
.data.organization.projectV2.items.nodes[] | |
| select(.fieldValueByName.name == "'"$column_name"'") | |
| .content.number | |
] | join(" ") | |
') | |
echo "issues=$issues" >> $GITHUB_ENV | |
echo "Issues: $issues" | |
- name: Create label if it does not exist | |
env: | |
GH_TOKEN: ${{ steps.generate-token.outputs.token }} | |
run: | | |
label=${{ github.event.inputs.fix_label }} | |
dry_run=${{ github.event.inputs.dry_run }} | |
echo "Label to create: $label" | |
if [ "$dry_run" = "false" ]; then | |
if ! gh label list --limit 100 | grep -q -w "$label"; then | |
echo "Creating label..." | |
gh label create "$label" --color FFFFFF | |
fi | |
fi | |
- name: Add label to issues | |
env: | |
GH_TOKEN: ${{ steps.generate-token.outputs.token }} | |
run: | | |
label=${{ github.event.inputs.fix_label }} | |
dry_run=${{ github.event.inputs.dry_run }} | |
for issue in ${{ env.issues }}; do | |
echo "Add label $label to issue $issue" | |
if [ "$dry_run" = "false" ]; then | |
gh issue edit $issue --add-label "$label" | |
fi | |
done | |
- name: Close issues | |
env: | |
GH_TOKEN: ${{ steps.generate-token.outputs.token }} | |
run: | | |
dry_run=${{ github.event.inputs.dry_run }} | |
for issue in ${{ env.issues }}; do | |
echo "Close issue $issue" | |
if [ "$dry_run" = "false" ]; then | |
gh issue close $issue | |
fi | |
done |