Skip to content

Commit

Permalink
feat: fix paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Germanov committed Jan 28, 2025
1 parent edcec7f commit 2e99b8b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
15 changes: 6 additions & 9 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 dist/index.js.map

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,22 @@ function processCustomDefaultsPath(path: string, currentBranch?: string): string
const branchMatch = path.match(/^([^@]+)@(.+)$/)
if (branchMatch) {
const [, filePath, branch] = branchMatch
// Don't include repo in filePath if it's already a full path
const cleanPath = filePath.startsWith(repo) ? filePath : `${repo}/${filePath}`
return `${apiUrl}/repos/${cleanPath}?ref=${branch}`
return `${apiUrl}/repos/${repo}/contents/${filePath}?ref=${branch}`
}

// For simple file paths, don't add server URL or branch
// Handle relative paths starting with ./ or ../
if (path.startsWith('./') || path.startsWith('../')) {
const normalizedPath = path.replace(/^[.\/]+/, '')
return `${apiUrl}/repos/${repo}/contents/${normalizedPath}?ref=${defaultBranch}`
}

// Handle absolute paths in repository
// Handle local files (no slashes)
if (!path.includes('/')) {
return path // Keep local files as-is
return `${apiUrl}/repos/${repo}/contents/${path}?ref=${defaultBranch}`
}

// Handle organization/repository paths
const cleanPath = path.startsWith(repo) ? path : `${repo}/${path}`
return `${apiUrl}/repos/${cleanPath}?ref=${defaultBranch}`
// Handle absolute paths in repository
return `${apiUrl}/repos/${repo}/contents/${path}?ref=${defaultBranch}`
}

export async function downloadDefaultConfig (server: string, apiURL: string, version: string, token: string, owner: string, repository: string, customDefaultsPaths: string): Promise<UploadResponse> {
Expand Down
2 changes: 1 addition & 1 deletion test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ describe('Config', () => {
'--defaultsFile',
'http://mock.test/asset/piper-defaults.yml',
'--defaultsFile',
'https://github.tools.sap/api/v3/repos/piper-test/gha-demo-k8s-node/contents/pipeline/custom-defaults.yml?ref=main',
'https://github.tools.sap/api/v3/repos/piper-test/gha-demo-k8s-node/contents/.pipeline/custom-defaults.yml?ref=main',
'--defaultsFile',
'https://github.tools.sap/api/v3/repos/piper-test/gha-demo-k8s-node/contents/shared/config.yaml?ref=main',
'--defaultsFile',
Expand Down

0 comments on commit 2e99b8b

Please sign in to comment.