@@ -48,18 +48,36 @@ async function getStatusValues () {
4848 console . log ( 'Hash: ' , hash ) ;
4949 const hashURL = `https://github.com/wevote/weconnect-client/commit/${ hash } ` ;
5050 console . log ( 'hashURL: ' , hashURL ) ;
51- const response = await fetch ( hashURL ) ;
52- const text = await response . text ( ) ;
53- // console.log(`git_commit_hash: '${text}'`);
54- if ( text !== 'Not Found' ) {
55- const pr = text . match ( / " M e r g e p u l l r e q u e s t ( .* ?) w e v o t e / ) ;
56- if ( pr ) {
57- stats . Pull_request = pr [ 1 ] . slice ( 0 , - 2 ) ;
58- const dateStringResults = text . match ( / " c o m m i t t e d D a t e " : " ( .* ?) " / ) ;
59- console . log ( dateStringResults [ 1 ] ) ;
60- const date = new DateTime ( dateStringResults [ 1 ] ) ;
61- stats . Git_committed_date = date . toLocaleString ( DateTime . DATETIME_MED_WITH_SECONDS ) ;
62- stats . Git_commit_hash = `<a href="${ hashURL } ">${ hash } </a>` ;
51+
52+ // Use the GitHub REST API instead of scraping HTML — works for all commit types
53+ const apiHeaders = { Accept : 'application/vnd.github.v3+json' , 'User-Agent' : 'weconnect-client-build' } ;
54+
55+ // Get commit details (date)
56+ const commitResponse = await fetch ( `https://api.github.com/repos/wevote/weconnect-client/commits/${ hash } ` , { headers : apiHeaders } ) ;
57+ if ( ! commitResponse . ok ) {
58+ throw new Error ( `GitHub API returned ${ commitResponse . status } for commit ${ hash } ` ) ;
59+ }
60+ const commitData = await commitResponse . json ( ) ;
61+ let committedDate ;
62+ try {
63+ committedDate = commitData . commit . committer . date || commitData . commit . author . date ;
64+ } catch ( error ) {
65+ committedDate = commitData . commit . author . date ;
66+ }
67+ console . log ( 'committedDate: ' , committedDate ) ;
68+ const date = new DateTime ( committedDate ) ;
69+ stats . Git_committed_date = date . toLocaleString ( DateTime . DATETIME_MED_WITH_SECONDS ) ;
70+ stats . Git_commit_hash = `<a href="${ hashURL } ">${ hash } </a>` ;
71+
72+ // Get associated pull request number
73+ const prsResponse = await fetch ( `https://api.github.com/repos/wevote/weconnect-client/commits/${ hash } /pulls` , { headers : apiHeaders } ) ;
74+ if ( prsResponse . ok ) {
75+ const prs = await prsResponse . json ( ) ;
76+ if ( prs . length > 0 ) {
77+ stats . Pull_request = `#${ prs [ 0 ] . number } ` ;
78+ console . log ( 'Pull_request: ' , stats . Pull_request ) ;
79+ } else {
80+ stats . Pull_request = 'none' ;
6381 }
6482 } else {
6583 stats . Pull_request = 'none' ;
@@ -68,6 +86,9 @@ async function getStatusValues () {
6886 }
6987 } catch ( error ) {
7088 console . log ( 'Error in getStatusValues git: ' , error ) ;
89+ stats . Pull_request = 'none' ;
90+ stats . Git_committed_date = 'none' ;
91+ stats . Git_commit_hash = 'none' ;
7192 }
7293
7394 return stats ;
0 commit comments