Make is_package_json_version_upgraded work with private repos

This commit is contained in:
Joseph Garrone 2024-06-20 03:11:27 +02:00
parent 45686f5e1d
commit 9356720963

View file

@ -41,7 +41,7 @@ export async function action(
//When it's a pr from: github.head_ref==="<name of the branch branch>" //When it's a pr from: github.head_ref==="<name of the branch branch>"
const branch = params.branch.replace(/^refs\/heads\//, ""); const branch = params.branch.replace(/^refs\/heads\//, "");
const to_version = await getPackageJsonVersion({ owner, repo, branch }); const to_version = await getPackageJsonVersion({ owner, repo, branch, github_token });
if( to_version === undefined ){ if( to_version === undefined ){
throw new Error(`No version in package.json on ${owner}/${repo}#${branch} (or repo is private)`); throw new Error(`No version in package.json on ${owner}/${repo}#${branch} (or repo is private)`);
@ -107,9 +107,10 @@ async function getPackageJsonVersion(params: {
owner: string; owner: string;
repo: string; repo: string;
branch: string; branch: string;
github_token: string;
}): Promise<NpmModuleVersion | undefined> { }): Promise<NpmModuleVersion | undefined> {
const { owner, repo, branch } = params; const { owner, repo, branch, github_token } = params;
const version = await fetch( const version = await fetch(
urlJoin( urlJoin(
@ -118,7 +119,12 @@ async function getPackageJsonVersion(params: {
repo, repo,
branch, branch,
"package.json" "package.json"
) ),
{
"headers": {
"Authorization": `token ${github_token}`
}
}
) )
.then(res => res.text()) .then(res => res.text())
.then(text => JSON.parse(text)) .then(text => JSON.parse(text))