1- name : Discover New Credly Badges
1+ name : Sync Existing Credly Badges
22
33on :
44 schedule :
@@ -10,7 +10,7 @@ permissions:
1010 issues : write
1111
1212jobs :
13- discover -badges :
13+ sync -badges :
1414 runs-on : ubuntu-latest
1515
1616 steps :
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 & Upsert Badges
24+ - name : Update Existing Issues Only
2525 uses : actions/github-script@v7
2626 with :
2727 script : |
@@ -44,19 +44,24 @@ jobs:
4444 }
4545 }
4646
47- let created = 0;
4847 let updated = 0;
48+ let skipped = 0;
4949
5050 for (const badge of badges) {
5151 if (badge.state !== 'accepted' || !badge.badge_template) continue;
5252
53- const name = badge.badge_template.name;
5453 const id = badge.id;
54+ const existing = issueMap.get(id);
55+
56+ if (!existing) {
57+ console.log(`Skipping new badge (no existing issue): ${badge.badge_template.name}`);
58+ skipped++;
59+ continue;
60+ }
61+
5562 const url = `https://www.credly.com/badges/${id}`;
5663 const issuedDate = badge.issued_at_date || 'Unknown';
5764
58- const existing = issueMap.get(id);
59-
6065 const body = `**Credly Badge URL**: ${url}
6166**Credly Badge ID**: ${id}
6267**Date Certified**: ${issuedDate}
@@ -79,27 +84,15 @@ ${badge.badge_template.description || 'Certification earned on Credly.'}
7984**Additional Labels:** credly, auto-created
8085` ;
8186
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- }
87+ await github.rest.issues.update({
88+ owner: context.repo.owner,
89+ repo: context.repo.repo,
90+ issue_number: existing.number,
91+ body: body
92+ });
93+
94+ console.log(` Updated issue # ${existing.number} for: ${badge.badge_template.name}`);
95+ updated++;
10396 }
10497
105- console.log(`Created : ${created }, Updated : ${updated }`);
98+ console.log(`Updated : ${updated }, Skipped (new) : ${skipped }`);
0 commit comments