Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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