mirror of
https://github.com/anuraghazra/github-readme-stats.git
synced 2024-12-21 06:11:29 +08:00
822efbf6cb
* ci: fix small bugs in theme-preview action * ci: format code
43 lines
870 B
JavaScript
43 lines
870 B
JavaScript
/**
|
|
* @file Contains helper functions used in the scripts.
|
|
*/
|
|
|
|
import { getInput } from "@actions/core";
|
|
|
|
// Script variables.
|
|
const OWNER = "anuraghazra";
|
|
const REPO = "github-readme-stats";
|
|
|
|
/**
|
|
* Retrieve information about the repository that ran the action.
|
|
*
|
|
* @param {Object} context Action context.
|
|
* @returns {Object} Repository information.
|
|
*/
|
|
export const getRepoInfo = (ctx) => {
|
|
try {
|
|
return {
|
|
owner: ctx.repo.owner,
|
|
repo: ctx.repo.repo,
|
|
};
|
|
} catch (error) {
|
|
return {
|
|
owner: OWNER,
|
|
repo: REPO,
|
|
};
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Retrieve github token and throw error if it is not found.
|
|
*
|
|
* @returns {string} Github token.
|
|
*/
|
|
export const getGithubToken = () => {
|
|
const token = getInput("github_token") || process.env.GITHUB_TOKEN;
|
|
if (!token) {
|
|
throw Error("Could not find github token");
|
|
}
|
|
return token;
|
|
};
|