Skip to content

Commit e66b31e

Browse files
authored
Merge pull request #595 from YiweiShen/codez-chore-594-feat-progress-add-view-job-run-link-to-status
feat(progress): add view job run link to status
2 parents b92b406 + 26b4562 commit e66b31e

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/github/progress.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ function getRandomLoadingPhrase(): string {
3232
return LOADING_PHRASES[Math.floor(Math.random() * LOADING_PHRASES.length)];
3333
}
3434

35+
/**
36+
* Construct a URL to the current GitHub Actions run.
37+
* @returns A URL string if context vars are set, otherwise null.
38+
*/
39+
function getRunUrl(): string | null {
40+
const server = process.env.GITHUB_SERVER_URL || 'https://github.com';
41+
const repo = process.env.GITHUB_REPOSITORY;
42+
const runId = process.env.GITHUB_RUN_ID;
43+
if (!repo || !runId) return null;
44+
return `${server}/${repo}/actions/runs/${runId}`;
45+
}
46+
3547
/**
3648
* Create a GitHub comment to display initial progress steps with checkboxes.
3749
* @param octokit - Authenticated Octokit client.
@@ -47,7 +59,8 @@ export async function createProgressComment(
4759
steps: string[],
4860
): Promise<number> {
4961
const emptyBar = '░'.repeat(PROGRESS_BAR_BLOCKS);
50-
const body = [
62+
const runUrl = getRunUrl();
63+
const lines = [
5164
PROGRESS_TITLE,
5265
'',
5366
`Progress: [${emptyBar}] 0%`,
@@ -59,7 +72,11 @@ export async function createProgressComment(
5972
return i === 0 ? `${checkbox}${SPINNER_HTML}` : checkbox;
6073
}),
6174
'',
62-
].join('\n');
75+
];
76+
if (runUrl) {
77+
lines.push(`[View job run](${runUrl})`, '');
78+
}
79+
const body = lines.join('\n');
6380
if ('issue' in event) {
6481
const { data } = await octokit.rest.issues.createComment({
6582
...repo,
@@ -104,7 +121,8 @@ export async function updateProgressComment(
104121
const bar = '█'.repeat(filled) + '░'.repeat(PROGRESS_BAR_BLOCKS - filled);
105122
const percent = Math.round((completed / total) * 100);
106123

107-
const body = [
124+
const runUrl = getRunUrl();
125+
const lines = [
108126
PROGRESS_TITLE,
109127
'',
110128
`Progress: ${bar} ${percent}%${percent === 100 ? ' ✅' : ''}`,
@@ -115,7 +133,11 @@ export async function updateProgressComment(
115133
i === completed && completed !== total ? `${line}${SPINNER_HTML}` : line,
116134
),
117135
'',
118-
].join('\n');
136+
];
137+
if (runUrl) {
138+
lines.push(`[View job run](${runUrl})`, '');
139+
}
140+
const body = lines.join('\n');
119141
if ('issue' in event) {
120142
await octokit.rest.issues.updateComment({
121143
...repo,

0 commit comments

Comments
 (0)