Skip to content

Commit d525789

Browse files
committed
Add label 'new user' on PRs for new GitGitGadget users
Suggested (among other suggestions) in gitgitgadget#414 (comment) Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 72bd222 commit d525789

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/ci-helper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,8 @@ export class CIHelper {
796796
const welcome = (await readFile("res/WELCOME.md")).toString()
797797
.replace(/\${username}/g, pr.author);
798798
await this.github.addPRComment(pullRequestURL, welcome);
799+
800+
await this.github.addPRLabels(pullRequestURL, ["new user"]);
799801
}
800802

801803
const commitOkay = await this.checkCommits(pr, addComment);

tests/ci-helper.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class TestCIHelper extends CIHelper {
4242
public ghGlue: GitHubGlue; // not readonly reference
4343
public addPRCommentCalls: string[][]; // reference mock.calls
4444
public updatePRCalls: string[][]; // reference mock.calls
45+
public addPRLabelsCalls: any[][]; // reference mock.calls
4546

4647
public constructor(workDir?: string, debug = false, gggDir = ".") {
4748
super(workDir, debug, gggDir);
@@ -61,6 +62,12 @@ class TestCIHelper extends CIHelper {
6162
this.ghGlue.updatePR = updatePR;
6263
this.updatePRCalls = updatePR.mock.calls;
6364

65+
const addPRLabels = jest.fn( async (_:string, labels: string[]):
66+
// eslint-disable-next-line @typescript-eslint/require-await
67+
Promise<string[]> => labels );
68+
this.ghGlue.addPRLabels = addPRLabels;
69+
this.addPRLabelsCalls = addPRLabels.mock.calls;
70+
6471
// need keys to authenticate
6572
// this.ghGlue.ensureAuthenticated = async (): Promise<void> => {};
6673
}
@@ -887,6 +894,7 @@ test("handle push/comment too many commits fails", async () => {
887894

888895
expect(ci.addPRCommentCalls[0][1]).toMatch(/Welcome/);
889896
expect(ci.addPRCommentCalls[1][1]).toMatch(failMsg);
897+
expect(ci.addPRLabelsCalls[0][1]).toEqual(["new user"]);
890898
});
891899

892900
test("handle push/comment merge commits fails", async () => {
@@ -990,6 +998,7 @@ test("handle push/comment merge commits fails", async () => {
990998

991999
expect(ci.addPRCommentCalls[0][1]).toMatch(/Welcome/);
9921000
expect(ci.addPRCommentCalls[1][1]).toMatch(commits[0].commit);
1001+
expect(ci.addPRLabelsCalls[0][1]).toEqual(["new user"]);
9931002
ci.addPRCommentCalls.length = 0;
9941003

9951004
// Test Multiple merges

0 commit comments

Comments
 (0)