diff --git a/packages/integration/src/harness/core.test.ts b/packages/integration/src/harness/core.test.ts index d3e5b3bae0..501586b289 100644 --- a/packages/integration/src/harness/core.test.ts +++ b/packages/integration/src/harness/core.test.ts @@ -78,7 +78,7 @@ describe('Harness code core', () => { }); }); - describe('getGiteaLatestCommitUrl', () => { + describe('getHarnessLatestCommitUrl', () => { it('can create an url from arguments', () => { const config: HarnessIntegrationConfig = { host: 'app.harness.io', @@ -154,7 +154,7 @@ describe('Harness code core', () => { expect( parseHarnessUrl( config, - 'https://app.harness.io/ng/account/accountId/module/code/orgs/orgName/projects/projectName/repos/repoName/files/branchName/simple/path', + 'https://app.harness.io/ng/account/accountId/module/code/orgs/orgName/projects/projectName/repos/repoName/files/branchName/simple/~/path', ), ).toEqual({ accountId: 'accountId', @@ -165,7 +165,7 @@ describe('Harness code core', () => { refDashStr: 'branchName-simple', refString: 'branchName/simple', repoName: 'repoName', - branch: 'branchName/simple/path', + branch: 'branchName/simple', }); }); }); diff --git a/packages/integration/src/harness/core.ts b/packages/integration/src/harness/core.ts index 06d54797ad..0a0a167fcb 100644 --- a/packages/integration/src/harness/core.ts +++ b/packages/integration/src/harness/core.ts @@ -99,7 +99,7 @@ export function getHarnessLatestCommitUrl( url: string, ) { const parsedUrl = parseHarnessUrl(config, url); - return `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}/${parsedUrl.orgName}/${parsedUrl.projectName}/${parsedUrl.repoName}/+/content?routingId=${parsedUrl.accountId}&include_commit=true&git_ref=refs/heads/${parsedUrl.refString}`; + return `${parsedUrl.baseUrl}/gateway/code/api/v1/repos/${parsedUrl.accountId}/${parsedUrl.orgName}/${parsedUrl.projectName}/${parsedUrl.repoName}/+/content?routingId=${parsedUrl.accountId}&include_commit=true&git_ref=refs/heads/${parsedUrl.branch}`; } /** @@ -175,10 +175,13 @@ export function parseHarnessUrl( ); const refIndex = refAndPath.findIndex(item => item === '~'); const refString = refAndPath.slice(0, refIndex).join('/'); - const pathWithoutSlash = refAndPath - .slice(refIndex + 1) - .join('/') - .replace(/^\//, ''); + const pathWithoutSlash = + refIndex !== -1 + ? refAndPath + .slice(refIndex + 1) + .join('/') + .replace(/^\//, '') + : ''; return { baseUrl: baseUrl, accountId: accountId, @@ -188,7 +191,10 @@ export function parseHarnessUrl( path: pathWithoutSlash, repoName: repoName, refDashStr: refAndPath.slice(0, refIndex).join('-'), - branch: refAndPath.join('/'), + branch: + refIndex !== -1 + ? refAndPath.slice(0, refIndex).join('/') + : refAndPath.join('/'), }; } catch (e) { throw new Error(`Incorrect URL: ${url}, ${e}`);