Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ jspm_packages
.yarn-integrity


# Local secrets (GITHUB_TOKEN)
.env

# Build output and Astro caches
dist/
.astro/
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ npm run lint:js # ESLint; lint:css = Stylelint, format = Prettier
npm run clean # remove build output and caches
```

Module and "Good First Issue" data come from the GitHub GraphQL API and need a GitHub [personal access token] (no extra scopes) in the environment as `GITHUB_TOKEN`.
Module and "Good First Issue" data come from the GitHub GraphQL API and need a GitHub [personal access token] (no extra scopes) in the environment as `GITHUB_TOKEN`, or in a git-ignored `.env` file in the project root (`GITHUB_TOKEN=...`).
With the GitHub CLI you can pass your login token for one build: `GITHUB_TOKEN=$(gh auth token) npm run build`.
Without it the build still completes: it warns and renders module pages from previously cached data, or empty if there is none.
Fetched data is cached for 12 hours in `.astro/`; `npm run clean` forces a refetch.
Contributor program topics and mentors come from public Trello boards and need no token.
Expand Down
14 changes: 13 additions & 1 deletion src/loaders/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ async function gql<T>(token: string, query: string, variables = {}): Promise<T>
return json.data;
}

/** GITHUB_TOKEN from the environment, else from a local .env file. */
function githubToken(): string | undefined {
if (!process.env.GITHUB_TOKEN) {
try {
process.loadEnvFile();
} catch {
// no .env file
}
}
return process.env.GITHUB_TOKEN;
}

/**
* Wraps a fetch in the shared policy: reuse store data younger than 12h,
* and without GITHUB_TOKEN (or on fetch errors) keep whatever is stored.
Expand All @@ -94,7 +106,7 @@ function cachedLoader(
logger.info(`using cached data (${store.keys().length} entries)`);
return;
}
const token = process.env.GITHUB_TOKEN;
const token = githubToken();
if (!token) {
logger.warn(`GITHUB_TOKEN not set; keeping ${store.keys().length} cached entries`);
return;
Expand Down
Loading