Skip to content

Commit 3c376fb

Browse files
committed
CIHelper: allow callers to specify installation access tokens explicitly
It is much better to be intentional about repository access, especially in the upcoming GitHub Action, instead of magically setting the tokens via a couple of config variables. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent eccd2cb commit 3c376fb

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

lib/ci-helper.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class CIHelper {
3737
protected testing: boolean;
3838
private gggNotesUpdated: boolean;
3939
private mail2CommitMapUpdated: boolean;
40+
private notesPushToken: string | undefined;
4041
protected maxCommitsExceptions: string[];
4142

4243
public constructor(workDir: string, skipUpdate?: boolean, gggConfigDir = ".") {
@@ -53,6 +54,13 @@ export class CIHelper {
5354
this.urlRepo = `${this.urlBase}${this.config.repo.name}/`;
5455
}
5556

57+
public setAccessToken(repositoryOwner: string, token: string): void {
58+
this.github.setAccessToken(repositoryOwner, token);
59+
if (this.config.repo.owner === repositoryOwner) {
60+
this.notesPushToken = token;
61+
}
62+
}
63+
5664
/*
5765
* Given a commit that was contributed as a patch via GitGitGadget (i.e.
5866
* a commit with a Message-ID recorded in `refs/notes/gitgitgadget`),
@@ -243,7 +251,7 @@ export class CIHelper {
243251
}
244252
}
245253
if (result) {
246-
await this.notes.push(this.urlRepo);
254+
await this.pushNotesRef();
247255
}
248256
return result;
249257
}
@@ -408,7 +416,7 @@ export class CIHelper {
408416
}
409417

410418
if (notesUpdated || optionsUpdated) {
411-
await this.notes.push(this.urlRepo);
419+
await this.pushNotesRef();
412420
}
413421

414422
return [notesUpdated, optionsUpdated];
@@ -806,7 +814,7 @@ export class CIHelper {
806814
this.config.mailrepo.branch,
807815
);
808816
if (await mailArchiveGit.processMails(prFilter)) {
809-
await this.notes.push(this.urlRepo);
817+
await this.pushNotesRef();
810818
return true;
811819
}
812820
return false;
@@ -878,7 +886,7 @@ export class CIHelper {
878886
if (optionsChanged) {
879887
console.log(`Changed options:\n${toPrettyJSON(options)}`);
880888
await this.notes.set("", options, true);
881-
await this.notes.push(this.urlRepo);
889+
await this.pushNotesRef();
882890
}
883891

884892
return optionsChanged;
@@ -933,4 +941,8 @@ export class CIHelper {
933941
this.mail2CommitMapUpdated = true;
934942
}
935943
}
944+
945+
private async pushNotesRef(): Promise<void> {
946+
await this.notes.push(this.urlRepo, this.notesPushToken);
947+
}
936948
}

0 commit comments

Comments
 (0)