Skip to content

Commit 936b48c

Browse files
committed
feat: add RESOURCE_URL input and update report entity URI construction
1 parent 0793617 commit 936b48c

File tree

5 files changed

+59
-20
lines changed

5 files changed

+59
-20
lines changed

.github/workflows/commit-context.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ jobs:
2525
RESOURCE_ID: example_resource
2626
ACTIVITY_NAME: non-repellat
2727
LEAGUE: default
28+
RESOURCE_URL: https://mortified-goldfish.biz/

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ inputs:
2222
RESOURCE_ID:
2323
description: 'Identifier of the resource in APICURON'
2424
required: true
25+
RESOURCE_URL:
26+
description: 'URL of the repository'
27+
required: false
2528
ACTIVITY_NAME:
2629
description: 'APICURON Activity name to be reported'
2730
required: true

dist/index.js

Lines changed: 21 additions & 5 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: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ async function processCommits(
6060
userInfoConfig: UserInfoServiceConfig,
6161
resourceId: string,
6262
activityName: string,
63-
league: string
63+
league: string,
64+
resourceUrl?: string
6465
): Promise<Report[]> {
6566
const { payload } = github.context
6667
const repo = payload.repository!
@@ -81,10 +82,11 @@ async function processCommits(
8182
core.info(`Skipping report for ${username} - no ORCID available`)
8283
return null
8384
}
84-
85+
const resUrl = resourceUrl? `${resourceUrl}/${repo.html_url}` : `${repo.html_url}`
86+
8587
return {
8688
curator_orcid: orcid,
87-
entity_uri: `${repo.html_url}/commit/${commit.id}`,
89+
entity_uri: `${resUrl}/commit/${commit.id}`,
8890
resource_id: resourceId,
8991
timestamp: commit.timestamp,
9092
activity_term: activityName,
@@ -100,27 +102,42 @@ async function sendToApi(
100102
apiConfig: ReportApiConfig
101103
): Promise<void> {
102104
try {
105+
core.info(`Sending ${reports.length} reports to ${apiConfig.endpoint}`);
106+
107+
const requestBody = {
108+
reports: reports,
109+
};
110+
103111
const response = await fetch(apiConfig.endpoint, {
104112
method: 'POST',
105113
headers: {
106114
'Content-Type': 'application/json',
107-
Authorization: `Bearer ${apiConfig.token}`
115+
'Authorization': `Bearer ${apiConfig.token}`,
116+
'version': '2'
108117
},
109-
body: JSON.stringify({ reports })
110-
})
118+
body: JSON.stringify(requestBody)
119+
});
120+
121+
const contentType = response.headers.get('content-type') || '';
122+
const isJson = contentType.includes('application/json');
123+
const responseBody = isJson ? await response.json() : await response.text();
111124

112125
if (!response.ok) {
113-
throw new Error(
114-
`API request failed: ${response.status} ${response.statusText}`
115-
)
126+
core.error(`API Error: ${response.status} ${response.statusText}`);
127+
core.error(`Response body: ${JSON.stringify(responseBody)}`);
128+
throw new Error(`API request failed: ${response.status} ${response.statusText}`);
116129
}
117-
core.info(`Successfully sent ${reports.length} reports`)
130+
131+
core.info(`Successfully sent ${reports.length} reports`);
132+
core.debug(`API Response: ${JSON.stringify(responseBody)}`);
118133
} catch (error) {
119-
core.error('Failed to send reports')
120-
throw error
134+
core.error('Failed to send reports');
135+
if (error instanceof Error) {
136+
core.error(error.stack || error.message);
137+
}
138+
throw error;
121139
}
122140
}
123-
124141
export async function run(): Promise<void> {
125142
try {
126143
const userInfoConfig: UserInfoServiceConfig = {
@@ -134,11 +151,13 @@ export async function run(): Promise<void> {
134151
const resourceId = core.getInput('RESOURCE_ID', { required: true })
135152
const activityName = core.getInput('ACTIVITY_NAME', { required: true })
136153
const league = core.getInput('LEAGUE', { required: true })
154+
const resourceUrl = core.getInput('RESOURCE_URL')
137155
const reports = await processCommits(
138156
userInfoConfig,
139157
resourceId,
140158
activityName,
141-
league
159+
league,
160+
resourceUrl
142161
)
143162

144163
if (reports.length === 0) {

0 commit comments

Comments
 (0)