Skip to content

Commit

Permalink
fix: Correct token retrieval in getRandomToken function (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
FajarKim authored Dec 8, 2023
1 parent 782e955 commit 810015e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
54 changes: 54 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "🙀 Generate your Stats GitHub Profile in SVG",
"main": "api/index.ts",
"dependencies": {
"@actions/core": "^1.10.1",
"@resvg/resvg-js": "^2.6.0",
"@types/escape-html": "^1.0.4",
"@types/express": "^4.17.21",
Expand Down
11 changes: 11 additions & 0 deletions src/getRandomToken.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Importing necessary module
import dotenv from "dotenv";
import { getInput } from "@actions/core";

// Loads environment variables from a .env file if present
dotenv.config();
Expand All @@ -19,9 +20,19 @@ function getRandomToken(bearerHeader: boolean): string {
const getRandomEnv: string =
getGhEnv[Math.floor(Math.random() * getGhEnv.length)];

if (!getRandomEnv) {
// Use GitHub Actions core module to get the token
const getRandomEnv = getInput("github_token");

if (!getRandomEnv) {
throw new Error("Could not find github token");
}
}

if (bearerHeader) {
return `Bearer ${getRandomEnv}`;
}

return getRandomEnv;
}

Expand Down

0 comments on commit 810015e

Please sign in to comment.