Skip to content

Commit 38b60ca

Browse files
authored
refactor: provide correct GitHub Pages domain in PRs (#5365)
* refactor: provide correct github pages domain * Add logging for pages API response Log the response from the pages API call. * Update preview-url-pr-description.js
1 parent fb1303b commit 38b60ca

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

scripts/github/preview-url-pr-description.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,34 @@ async function previewUrlPrDescription({ github, context }) {
1212
const pullNumber = context.payload.pull_request.number;
1313
const headRef = context.payload.pull_request.head.ref;
1414

15+
// Get the configured custom domain for GitHub Pages
16+
let baseUrl;
17+
try {
18+
const pagesResponse = await github.rest.repos.getPages({
19+
owner,
20+
repo
21+
});
22+
23+
// Use custom domain if available, otherwise fall back to github.io
24+
baseUrl =
25+
pagesResponse.data.html_url ??
26+
`https://${owner}.github.io/${repo}/`;
27+
// Ensure baseUrl ends with a single trailing slash
28+
if (!baseUrl.endsWith('/')) {
29+
baseUrl += '/';
30+
}
31+
} catch (error) {
32+
console.warn(
33+
'Could not fetch GitHub Pages configuration, using default domain:',
34+
error.message
35+
);
36+
baseUrl = `https://${owner}.github.io/${repo}/`;
37+
// Ensure baseUrl ends with a single trailing slash
38+
if (!baseUrl.endsWith('/')) {
39+
baseUrl += '/';
40+
}
41+
}
42+
1543
// Fetch current PR
1644
const pr = await github.rest.pulls.get({
1745
owner,
@@ -20,7 +48,7 @@ async function previewUrlPrDescription({ github, context }) {
2048
});
2149
const urlSectionStart = '\n<!-- DBUX-TEST-URL-START -->';
2250
const urlSectionEnd = '\n<!-- DBUX-TEST-URL-END -->';
23-
const testUrl = `\n\n🔭🐙🐈 Test this branch here: <https://${owner}.github.io/${repo}/review/${headRef}>\n`;
51+
const testUrl = `\n\n🔭🐙🐈 Test this branch here: <${baseUrl}review/${headRef}>\n`;
2452
let body = pr.data.body || '';
2553
// Remove any existing test URL section
2654
const startIdx = body.indexOf(urlSectionStart);

0 commit comments

Comments
 (0)