Skip to content

Commit 7253c8d

Browse files
authored
Merge pull request #155 from DaleMcGrew/Dale_WCC_Mar31-2026
Brought back some recent webpack changes made by @josephevans.
2 parents 2fc85ea + 2b892c6 commit 7253c8d

2 files changed

Lines changed: 35 additions & 12 deletions

File tree

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"buildCordovaAndLinks": "node node/buildDateFile.js && node node/buildSrcCordova && CORDOVA=1 && webpack --mode development && node node/buildSymLinksRemote.js && bash ./node/unSymLinkIOS.sh && node node/logCompileDate.js",
2222
"lint": "eslint --format stylish --ext .jsx --ext .js src/js",
2323
"lintCordova": "eslint --format stylish --ext .jsx --ext .js srcCordova/js",
24+
"prebuild": "test -f git_commit_hash || git rev-parse HEAD > git_commit_hash",
25+
"prestart": "test -f git_commit_hash || git rev-parse HEAD > git_commit_hash",
2426
"prod": "npm run build",
2527
"run-prod-local": "node server-prod-local.js",
2628
"start": "node node/buildDateFile.js && PROTOCOL=HTTP webpack serve --mode development",

webpack.config.js

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/"Merge pull request (.*?)wevote/);
56-
if (pr) {
57-
stats.Pull_request = pr[1].slice(0, -2);
58-
const dateStringResults = text.match(/"committedDate":"(.*?)"/);
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

Comments
 (0)