@@ -9,32 +9,52 @@ export interface CommitStatusResult {
99}
1010
1111export async function fetchCommitStatus ( username : string , requestId : string ) : Promise < CommitStatusResult > {
12+ if ( ! username || username . trim ( ) . length === 0 ) {
13+ throw new Error ( 'Username is required. Please provide the DevOps Center org username.' ) ;
14+ }
15+
1216 const connection = await getConnection ( username ) ;
13- const query = `SELECT Id, Status__c, RequestToken__c FROM DevopsRequestInfo WHERE RequestToken__c = '${ requestId } ' LIMIT 1` ;
14-
15- const response = await axios . get ( `${ connection . instanceUrl } /services/data/v65.0/query` , {
16- headers : {
17- 'Authorization' : `Bearer ${ connection . accessToken } ` ,
18- 'Content-Type' : 'application/json'
19- } ,
20- params : { q : query }
21- } ) ;
22-
23- if ( response . data . records && response . data . records . length > 0 ) {
24- const record = response . data . records [ 0 ] ;
17+ const accessToken = connection . accessToken ;
18+ const instanceUrl = connection . instanceUrl ;
19+
20+ if ( ! accessToken || ! instanceUrl ) {
21+ throw new Error ( 'Missing access token or instance URL. Please check if you are authenticated to the org.' ) ;
22+ }
23+
24+ if ( ! requestId || requestId . trim ( ) . length === 0 ) {
25+ throw new Error ( 'Request ID is required to check commit status.' ) ;
26+ }
27+
28+ const soqlQuery = `SELECT Status FROM DevopsRequestInfo WHERE RequestToken = '${ requestId } '` ;
29+ const encodedQuery = encodeURIComponent ( soqlQuery ) ;
30+ const url = `${ instanceUrl } /services/data/v65.0/query/?q=${ encodedQuery } ` ;
31+ const headers = {
32+ 'Authorization' : `Bearer ${ accessToken } ` ,
33+ 'Content-Type' : 'application/json'
34+ } ;
35+
36+ try {
37+ const response = await axios . get ( url , { headers } ) ;
38+ const records = response . data . records || [ ] ;
39+
40+ if ( records . length === 0 ) {
41+ return {
42+ requestId,
43+ status : 'NOT_FOUND' ,
44+ message : `No commit status found for request ID: ${ requestId } `
45+ } ;
46+ }
47+
48+ const status = records [ 0 ] . Status ;
2549 return {
2650 requestId,
27- status : record . Status__c ,
28- recordId : record . Id ,
29- message : `Request ${ requestId } has status : ${ record . Status__c } `
51+ status,
52+ recordId : records [ 0 ] . Id ,
53+ message : `Commit status for request ID ${ requestId } : ${ status } `
3054 } ;
55+ } catch ( error : any ) {
56+ const errorMessage = error . response ?. data ?. [ 0 ] ?. message || error . message ;
57+ throw new Error ( `Error checking commit status: ${ errorMessage } ` ) ;
3158 }
32-
33- return {
34- requestId,
35- status : 'NOT_FOUND' ,
36- message : `No record found for request ID: ${ requestId } `
37- } ;
3859}
3960
40-
0 commit comments