diff --git a/__tests__/dependencies.test.ts b/__tests__/dependencies.test.ts index f29c512..ea0c76b 100644 --- a/__tests__/dependencies.test.ts +++ b/__tests__/dependencies.test.ts @@ -20,7 +20,8 @@ jest.mock('@actions/github', () => ({ }, runId: 12345, runAttempt: 1, - job: 'test-job' + job: 'test-job', + serverUrl: 'https://github.com' }, getOctokit: jest.fn() })) @@ -304,6 +305,54 @@ describe('RuntimeDependencies Code Coverage', () => { expect(result).toEqual('https://github.com/test-owner/test-repo/actions/runs/12345/attempts/1') }) + it('createActionSummaryLink - uses serverUrl for GitHub Enterprise Server', async () => { + const originalServerUrl = github.context.serverUrl + ;(github.context as { serverUrl: string }).serverUrl = 'https://github.securian.com' + + const mockOctokit = { + rest: { + actions: { + listJobsForWorkflowRun: jest.fn().mockResolvedValue({ + data: { + jobs: [{ id: 5, name: 'test-job' }] + } + }) + } + } + } + ;(github.getOctokit as jest.Mock).mockReturnValue(mockOctokit) + + const result = await dependencies.createActionSummaryLink('test-token') + + expect(result).toEqual( + 'https://github.securian.com/test-owner/test-repo/actions/runs/12345/attempts/1#summary-5' + ) + ;(github.context as { serverUrl: string }).serverUrl = originalServerUrl + }) + + it('createActionSummaryLink - uses serverUrl for GHES without matching job', async () => { + const originalServerUrl = github.context.serverUrl + ;(github.context as { serverUrl: string }).serverUrl = 'https://github.securian.com' + + const mockOctokit = { + rest: { + actions: { + listJobsForWorkflowRun: jest.fn().mockResolvedValue({ + data: { + jobs: [{ id: 1, name: 'other-job' }] + } + }) + } + } + } + ;(github.getOctokit as jest.Mock).mockReturnValue(mockOctokit) + + const result = await dependencies.createActionSummaryLink('test-token') + + expect(result).toEqual('https://github.securian.com/test-owner/test-repo/actions/runs/12345/attempts/1') + ;(github.context as { serverUrl: string }).serverUrl = originalServerUrl + }) + it('createActionSummaryLink - API error', async () => { const mockOctokit = { rest: { diff --git a/dist/index.js b/dist/index.js index 4434a38..9202367 100644 --- a/dist/index.js +++ b/dist/index.js @@ -106132,6 +106132,7 @@ class RuntimeDependencies { const repo = github.context.repo.repo; const runId = github.context.runId; const runAttempt = github.context.runAttempt; + const serverUrl = github.context.serverUrl; const octokit = github.getOctokit(githubToken); let matchingJob; try { @@ -106153,10 +106154,10 @@ class RuntimeDependencies { // matrices, then we can't link directly to the table, and have to link to just the page itself and expect the user] // to scroll down the table themselves. if (matchingJob) { - return `https://github.com/${owner}/${repo}/actions/runs/${runId}/attempts/${runAttempt}#summary-${matchingJob.id}`; + return `${serverUrl}/${owner}/${repo}/actions/runs/${runId}/attempts/${runAttempt}#summary-${matchingJob.id}`; } else { - return `https://github.com/${owner}/${repo}/actions/runs/${runId}/attempts/${runAttempt}`; + return `${serverUrl}/${owner}/${repo}/actions/runs/${runId}/attempts/${runAttempt}`; } } async createPullRequestReview(githubToken, reviewBody) { diff --git a/package-lock.json b/package-lock.json index 8d412af..12d7c31 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,7 +36,7 @@ "typescript-eslint": "^8.59.4" }, "engines": { - "node": ">=20.9.0" + "node": ">=24.0.0" } }, "node_modules/@actions/artifact": { diff --git a/src/dependencies.ts b/src/dependencies.ts index 97898d1..f24470f 100644 --- a/src/dependencies.ts +++ b/src/dependencies.ts @@ -108,6 +108,7 @@ export class RuntimeDependencies implements Dependencies { const repo = github.context.repo.repo const runId = github.context.runId const runAttempt = github.context.runAttempt + const serverUrl = github.context.serverUrl const octokit = github.getOctokit(githubToken) let matchingJob: { id: number } | undefined try { @@ -128,9 +129,9 @@ export class RuntimeDependencies implements Dependencies { // matrices, then we can't link directly to the table, and have to link to just the page itself and expect the user] // to scroll down the table themselves. if (matchingJob) { - return `https://github.com/${owner}/${repo}/actions/runs/${runId}/attempts/${runAttempt}#summary-${matchingJob.id}` + return `${serverUrl}/${owner}/${repo}/actions/runs/${runId}/attempts/${runAttempt}#summary-${matchingJob.id}` } else { - return `https://github.com/${owner}/${repo}/actions/runs/${runId}/attempts/${runAttempt}` + return `${serverUrl}/${owner}/${repo}/actions/runs/${runId}/attempts/${runAttempt}` } }