Skip to content

Commit

Permalink
feat(config/presets): fetchJSONFile handle branchOrTag in Bitbucket S…
Browse files Browse the repository at this point in the history
…erver (#13005)


Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
olegkrivtsov and viceice committed Dec 10, 2021
1 parent 8dfb48e commit 7e873ca
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
@@ -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 {
Expand Down
20 changes: 20 additions & 0 deletions lib/config/presets/bitbucket-server/index.spec.ts
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions lib/config/presets/bitbucket-server/index.ts
Expand Up @@ -17,11 +17,16 @@ const http = new BitbucketServerHttp();
export async function fetchJSONFile(
repo: string,
fileName: string,
endpoint: string
endpoint: string,
branchOrTag?: string
): Promise<Preset> {
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);
Expand Down

0 comments on commit 7e873ca

Please sign in to comment.