Skip to content

Commit 9aa666f

Browse files
committed
GitGitGadget: set the token (if any) to push the Git notes
This continues the new paradigm where the token is _not_ specified via the Git config, but explicitly via a method of the `CIHelper` class. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 3c376fb commit 9aa666f

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/ci-helper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ export class CIHelper {
576576
};
577577

578578
try {
579-
const gitGitGadget = await GitGitGadget.get(this.gggConfigDir, this.workDir);
579+
const gitGitGadget = await GitGitGadget.get(this.gggConfigDir, this.workDir, this.notesPushToken);
580580
if (!gitGitGadget.isUserAllowed(comment.author)) {
581581
throw new Error(`User ${comment.author} is not yet permitted to use ${this.config.app.displayName}`);
582582
}
@@ -782,7 +782,7 @@ export class CIHelper {
782782
await this.github.addPRComment(prKey, redacted);
783783
};
784784

785-
const gitGitGadget = await GitGitGadget.get(this.gggConfigDir, this.workDir);
785+
const gitGitGadget = await GitGitGadget.get(this.gggConfigDir, this.workDir, this.notesPushToken);
786786
if (!pr.hasComments && !gitGitGadget.isUserAllowed(pr.author)) {
787787
const welcome = (await readFile("res/WELCOME.md")).toString().replace(/\${username}/g, pr.author);
788788
await this.github.addPRComment(prKey, welcome);

lib/gitgitgadget.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class GitGitGadget {
3636
return workDir;
3737
}
3838

39-
public static async get(gitGitGadgetDir: string, workDir?: string): Promise<GitGitGadget> {
39+
public static async get(gitGitGadgetDir: string, workDir?: string, notesPushToken?: string): Promise<GitGitGadget> {
4040
if (!workDir) {
4141
workDir = await this.getWorkDir(gitGitGadgetDir);
4242
}
@@ -76,6 +76,7 @@ export class GitGitGadget {
7676
allowedUsers,
7777
{ smtpHost, smtpOpts, smtpPass, smtpUser },
7878
publishTagsAndNotesToRemote,
79+
notesPushToken,
7980
);
8081
}
8182

@@ -98,13 +99,15 @@ export class GitGitGadget {
9899
protected readonly smtpOptions: ISMTPOptions;
99100

100101
protected readonly publishTagsAndNotesToRemote: string;
102+
private readonly publishToken: string | undefined;
101103

102104
protected constructor(
103105
notes: GitNotes,
104106
options: IGitGitGadgetOptions,
105107
allowedUsers: Set<string>,
106108
smtpOptions: ISMTPOptions,
107109
publishTagsAndNotesToRemote: string,
110+
publishToken?: string,
108111
) {
109112
if (!notes.workDir) {
110113
throw new Error("Could not determine Git worktree");
@@ -117,6 +120,7 @@ export class GitGitGadget {
117120
this.smtpOptions = smtpOptions;
118121

119122
this.publishTagsAndNotesToRemote = publishTagsAndNotesToRemote;
123+
this.publishToken = publishToken;
120124
}
121125

122126
public isUserAllowed(user: string): boolean {
@@ -240,7 +244,7 @@ export class GitGitGadget {
240244
}
241245

242246
protected async pushNotesRef(): Promise<void> {
243-
await this.notes.push(this.publishTagsAndNotesToRemote);
247+
await this.notes.push(this.publishTagsAndNotesToRemote, this.publishToken);
244248

245249
// re-read options
246250
[this.options, this.allowedUsers] = await GitGitGadget.readOptions(this.notes);

0 commit comments

Comments
 (0)