Skip to content

Commit 20410eb

Browse files
committed
github-glue: allow setting the repository access token directly
This is not yet used, but will come in really handy when moving GitGitGadget to a GitHub Action. No more fiddling with secrets in the Git config! Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent b80b25b commit 20410eb

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/github-glue.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export class GitHubGlue {
5757
protected authenticated?: string;
5858
protected owner: string;
5959
protected repo: string;
60+
private tokens: Map<string, string> = new Map();
6061

6162
public constructor(workDir: string, owner: string, repo: string) {
6263
this.owner = owner;
@@ -472,12 +473,19 @@ export class GitHubGlue {
472473
}
473474
}
474475

476+
public setAccessToken(repositoryOwner: string, token: string): void {
477+
this.tokens.set(repositoryOwner, token);
478+
}
479+
475480
protected async ensureAuthenticated(repositoryOwner: string): Promise<void> {
476481
if (repositoryOwner !== this.authenticated) {
477-
const infix = repositoryOwner === "gitgitgadget" ? "" : `.${repositoryOwner}`;
478-
const tokenKey = `gitgitgadget${infix}.githubToken`;
479-
const tokenVar = tokenKey.toUpperCase().replace(/\./, "_");
480-
const token = process.env[tokenVar] ? process.env[tokenVar] : await gitConfig(tokenKey);
482+
let token = this.tokens.get(repositoryOwner);
483+
if (!token) {
484+
const infix = repositoryOwner === "gitgitgadget" ? "" : `.${repositoryOwner}`;
485+
const tokenKey = `gitgitgadget${infix}.githubToken`;
486+
const tokenVar = tokenKey.toUpperCase().replace(/\./, "_");
487+
token = process.env[tokenVar] ? process.env[tokenVar] : await gitConfig(tokenKey);
488+
}
481489
if (!token) {
482490
throw new Error(`Need a GitHub token for ${repositoryOwner}`);
483491
}

0 commit comments

Comments
 (0)