Skip to content

Commit

Permalink
feat: test raw gh links
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Germanov committed Jan 28, 2025
1 parent f0b2d93 commit 067b78c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,16 @@ function processCustomDefaultsPath(path: string, currentBranch?: string): string
return url.toString()
}

const baseUrl = process.env.GITHUB_SERVER_URL
const repo = process.env.GITHUB_REPOSITORY
const defaultBranch = currentBranch ?? process.env.GITHUB_REF_NAME ?? 'main'


// Handle relative paths with branch references (org/repo/path@branch)
const branchMatch = path.match(/^([^@]+)@(.+)$/)
if (branchMatch) {
const [, filePath, branch] = branchMatch
return `${process.env.GITHUB_SERVER_URL}/${filePath}?ref=${branch}`
return `${baseUrl}/raw/${filePath}/${branch}`
}

// For simple file paths, don't add server URL or branch
Expand All @@ -63,8 +68,7 @@ function processCustomDefaultsPath(path: string, currentBranch?: string): string
}

// Handle organization/repository paths (without branch reference)
const branch = currentBranch ?? process.env.GITHUB_REF_NAME ?? 'main'
return `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/${path}?ref=${branch}`
return `${baseUrl}/raw/${repo}/${path}/${defaultBranch}`
}

export async function downloadDefaultConfig (server: string, apiURL: string, version: string, token: string, owner: string, repository: string, customDefaultsPaths: string): Promise<UploadResponse> {
Expand Down
10 changes: 5 additions & 5 deletions test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,13 @@ describe('Config', () => {
'--defaultsFile',
'http://mock.test/asset/piper-defaults.yml',
'--defaultsFile',
'https://github.com/org/repo/config.yaml?ref=feature',
'https://github.com/raw/org/repo/config.yaml/feature',
'--defaultsFile',
'https://github.com/raw/org/repo/local/config.yaml/main',
'--defaultsFile',
'https://github.com/org/repo/local/config.yaml?ref=main',
'--defaultsFile',
'https://github.com/org/repo/config.yaml?ref=develop',
'--defaultsFile',
'https://github.com/org/repo/shared/config.yaml?ref=main'
'https://github.com/raw/org/repo/shared/config.yaml/main'
]))
})

Expand All @@ -295,7 +295,7 @@ describe('Config', () => {
'https://github.com/org/repo/config.yaml?ref=feature',
'local/config.yaml'
]

piperExecResultMock = generatePiperGetDefaultsOutput(paths)

const result = await config.downloadDefaultConfig(
Expand Down

0 comments on commit 067b78c

Please sign in to comment.