2121 run : |
2222 curl -sL "https://www.credly.com/users/jacob-kraniak/badges.json?page=1&page_size=100" -o badges.json
2323
24- - name : Process New Badges
24+ - name : Process & Upsert Badges
2525 uses : actions/github-script@v7
2626 with :
2727 script : |
@@ -35,57 +35,71 @@ jobs:
3535 per_page: 100
3636 });
3737
38- const existingTitles = new Set(existingIssues.map(i => i.title.toLowerCase()));
38+ // Map existing issues by credly_badge_id
39+ const issueMap = new Map();
40+ for (const issue of existingIssues) {
41+ const match = issue.body && issue.body.match(/\*\*Credly Badge ID\*\*: ([a-f0-9-]+)/i);
42+ if (match) {
43+ issueMap.set(match[1], issue);
44+ }
45+ }
3946
4047 let created = 0;
48+ let updated = 0;
49+
4150 for (const badge of badges) {
4251 if (badge.state !== 'accepted' || !badge.badge_template) continue;
4352
4453 const name = badge.badge_template.name;
4554 const id = badge.id;
4655 const url = `https://www.credly.com/badges/${id}`;
47- const title = `[Certification] ${name}` ;
56+ const issuedDate = badge.issued_at_date || 'Unknown' ;
4857
49- if (existingTitles.has(title.toLowerCase())) {
50- console.log(`Skipping existing: ${name}`);
51- continue;
52- }
58+ const existing = issueMap.get(id);
5359
54- const issuedDate = badge.issued_at_date || 'Unknown';
55- const bodyLines = [
56- `**Credly Badge URL**: ${url}`,
57- `**Credly Badge ID**: ${id}`,
58- `**Date Certified**: ${issuedDate}`,
59- '',
60- '**Status:** Backlog',
61- '**Target Completion:** TBD',
62- '**Priority:** Medium',
63- '',
64- '## Overview',
65- badge.badge_template.description || 'Certification earned on Credly.',
66- '',
67- `**Official Page:** ${badge.badge_template.url || 'https://www.credly.com'}`,
68- '',
69- '**Milestones / Tasks**',
70- '- [ ] Claim badge on Credly (already done)',
71- '- [ ] Add to Project Board',
72- '- [ ] Update LinkedIn / resume',
73- '- [ ] Plan renewal (if applicable)',
74- '',
75- '**Additional Labels:** credly, auto-created'
76- ];
77- const body = bodyLines.join('\n');
78-
79- await github.rest.issues.create({
80- owner: context.repo.owner,
81- repo: context.repo.repo,
82- title: title,
83- body: body,
84- labels: ['certification', 'credly', 'auto-created']
85- });
86-
87- console.log(`Created issue for: ${name}`);
88- created++;
60+ const body = `**Credly Badge URL**: ${url}
61+ **Credly Badge ID**: ${id}
62+ **Date Certified**: ${issuedDate}
63+
64+ **Status:** Backlog
65+ **Target Completion:** TBD
66+ **Priority:** Medium
67+
68+ # # Overview
69+ ${badge.badge_template.description || 'Certification earned on Credly.'}
70+
71+ **Official Page:** ${badge.badge_template.url || 'https://www.credly.com'}
72+
73+ **Milestones / Tasks**
74+ - [ ] Claim badge on Credly (already done)
75+ - [ ] Add to Project Board
76+ - [ ] Update LinkedIn / resume
77+ - [ ] Plan renewal (if applicable)
78+
79+ **Additional Labels:** credly, auto-created
80+ ` ;
81+
82+ if (existing) {
83+ await github.rest.issues.update({
84+ owner: context.repo.owner,
85+ repo: context.repo.repo,
86+ issue_number: existing.number,
87+ body: body
88+ });
89+ console.log(` Updated issue # ${existing.number} for: ${name}`);
90+ updated++;
91+ } else {
92+ const title = `[Certification] ${name}`;
93+ await github.rest.issues.create({
94+ owner : context.repo.owner,
95+ repo : context.repo.repo,
96+ title : title,
97+ body : body,
98+ labels : ['certification', 'credly', 'auto-created']
99+ });
100+ console.log(`Created new issue for : ${name}`);
101+ created++;
102+ }
89103 }
90104
91- console.log(`Total new issues created: ${created }`);
105+ console.log(`Created : ${ created}, Updated : ${updated }`);
0 commit comments