Skip to content
Merged
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
15 changes: 15 additions & 0 deletions src/utilities/githubUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/utilities/githubUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Comment thread
ejaifeobuks marked this conversation as resolved.
Resolved
return `${serverUrl}/${process.env.GITHUB_REPOSITORY}/blob/${process.env.GITHUB_SHA}/${pathValue}`
}
return pathValue
}
Expand Down
4 changes: 3 additions & 1 deletion src/utilities/workflowAnnotationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ 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,
workflow: process.env.GITHUB_WORKFLOW,
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,
Expand Down
Loading