diff --git a/lib/config/presets/bitbucket-server/__snapshots__/index.spec.ts.snap b/lib/config/presets/bitbucket-server/__snapshots__/index.spec.ts.snap index 26af38c45b1e11..c76919ded3ccba 100644 --- a/lib/config/presets/bitbucket-server/__snapshots__/index.spec.ts.snap +++ b/lib/config/presets/bitbucket-server/__snapshots__/index.spec.ts.snap @@ -1,5 +1,22 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`config/presets/bitbucket-server/index fetchJSONFile() handles branches/tags 1`] = ` +Array [ + Object { + "headers": Object { + "accept": "application/json", + "accept-encoding": "gzip, deflate, br", + "authorization": "Bearer abc", + "host": "git.company.org", + "user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)", + "x-atlassian-token": "no-check", + }, + "method": "GET", + "url": "https://git.company.org/rest/api/1.0/projects/some/repos/repo/browse/some-filename.json?limit=20000&at=feature%2Fbranch", + }, +] +`; + exports[`config/presets/bitbucket-server/index fetchJSONFile() returns JSON 1`] = ` Array [ Object { diff --git a/lib/config/presets/bitbucket-server/index.spec.ts b/lib/config/presets/bitbucket-server/index.spec.ts index 9e98bd01150243..ba5e6d0c02f74e 100644 --- a/lib/config/presets/bitbucket-server/index.spec.ts +++ b/lib/config/presets/bitbucket-server/index.spec.ts @@ -36,6 +36,26 @@ describe('config/presets/bitbucket-server/index', () => { expect(httpMock.getTrace()).toMatchSnapshot(); }); + it('handles branches/tags', async () => { + httpMock + .scope(bitbucketApiHost) + .get(`${basePath}/some-filename.json`) + .query({ limit: 20000, at: 'feature/branch' }) + .reply(200, { + isLastPage: true, + lines: [{ text: '{"from":"api"' }, { text: '}' }], + }); + + const res = await bitbucketServer.fetchJSONFile( + 'some/repo', + 'some-filename.json', + bitbucketApiHost, + 'feature/branch' + ); + expect(res).toEqual({ from: 'api' }); + expect(httpMock.getTrace()).toMatchSnapshot(); + }); + it('throws 404', async () => { httpMock .scope(bitbucketApiHost) diff --git a/lib/config/presets/bitbucket-server/index.ts b/lib/config/presets/bitbucket-server/index.ts index 3dbe80cf46caaa..80a0f5d67e671b 100644 --- a/lib/config/presets/bitbucket-server/index.ts +++ b/lib/config/presets/bitbucket-server/index.ts @@ -17,11 +17,16 @@ const http = new BitbucketServerHttp(); export async function fetchJSONFile( repo: string, fileName: string, - endpoint: string + endpoint: string, + branchOrTag?: string ): Promise { const [projectKey, repositorySlug] = repo.split('/'); setBaseUrl(endpoint); - const url = `rest/api/1.0/projects/${projectKey}/repos/${repositorySlug}/browse/${fileName}?limit=20000`; + let url = `rest/api/1.0/projects/${projectKey}/repos/${repositorySlug}/browse/${fileName}?limit=20000`; + if (branchOrTag) { + url += '&at=' + encodeURIComponent(branchOrTag); + } + let res: { body: FileData }; try { res = await http.getJson(url);