refactor(github): Platform-wide getJsonFile (#9383)

This commit is contained in:
Sergei Zharinov 2021-04-03 16:47:54 +04:00 committed by GitHub
parent 3915fa6512
commit 5928c8eb45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -140,18 +140,17 @@ async function getBranchProtection(
return res.body; return res.body;
} }
export async function getJsonFile(fileName: string): Promise<any | null> { export async function getJsonFile(
fileName: string,
repo: string = config.repository
): Promise<any | null> {
try { try {
return JSON.parse( const url = `repos/${repo}/contents/${fileName}`;
Buffer.from( const res = await githubApi.getJson<{ content: string }>(url);
( const buf = res.body.content;
await githubApi.getJson<{ content: string }>( const str = Buffer.from(buf, 'base64').toString();
`repos/${config.repository}/contents/${fileName}` const result = JSON.parse(str);
) return result;
).body.content,
'base64'
).toString()
);
} catch (err) { } catch (err) {
return null; return null;
} }