diff --git a/src/utilities/githubUtils.test.ts b/src/utilities/githubUtils.test.ts index 9d834e810..6f5ff0af7 100644 --- a/src/utilities/githubUtils.test.ts +++ b/src/utilities/githubUtils.test.ts @@ -36,6 +36,21 @@ describe('Github utils', () => { ) }) + it('normalizes path with a custom server url', () => { + const serverUrl = 'https://github.enterprise.com' + const repo = 'gh_repo' + const sha = 'gh_sha' + const path = 'path' + process.env.GITHUB_SERVER_URL = serverUrl + process.env.GITHUB_REPOSITORY = repo + process.env.GITHUB_SHA = sha + expect(getNormalizedPath(path)).toBe( + `${serverUrl}/${repo}/blob/${sha}/${path}` + ) + + delete process.env.GITHUB_SERVER_URL + }) + it('checks if url is http', () => { expect(isHttpUrl('www.test.com')).toBe(false) expect(isHttpUrl('http.test.com')).toBe(false) diff --git a/src/utilities/githubUtils.ts b/src/utilities/githubUtils.ts index 86b80eae1..2d0301539 100644 --- a/src/utilities/githubUtils.ts +++ b/src/utilities/githubUtils.ts @@ -44,7 +44,8 @@ export function normalizeWorkflowStrLabel(workflowName: string): string { export function getNormalizedPath(pathValue: string) { if (!isHttpUrl(pathValue)) { //if it is not an http url then convert to link from current repo and commit - return `https://github.com/${process.env.GITHUB_REPOSITORY}/blob/${process.env.GITHUB_SHA}/${pathValue}` + const serverUrl = process.env.GITHUB_SERVER_URL || 'https://github.com' + return `${serverUrl}/${process.env.GITHUB_REPOSITORY}/blob/${process.env.GITHUB_SHA}/${pathValue}` } return pathValue } diff --git a/src/utilities/workflowAnnotationUtils.ts b/src/utilities/workflowAnnotationUtils.ts index b4ff55080..a2a5a9528 100644 --- a/src/utilities/workflowAnnotationUtils.ts +++ b/src/utilities/workflowAnnotationUtils.ts @@ -9,6 +9,8 @@ export function getWorkflowAnnotations( workflowFilePath: string, deploymentConfig: DeploymentConfig ): string { + const serverUrl = process.env.GITHUB_SERVER_URL || 'https://github.com' + const runUri = `${serverUrl}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}` const annotationObject = { run: process.env.GITHUB_RUN_ID, repository: process.env.GITHUB_REPOSITORY, @@ -16,7 +18,7 @@ export function getWorkflowAnnotations( workflowFileName: workflowFilePath.replace('.github/workflows/', ''), jobName: process.env.GITHUB_JOB, createdBy: process.env.GITHUB_ACTOR, - runUri: `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`, + runUri, commit: process.env.GITHUB_SHA, lastSuccessRunCommit: lastSuccessRunSha, branch: process.env.GITHUB_REF,