2022-10-02 17:05:13 +08:00
|
|
|
/**
|
|
|
|
* @file Contains helper functions used in the scripts.
|
|
|
|
*/
|
|
|
|
|
2022-10-02 23:41:28 +08:00
|
|
|
import { getInput } from "@actions/core";
|
|
|
|
|
2022-10-02 17:05:13 +08:00
|
|
|
const OWNER = "anuraghazra";
|
|
|
|
const REPO = "github-readme-stats";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve information about the repository that ran the action.
|
|
|
|
*
|
2023-07-05 14:32:22 +08:00
|
|
|
* @param {Object} ctx Action context.
|
2022-10-02 17:05:13 +08:00
|
|
|
* @returns {Object} Repository information.
|
|
|
|
*/
|
|
|
|
export const getRepoInfo = (ctx) => {
|
|
|
|
try {
|
|
|
|
return {
|
|
|
|
owner: ctx.repo.owner,
|
|
|
|
repo: ctx.repo.repo,
|
|
|
|
};
|
|
|
|
} catch (error) {
|
2024-08-13 01:19:17 +08:00
|
|
|
// Resolve eslint no-unused-vars
|
|
|
|
error;
|
|
|
|
|
2022-10-02 17:05:13 +08:00
|
|
|
return {
|
|
|
|
owner: OWNER,
|
|
|
|
repo: REPO,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve github token and throw error if it is not found.
|
|
|
|
*
|
2022-10-26 22:41:59 +08:00
|
|
|
* @returns {string} GitHub token.
|
2022-10-02 17:05:13 +08:00
|
|
|
*/
|
|
|
|
export const getGithubToken = () => {
|
2022-10-02 23:41:28 +08:00
|
|
|
const token = getInput("github_token") || process.env.GITHUB_TOKEN;
|
2022-10-02 17:05:13 +08:00
|
|
|
if (!token) {
|
|
|
|
throw Error("Could not find github token");
|
|
|
|
}
|
|
|
|
return token;
|
|
|
|
};
|