Rename Gmail - Congratulations on Your Microsoft Certification! Acces… #5
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: Sync Existing Credly Badges | ||
| on: | ||
| schedule: | ||
| - cron: '0 6 * * *' | ||
| workflow_dispatch: | ||
| permissions: | ||
| contents: read | ||
| issues: write | ||
| jobs: | ||
| sync-badges: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Fetch Credly Badges | ||
| run: | | ||
| curl -sL "https://www.credly.com/users/jacob-kraniak/badges.json?page=1&page_size=100" -o badges.json | ||
| - name: Update Existing Issues Only | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const fs = require('fs'); | ||
| const badges = JSON.parse(fs.readFileSync('badges.json', 'utf8')).data || []; | ||
| const { data: existingIssues } = await github.rest.issues.listForRepo({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| state: 'all', | ||
| per_page: 100 | ||
| }); | ||
| // Map existing issues by credly_badge_id | ||
| const issueMap = new Map(); | ||
| for (const issue of existingIssues) { | ||
| const match = issue.body && issue.body.match(/\*\*Credly Badge ID\*\*: ([a-f0-9-]+)/i); | ||
| if (match) { | ||
| issueMap.set(match[1], issue); | ||
| } | ||
| } | ||
| let updated = 0; | ||
| let skipped = 0; | ||
| for (const badge of badges) { | ||
| if (badge.state !== 'accepted' || !badge.badge_template) continue; | ||
| const id = badge.id; | ||
| const existing = issueMap.get(id); | ||
| if (!existing) { | ||
| console.log(`Skipping new badge (no existing issue): ${badge.badge_template.name}`); | ||
| skipped++; | ||
| continue; | ||
| } | ||
| const url = `https://www.credly.com/badges/${id}`; | ||
| const issuedDate = badge.issued_at_date || 'Unknown'; | ||
| const body = `**Credly Badge URL**: ${url} | ||
| **Credly Badge ID**: ${id} | ||
| **Date Certified**: ${issuedDate} | ||
| **Status:** Backlog | ||
| **Target Completion:** TBD | ||
| **Priority:** Medium | ||
| ## Overview | ||
| ${badge.badge_template.description || 'Certification earned on Credly.'} | ||
| **Official Page:** ${badge.badge_template.url || 'https://www.credly.com'} | ||
| **Milestones / Tasks** | ||
| - [ ] Claim badge on Credly (already done) | ||
| - [ ] Add to Project Board | ||
| - [ ] Update LinkedIn / resume | ||
| - [ ] Plan renewal (if applicable) | ||
| **Additional Labels:** credly, auto-created | ||
| `; | ||
| await github.rest.issues.update({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: existing.number, | ||
| body: body | ||
| }); | ||
| console.log(`Updated issue #${existing.number} for: ${badge.badge_template.name}`); | ||
| updated++; | ||
| } | ||
| console.log(`Updated: ${updated}, Skipped (new): ${skipped}`); | ||