Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions src/github/progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ function getRandomLoadingPhrase(): string {
return LOADING_PHRASES[Math.floor(Math.random() * LOADING_PHRASES.length)];
}

/**
* Construct a URL to the current GitHub Actions run.
* @returns A URL string if context vars are set, otherwise null.
*/
function getRunUrl(): string | null {
const server = process.env.GITHUB_SERVER_URL || 'https://github.com';
const repo = process.env.GITHUB_REPOSITORY;
const runId = process.env.GITHUB_RUN_ID;
if (!repo || !runId) return null;
return `${server}/${repo}/actions/runs/${runId}`;
}

/**
* Create a GitHub comment to display initial progress steps with checkboxes.
* @param octokit - Authenticated Octokit client.
Expand All @@ -47,7 +59,8 @@ export async function createProgressComment(
steps: string[],
): Promise<number> {
const emptyBar = '░'.repeat(PROGRESS_BAR_BLOCKS);
const body = [
const runUrl = getRunUrl();
const lines = [
PROGRESS_TITLE,
'',
`Progress: [${emptyBar}] 0%`,
Expand All @@ -59,7 +72,11 @@ export async function createProgressComment(
return i === 0 ? `${checkbox}${SPINNER_HTML}` : checkbox;
}),
'',
].join('\n');
];
if (runUrl) {
lines.push(`[View job run](${runUrl})`, '');
}
const body = lines.join('\n');
if ('issue' in event) {
const { data } = await octokit.rest.issues.createComment({
...repo,
Expand Down Expand Up @@ -104,7 +121,8 @@ export async function updateProgressComment(
const bar = '█'.repeat(filled) + '░'.repeat(PROGRESS_BAR_BLOCKS - filled);
const percent = Math.round((completed / total) * 100);

const body = [
const runUrl = getRunUrl();
const lines = [
PROGRESS_TITLE,
'',
`Progress: ${bar} ${percent}%${percent === 100 ? ' ✅' : ''}`,
Expand All @@ -115,7 +133,11 @@ export async function updateProgressComment(
i === completed && completed !== total ? `${line}${SPINNER_HTML}` : line,
),
'',
].join('\n');
];
if (runUrl) {
lines.push(`[View job run](${runUrl})`, '');
}
const body = lines.join('\n');
if ('issue' in event) {
await octokit.rest.issues.updateComment({
...repo,
Expand Down