Skip to content

Commit 07b75b0

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

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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: 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: headers});
9499
const branchData = await branchResponse.json();
95100
queryCount += 1;
96101

0 commit comments

Comments
 (0)