|
4 | 4 | pull_request: |
5 | 5 | types: [opened] |
6 | 6 | issues: |
7 | | - types: [opened] |
| 7 | + types: [opened, closed] |
8 | 8 |
|
9 | 9 | jobs: |
10 | 10 | auto-assign-and-label: |
@@ -130,3 +130,70 @@ jobs: |
130 | 130 | issue_number: context.issue.number, |
131 | 131 | body: `🎖️ **Badge Submission Tracking Issue Created!**\n\nYour badge submission is being tracked.\n\n**Status:** Pending Review ⏳\n**Assigned to:** @nisalgunawardhana\n**Expected Review Time:** 2-5 days\n\n✅ **Next Steps:**\n1. Ensure your PR is linked above\n2. Verify all evidence is in the PR\n3. Wait for review and feedback\n\nWe'll notify you as soon as the review is complete! 🚀` |
132 | 132 | }); |
| 133 | +
|
| 134 | + # Auto-assign badge on issue closure |
| 135 | + issue-closed-badge: |
| 136 | + if: github.event.action == 'closed' && github.event.issue != null && github.actor == 'nisalgunawardhana' |
| 137 | + runs-on: ubuntu-latest |
| 138 | + permissions: |
| 139 | + pull-requests: write |
| 140 | + issues: write |
| 141 | + |
| 142 | + steps: |
| 143 | + - name: Check if submission issue |
| 144 | + id: check-submission |
| 145 | + run: | |
| 146 | + if [[ "${{ github.event.issue.title }}" == *"🎖️"* ]] || [[ "${{ github.event.issue.title }}" == *"Badge"* ]] || [[ "${{ github.event.issue.title }}" == *"submission"* ]]; then |
| 147 | + echo "is_submission=true" >> $GITHUB_OUTPUT |
| 148 | + fi |
| 149 | +
|
| 150 | + # Determine badge level from issue body "My Level:" field |
| 151 | + - name: Determine badge level |
| 152 | + id: badge-level |
| 153 | + run: | |
| 154 | + body="${{ github.event.issue.body }}" |
| 155 | + # Extract level from "**My Level:**" field |
| 156 | + if [[ "$body" =~ \*\*My\ Level:\*\*[[:space:]]*([a-zA-Z]+) ]]; then |
| 157 | + level="${BASH_REMATCH[1]}" |
| 158 | + level_lower=$(echo "$level" | tr '[:upper:]' '[:lower:]') |
| 159 | + if [[ "$level_lower" == "beginner" ]]; then |
| 160 | + echo "level=beginner" >> $GITHUB_OUTPUT |
| 161 | + echo "badge_label=🟢-Beginner" >> $GITHUB_OUTPUT |
| 162 | + elif [[ "$level_lower" == "intermediate" ]]; then |
| 163 | + echo "level=intermediate" >> $GITHUB_OUTPUT |
| 164 | + echo "badge_label=🟡-Intermediate" >> $GITHUB_OUTPUT |
| 165 | + elif [[ "$level_lower" == "advanced" ]]; then |
| 166 | + echo "level=advanced" >> $GITHUB_OUTPUT |
| 167 | + echo "badge_label=🔴-Advanced" >> $GITHUB_OUTPUT |
| 168 | + fi |
| 169 | + fi |
| 170 | +
|
| 171 | + # Add completed badge label |
| 172 | + - name: Add completion badge |
| 173 | + if: steps.check-submission.outputs.is_submission == 'true' && steps.badge-level.outputs.level != '' |
| 174 | + uses: actions/github-script@v7 |
| 175 | + with: |
| 176 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 177 | + script: | |
| 178 | + github.rest.issues.addLabels({ |
| 179 | + owner: context.repo.owner, |
| 180 | + repo: context.repo.repo, |
| 181 | + issue_number: context.issue.number, |
| 182 | + labels: ['reviewed', 'completed', '${{ steps.badge-level.outputs.level }}'] |
| 183 | + }); |
| 184 | +
|
| 185 | + # Add completion comment |
| 186 | + - name: Add completion comment |
| 187 | + if: steps.check-submission.outputs.is_submission == 'true' |
| 188 | + uses: actions/github-script@v7 |
| 189 | + with: |
| 190 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 191 | + script: | |
| 192 | + const badge = '${{ steps.badge-level.outputs.badge_label }}' || '✅'; |
| 193 | + github.rest.issues.createComment({ |
| 194 | + owner: context.repo.owner, |
| 195 | + repo: context.repo.repo, |
| 196 | + issue_number: context.issue.number, |
| 197 | + body: `✅ **Issue Closed - Badge Awarded!**\n\n${badge}\n\n**Status:** Reviewed and Successfully Completed 🎉\n\nCongratulations! Your submission has been reviewed and successfully completed. You have earned this badge!\n\n📌 **Achievement Unlocked:** ${{ steps.badge-level.outputs.level || 'Badge' }}\n\nGreat work! Keep contributing and earning more badges! 🚀` |
| 198 | + }); |
| 199 | +
|
0 commit comments