@@ -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-
124141export 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