Skip to content

Instantly share code, notes, and snippets.

@kuroppe1819
Last active September 29, 2023 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuroppe1819/575c3f5d818daa2fc5c6d4d5323baecc to your computer and use it in GitHub Desktop.
Save kuroppe1819/575c3f5d818daa2fc5c6d4d5323baecc to your computer and use it in GitHub Desktop.
Close all "Done" or "Canceled" status issues
#!/bin/bash
# Project(beta) を API で読み取るには read:project の権限が必要
# 手元で実行する場合は gh auth login --scopes "read:project" で認証してから実行する
issues=$(gh api graphql --paginate -f query='
query ($endCursor: String) {
organization(login: $organization_name){
projectV2(number: $project_number) {
title
items(first: 100, after: $endCursor) {
totalCount
pageInfo {
hasNextPage
endCursor
}
nodes {
type
... on ProjectV2Item {
fieldValueByName(name: "Status") {
... on ProjectV2ItemFieldSingleSelectValue {
name
}
}
}
content {
... on Issue {
id
closed
}
}
}
}
}
}
}' | jq '.[].organization.projectV2.items.nodes[] | select(.fieldValueByName.name == "Done" or .fieldValueByName.name == "Canceled") | select(.type == "ISSUE") | select(.content.closed == false) | .content.id' | jq -r -s .[])
for issue in $issues; do
gh api graphql -f query='
mutation {
closeIssue(input: {issueId: "'$issue'"}) {
issue {
id
}
}
}'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment