Skip to content
Snippets Groups Projects
Unverified Commit 7e873cac authored by Oleg Krivtsov's avatar Oleg Krivtsov Committed by GitHub
Browse files

feat(config/presets): fetchJSONFile handle branchOrTag in Bitbucket Server (#13005)

parent 8dfb48e0
No related branches found
Tags 38.44.1
No related merge requests found
// 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 {
......
......@@ -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)
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment