Skip to content
Open
Show file tree
Hide file tree
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
51 changes: 50 additions & 1 deletion __tests__/dependencies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}))
Expand Down Expand Up @@ -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: {
Expand Down
5 changes: 3 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}`
}
}

Expand Down
Loading