Last active
August 20, 2022 17:50
-
-
Save mauritsvanrees/f0dc7d829a1957a1771adbf0e86057c5 to your computer and use it in GitHub Desktop.
Iterate over open issues using the 'gh' command, and offer to close them.
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
#!/bin/sh | |
# Get a list of open issues using the 'gh' command from GitHub. | |
# By default this gives at most 30 answers. | |
# We print only the number. | |
# Then we iterate over these issues and check each one, offering to close it. | |
# There are a few sample queries. | |
# Make sure one of the ISSUES commands is uncommented. | |
# 1. Get open issues last updated before 2019. | |
# Sort the oldest one first. | |
ISSUES=$(gh issue list --search="updated:<2019-01-01, sort:updated-asc" --json number --jq ".[]|.number") | |
# 2. Get open issues belonging to a milestone. | |
# Milestones are not used much in the plone GitHub organisation. | |
# I guess only here: | |
# https://github.com/plone/Products.CMFPlone/milestones | |
# ISSUES=$(gh issue list --milestone "Plone 4.3" --json number --jq ".[]|.number") | |
# 3. Simply all issues. | |
# ISSUES=$(gh issue list --json number --jq ".[]|.number") | |
echo "Found these matching issues (at most 30):" | |
echo $ISSUES | |
if test "$ISSUES" == ""; then | |
exit | |
fi | |
# If we close an issue, we add a comment: | |
CLOSING_COMMENT="Closed due to long inactivity. Please reopen if this is still relevant for Plone 5.2 or 6. You could check one of the demo sites: https://plone.org/what-is-plone/plone/try-plone" | |
# If we close an issue, we add a label, if we find a matching one: | |
AVAILABLE_LABELS=$(gh label list --json name --jq ".[]|.name") | |
LABEL1="25 status: deferred" | |
LABEL2="wontfix" | |
if [[ $AVAILABLE_LABELS == *"$LABEL1"* ]]; then | |
LABEL=$LABEL1 | |
elif [[ $AVAILABLE_LABELS == *"$LABEL2"* ]]; then | |
LABEL=$LABEL2 | |
else | |
LABEL="" | |
echo "No nice label found for adding to a closed issue." | |
fi | |
if test "$LABEL" != ""; then | |
echo "Will add this label to closed issues: $LABEL" | |
fi | |
echo "Now we go through each issue, and give you the chance to close it." | |
for number in $ISSUES; do | |
echo | |
echo "##################################" | |
echo "Viewing next issue..." | |
gh issue view $number | |
echo | |
cat <<EOF | |
What do you want to do with this issue?" | |
1. Continue without changes [default] | |
2. Close it. | |
3. Open in a browser for manual inspection. | |
EOF | |
read answer | |
if test "$answer" == "2"; then | |
echo "CLOSING issue $number" | |
if test "$LABEL" != ""; then | |
echo "Adding label $LABEL" | |
# Adding a label twice is no problem. | |
gh issue edit $number --add-label "$LABEL" | |
fi | |
gh issue close $number --comment="$CLOSING_COMMENT" | |
elif test "$answer" == "3"; then | |
gh browse $number | |
else | |
echo "continuing" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment