diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 51ae923..50d0472 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,6 +36,7 @@ jobs: - name: Fetch pull request data run: npm run compose-db env: + GRAPHQL_TOKEN: ${{ secrets.GRAPHQL_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Archive production artifacts diff --git a/.gitignore b/.gitignore index 6206d86..f40a54f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ +# Project folders. node_modules/ out/ +logs/ + +# Development environments. .idea/ +.vscode/ diff --git a/README.md b/README.md index ab9524e..f9a7c5e 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ should work just fine). This project uses GitHub's GraphQL API. To fetch live data you need to generate a [personal OAuth token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token). -You can supply your token to the scripts using the `GITHUB_TOKEN` environment +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 may not be able to access all the information used when generating the database. diff --git a/compose-db.js b/compose-db.js index 30848a2..5c6380a 100644 --- a/compose-db.js +++ b/compose-db.js @@ -36,7 +36,9 @@ async function fetchGithub(query) { init.headers = {}; init.headers["Content-Type"] = "application/json"; init.headers["Accept"] = "application/vnd.github.merge-info-preview+json"; - if (process.env.GITHUB_TOKEN) { + if (process.env.GRAPHQL_TOKEN) { + init.headers["Authorization"] = `token ${process.env.GRAPHQL_TOKEN}`; + } else if (process.env.GITHUB_TOKEN) { init.headers["Authorization"] = `token ${process.env.GITHUB_TOKEN}`; } @@ -47,6 +49,14 @@ async function fetchGithub(query) { return await fetch("https://api.github.com/graphql", init); } +async function logResponse(data, name) { + try { + await fs.writeFile(`logs/${name}.json`, JSON.stringify(data, null, 4), {encoding: "utf-8"}); + } catch (err) { + console.error("Error saving log file: " + err); + } +} + function handleErrors(data) { if (typeof data["errors"] === "undefined") { return; @@ -88,6 +98,7 @@ async function checkRates() { } const data = await res.json(); + logResponse(data, "_rate_limit"); handleErrors(data); const rate_limit = data.data["rateLimit"]; @@ -201,6 +212,7 @@ async function fetchPulls(page) { } const data = await res.json(); + logResponse(data, `data_page_${page}`); handleErrors(data); const rate_limit = data.data["rateLimit"];