Skip to content

Commit

Permalink
refactor(bitbucket-server): Platform-wide getJsonFile (#9382)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Apr 3, 2021
1 parent 5928c8e commit 83fa6cd
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/platform/bitbucket-server/index.ts
Expand Up @@ -118,15 +118,19 @@ export async function getRepos(): Promise<string[]> {
}
}

export async function getJsonFile(fileName: string): Promise<any | null> {
export async function getJsonFile(
fileName: string,
repo: string = config.repository
): Promise<any | null> {
try {
const { body } = await bitbucketServerHttp.getJson<FileData>(
`./rest/api/1.0/projects/${config.projectKey}/repos/${config.repositorySlug}/browse/${fileName}?limit=20000`
);
if (body.isLastPage) {
return JSON.parse(body.lines.map((l) => l.text).join(''));
const [project, slug] = repo.split('/');
const fileUrl = `./rest/api/1.0/projects/${project}/repos/${slug}/browse/${fileName}?limit=20000`;
const res = await bitbucketServerHttp.getJson<FileData>(fileUrl);
const { isLastPage, lines, size } = res.body;
if (isLastPage) {
return JSON.parse(lines.map(({ text }) => text).join(''));
}
logger.warn({ size: body.size }, `The file is too big`);
logger.warn({ size }, `The file is too big`);
} catch (err) {
// no-op
}
Expand Down

0 comments on commit 83fa6cd

Please sign in to comment.