Skip to content

Commit 039743f

Browse files
committed
feat: enhance error handling and logging for user ORCID fetching
1 parent a2cab6f commit 039743f

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed

.github/workflows/commit-context.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ jobs:
2323
USER_INFO_SERVICE_ENDPOINT: ${{ secrets.USER_INFO_SERVICE_ENDPOINT }}
2424
USER_INFO_SERVICE_TOKEN: ${{ secrets.USER_INFO_SERVICE_TOKEN }}
2525
RESOURCE_ID: example_resource
26-
ACTIVITY_NAME: example_activity
26+
ACTIVITY_NAME: non-repellat
2727
LEAGUE: default

dist/index.js

Lines changed: 19 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,23 @@ async function fetchUserInfo(
3131
'Content-Type': 'application/json'
3232
}
3333
})
34-
3534
if (!response.ok) {
36-
throw new Error(`HTTP error! status: ${response.status}`)
35+
if (response.status >= 400) {
36+
core.warning(`User '${username}' won't be credited - no ORCID associated with their github account`)
37+
} else {
38+
throw new Error(`HTTP error! status: ${response.status}`)
39+
}
40+
return 'unknown'
3741
}
3842

3943
const data = (await response.json()) as { orcid_id?: string }
44+
45+
if (!data?.orcid_id) {
46+
core.notice(`No ORCID found for user '${username}' in API response`)
47+
return 'unknown'
48+
}
4049

41-
return data?.orcid_id || 'unknown'
50+
return data.orcid_id
4251
} catch (error) {
4352
core.error(
4453
`Failed to fetch user info for ${username}: ${error instanceof Error ? error.message : 'Unknown error'}`
@@ -62,9 +71,17 @@ async function processCommits(
6271
payload.commits.map(async (commit: any) => {
6372
const username = commit.author?.username || commit.committer?.username
6473
if (!username) {
65-
throw new Error('No username found in the commit')
74+
core.warning(`Skipping commit ${commit.id} - no username associated`)
75+
return null
6676
}
77+
6778
const orcid = await fetchUserInfo(username, userInfoConfig)
79+
80+
if (orcid === 'unknown') {
81+
core.info(`Skipping report for ${username} - no ORCID available`)
82+
return null
83+
}
84+
6885
return {
6986
curator_orcid: orcid,
7087
entity_uri: `${repo.html_url}/commit/${commit.id}`,
@@ -75,7 +92,7 @@ async function processCommits(
7592
}
7693
})
7794
)
78-
return reports
95+
return reports.filter((report): report is Report => report !== null)
7996
}
8097

8198
async function sendToApi(

0 commit comments

Comments
 (0)