Integrate GRAPHQL_TOKEN enhancements & checks

This commit is contained in:
Thaddeus Crews
2025-06-26 10:27:50 -05:00
parent 652d0d4fc8
commit 4c69f71cfa
4 changed files with 22 additions and 3 deletions

3
.gitignore vendored
View File

@@ -1,3 +1,6 @@
# Environment variables.
.env
# Project folders. # Project folders.
node_modules/ node_modules/
out/ out/

View File

@@ -32,6 +32,10 @@ You can supply your token to the scripts using the `GRAPHQL_TOKEN` environment
variable. Note, that if you don't have member access to the organization, you variable. Note, that if you don't have member access to the organization, you
may not be able to access all the information used when generating the database. may not be able to access all the information used when generating the database.
> [!TIP]
For convenience, it's recommended to store the `GRAPHQL_TOKEN` environment variable
in a `.env` file at the repository root.
### Building the website ### Building the website
1. Clone or download the project. 1. Clone or download the project.

View File

@@ -161,6 +161,10 @@ class DataFetcher {
init.headers["Authorization"] = `token ${process.env.GRAPHQL_TOKEN}`; init.headers["Authorization"] = `token ${process.env.GRAPHQL_TOKEN}`;
} else if (process.env.GITHUB_TOKEN) { } else if (process.env.GITHUB_TOKEN) {
init.headers["Authorization"] = `token ${process.env.GITHUB_TOKEN}`; init.headers["Authorization"] = `token ${process.env.GITHUB_TOKEN}`;
} else {
console.error(" Unable to find environment variable: `GRAPHQL_TOKEN`. Did you forget to set it in your local environment or a root `.env` file?");
process.exitCode = buildCommon.ExitCodes.ParseFailure;
return [null, null];
} }
init.body = JSON.stringify({ init.body = JSON.stringify({
@@ -204,6 +208,10 @@ class DataFetcher {
init.headers["Authorization"] = `token ${process.env.GRAPHQL_TOKEN}`; init.headers["Authorization"] = `token ${process.env.GRAPHQL_TOKEN}`;
} else if (process.env.GITHUB_TOKEN) { } else if (process.env.GITHUB_TOKEN) {
init.headers["Authorization"] = `token ${process.env.GITHUB_TOKEN}`; init.headers["Authorization"] = `token ${process.env.GITHUB_TOKEN}`;
} else {
console.error(" Unable to find environment variable: `GRAPHQL_TOKEN`. Did you forget to set it in your local environment or a root `.env` file?");
process.exitCode = buildCommon.ExitCodes.ParseFailure;
return null;
} }
return await fetch(`${this.api_rest_path}${query}`, init); return await fetch(`${this.api_rest_path}${query}`, init);
@@ -218,7 +226,9 @@ class DataFetcher {
`; `;
const [res, data] = await this.fetchGithub(query); const [res, data] = await this.fetchGithub(query);
if (res.status !== 200 || data === null) { if (res === null) {
return;
} else if (res.status !== 200 || data === null) {
this._handleResponseErrors(this.api_repository_id, res); this._handleResponseErrors(this.api_repository_id, res);
process.exitCode = buildCommon.ExitCodes.RequestFailure; process.exitCode = buildCommon.ExitCodes.RequestFailure;
return; return;
@@ -323,7 +333,9 @@ class DataFetcher {
console.log(` Requesting batch ${page}/${totalPages} of commit and pull request data.`); console.log(` Requesting batch ${page}/${totalPages} of commit and pull request data.`);
const [res, data] = await this.fetchGithub(query, API_MAX_RETRIES); const [res, data] = await this.fetchGithub(query, API_MAX_RETRIES);
if (res.status !== 200 || data === null) { if (res === null) {
return;
} else if (res.status !== 200 || data === null) {
this._handleResponseErrors(this.api_repository_id, res); this._handleResponseErrors(this.api_repository_id, res);
process.exitCode = buildCommon.ExitCodes.RequestFailure; process.exitCode = buildCommon.ExitCodes.RequestFailure;
return []; return [];

View File

@@ -4,7 +4,7 @@
"description": "", "description": "",
"scripts": { "scripts": {
"build": "rollup -c", "build": "rollup -c",
"compose-db": "node ./compose-db.js", "compose-db": "node --env-file-if-exists=./.env ./compose-db.js",
"publish-db": "node ./publish-db.js" "publish-db": "node ./publish-db.js"
}, },
"author": "Yuri Sizov <yuris@humnom.net>", "author": "Yuri Sizov <yuris@humnom.net>",