Skip to content

Commit

Permalink
Fix previous feat
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Jun 20, 2024
1 parent a685911 commit 42b51ab
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
7 changes: 5 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,15 @@ exports.action = action;
function getPackageJsonVersion(params) {
return __awaiter(this, void 0, void 0, function* () {
const { owner, repo, branch, github_token } = params;
const version = yield node_fetch_1.default(urlJoin(`https://raw.github.com`, owner, repo, branch, "package.json"), {
const version = yield node_fetch_1.default(`https://api.github.com/repos/${owner}/${repo}/contents/package.json?ref=${branch}`, {
"headers": {
"Authorization": `token ${github_token}`
}
})
.then(res => res.text())
.then((res) => __awaiter(this, void 0, void 0, function* () {
const { content } = JSON.parse(yield res.text());
return Buffer.from(content, "base64").toString("utf-8");
}))
.then(text => JSON.parse(text))
.then(({ version }) => version)
.catch(() => undefined);
Expand Down
33 changes: 19 additions & 14 deletions src/is_package_json_version_upgraded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,32 @@ async function getPackageJsonVersion(params: {
github_token: string;
}): Promise<NpmModuleVersion | undefined> {

const { owner, repo, branch, github_token } = params;
const {
owner,
repo,
branch,
github_token
} = params;

const version = await fetch(
urlJoin(
`https://raw.github.com`,
owner,
repo,
branch,
"package.json"
),
`https://api.github.com/repos/${owner}/${repo}/contents/package.json?ref=${branch}`,
{
"headers": {
"Authorization": `token ${github_token}`
}
"headers": {
"Authorization": `token ${github_token}`
}
)
.then(res => res.text())
})
.then(async res => {

const { content }= JSON.parse(await res.text()) as { content: string; };

return Buffer.from(content, "base64").toString("utf-8");

})
.then(text => JSON.parse(text))

.then(({ version }) => version as string)
.catch(() => undefined)
;


if (version === undefined) {
return undefined;
Expand Down
13 changes: 9 additions & 4 deletions src/test/is_package_json_version_upgraded.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@


import { action } from "../is_package_json_version_upgraded";
import { assert } from "tsafe/assert";

(async () => {

const repo = "keycloakify-demo-app";
const repo = "tss-react";

const github_token = process.env.GITHUB_TOKEN

assert(github_token !== undefined);

const result = await action("is_package_json_version_upgraded", {
"owner": "InseeFrLab",
"owner": "garronej",
repo,
"branch": "4fc0ccb46bdb3912e0a215ca3ae45aed458ea6a4",
"github_token": ""
"branch": "main",
github_token
}, { "debug": console.log });

console.log(result);
Expand Down

0 comments on commit 42b51ab

Please sign in to comment.