Prioritize Issues by Reactions #6
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: Prioritize Issues by Reactions | |
| on: | |
| # schedule: | |
| # - cron: '*/10 * * * *' # Runs every 10 mins | |
| workflow_dispatch: # Allows manual runs | |
| jobs: | |
| prioritize: | |
| permissions: | |
| issues: write | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v3 | |
| - name: Install jq | |
| run: sudo apt-get install -y jq | |
| - name: Prioritize issues by reactions | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| REPO: NuGet/Entropy | |
| HIGH: 5 | |
| MEDIUM: 2 | |
| run: | | |
| issue_numbers=$(gh issue list -R "$REPO" --state open --json number -q '.[].number') | |
| for ISSUE in $issue_numbers; do | |
| echo "🔍 Checking Issue #$ISSUE" | |
| reactions=$(curl -s \ | |
| -H "Accept: application/vnd.github.squirrel-girl-preview+json" \ | |
| -H "Authorization: token $GH_TOKEN" \ | |
| https://api.github.com/repos/$REPO/issues/$ISSUE/reactions) | |
| total=$(echo "$reactions" | jq 'length') | |
| if [ "$total" -ge "$HIGH" ]; then | |
| priority="p/0" | |
| elif [ "$total" -ge "$MEDIUM" ]; then | |
| priority="p/1" | |
| else | |
| priority="p/2" | |
| fi | |
| echo "👉 Issue #$ISSUE has $total reactions — Assigning label: $priority" | |
| # Get current p/* label (if any) | |
| current_priority=$(gh issue view $ISSUE -R $REPO --json labels -q '.labels[].name' | grep '^p/' || echo "") | |
| if [[ "$current_priority" != "$priority" ]]; then | |
| # Check if current priority label was added by github-actions | |
| if [[ -n "$current_priority" ]]; then | |
| # Get the timeline events to see who added the current priority label | |
| label_added_by=$(gh api repos/$REPO/issues/$ISSUE/timeline --paginate | jq -r --arg label "$current_priority" '.[] | select(.event == "labeled" and .label.name == $label) | .actor.login' | tail -1) | |
| if [[ "$label_added_by" != "github-actions[bot]" ]]; then | |
| echo " 🚫 Priority label '$current_priority' was set by '$label_added_by' (not github-actions), skipping update" | |
| continue | |
| fi | |
| echo " ⏹️ Removing old label: $current_priority (was set by github-actions)" | |
| gh issue edit $ISSUE -R $REPO --remove-label "$current_priority" | |
| fi | |
| echo " ➕ Adding new label: $priority" | |
| gh issue edit $ISSUE -R $REPO --add-label "$priority" | |
| else | |
| echo " ✅ Priority label already correct: $priority" | |
| fi | |
| echo "" | |
| done |