Skip to content

Commit e427891

Browse files
committed
use env var GITHUB_TOKEN for api calls (if set)
1 parent ba3c4cd commit e427891

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

eslint.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export default defineConfig([
2525
languageOptions: {
2626
ecmaVersion: "latest",
2727
globals: {
28-
...globals.browser
28+
...globals.browser,
29+
process: "readonly"
2930
}
3031
},
3132
plugins: {js, stylistic},

scripts/updateGitHubApiData.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ function printProgress (count, total) {
1212
// Function to check whether new data should be retrieved.
1313
function shouldFetch (repository) {
1414
let retrieve = false;
15-
if (repository.url.includes("github.com")) {
16-
if (queryCount < maxQueryCount) {
15+
if (repository.url.includes("github.com") && maxQueryCount > 0) {
16+
if (queryCount < maxQueryCount || process.env.GITHUB_TOKEN) {
1717
retrieve = true;
1818
}
1919
}
@@ -75,6 +75,11 @@ async function updateData () {
7575

7676
sortModuleListByLastUpdate(previousData, moduleList);
7777

78+
const headers = {};
79+
if (process.env.GITHUB_TOKEN) {
80+
headers.Authorization = `Bearer ${process.env.GITHUB_TOKEN}`;
81+
}
82+
7883
for (const module of moduleList) {
7984
const repositoryId = module.id;
8085
const repositoryApiUrl = `https://api.github.com/repos/${repositoryId}`;
@@ -85,12 +90,12 @@ async function updateData () {
8590

8691
if (shouldFetchData) {
8792
printProgress(moduleCount, moduleListLength);
88-
const response = await fetch(repositoryApiUrl);
93+
const response = await fetch(repositoryApiUrl, {headers});
8994
const data = await response.json();
9095
queryCount += 1;
9196

9297
const branchUrl = `https://api.github.com/repos/${repositoryId}/commits/${data.default_branch}`;
93-
const branchResponse = await fetch(branchUrl);
98+
const branchResponse = await fetch(branchUrl, {headers});
9499
const branchData = await branchResponse.json();
95100
queryCount += 1;
96101

0 commit comments

Comments
 (0)