mirror of
https://github.com/kiegroup/git-backporting.git
synced 2025-06-29 14:13:48 +00:00
feat: override local git user config
This commit is contained in:
parent
22bec0c537
commit
ee692c3db4
16 changed files with 182 additions and 73 deletions
|
@ -24,7 +24,8 @@ describe("cli args parser", () => {
|
|||
const args: Args = parser.parse();
|
||||
expect(args.dryRun).toEqual(false);
|
||||
expect(args.auth).toEqual("");
|
||||
expect(args.author).toEqual(undefined);
|
||||
expect(args.gitUser).toEqual("GitHub");
|
||||
expect(args.gitEmail).toEqual("noreply@github.com");
|
||||
expect(args.folder).toEqual(undefined);
|
||||
expect(args.targetBranch).toEqual("target");
|
||||
expect(args.pullRequest).toEqual("https://localhost/whatever/pulls/1");
|
||||
|
@ -45,7 +46,8 @@ describe("cli args parser", () => {
|
|||
const args: Args = parser.parse();
|
||||
expect(args.dryRun).toEqual(false);
|
||||
expect(args.auth).toEqual("");
|
||||
expect(args.author).toEqual(undefined);
|
||||
expect(args.gitUser).toEqual("GitHub");
|
||||
expect(args.gitEmail).toEqual("noreply@github.com");
|
||||
expect(args.folder).toEqual(undefined);
|
||||
expect(args.targetBranch).toEqual("target");
|
||||
expect(args.pullRequest).toEqual("https://localhost/whatever/pulls/1");
|
||||
|
@ -63,13 +65,18 @@ describe("cli args parser", () => {
|
|||
"-tb",
|
||||
"target",
|
||||
"-pr",
|
||||
"https://localhost/whatever/pulls/1"
|
||||
"https://localhost/whatever/pulls/1",
|
||||
"-gu",
|
||||
"Me",
|
||||
"-ge",
|
||||
"me@email.com",
|
||||
]);
|
||||
|
||||
const args: Args = parser.parse();
|
||||
expect(args.dryRun).toEqual(true);
|
||||
expect(args.auth).toEqual("bearer-token");
|
||||
expect(args.author).toEqual(undefined);
|
||||
expect(args.gitUser).toEqual("Me");
|
||||
expect(args.gitEmail).toEqual("me@email.com");
|
||||
expect(args.folder).toEqual(undefined);
|
||||
expect(args.targetBranch).toEqual("target");
|
||||
expect(args.pullRequest).toEqual("https://localhost/whatever/pulls/1");
|
||||
|
@ -88,6 +95,10 @@ describe("cli args parser", () => {
|
|||
"target",
|
||||
"--pull-request",
|
||||
"https://localhost/whatever/pulls/1",
|
||||
"--git-user",
|
||||
"Me",
|
||||
"--git-email",
|
||||
"me@email.com",
|
||||
"--title",
|
||||
"New Title",
|
||||
"--body",
|
||||
|
@ -101,7 +112,8 @@ describe("cli args parser", () => {
|
|||
const args: Args = parser.parse();
|
||||
expect(args.dryRun).toEqual(true);
|
||||
expect(args.auth).toEqual("bearer-token");
|
||||
expect(args.author).toEqual(undefined);
|
||||
expect(args.gitUser).toEqual("Me");
|
||||
expect(args.gitEmail).toEqual("me@email.com");
|
||||
expect(args.folder).toEqual(undefined);
|
||||
expect(args.targetBranch).toEqual("target");
|
||||
expect(args.pullRequest).toEqual("https://localhost/whatever/pulls/1");
|
||||
|
|
|
@ -14,6 +14,22 @@ describe("gha args parser", () => {
|
|||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
test("getOrDefault", () => {
|
||||
spyGetInput({
|
||||
"present": "value"
|
||||
});
|
||||
expect(parser.getOrDefault("not-present", "default")).toStrictEqual("default");
|
||||
expect(parser.getOrDefault("present", "default")).toStrictEqual("value");
|
||||
});
|
||||
|
||||
test("getOrUndefined", () => {
|
||||
spyGetInput({
|
||||
"present": "value",
|
||||
"empty": ""
|
||||
});
|
||||
expect(parser.getOrUndefined("empty")).toStrictEqual(undefined);
|
||||
expect(parser.getOrUndefined("present")).toStrictEqual("value");
|
||||
});
|
||||
|
||||
test("valid execution [default]", () => {
|
||||
spyGetInput({
|
||||
|
@ -24,7 +40,8 @@ describe("gha args parser", () => {
|
|||
const args: Args = parser.parse();
|
||||
expect(args.dryRun).toEqual(false);
|
||||
expect(args.auth).toEqual("");
|
||||
expect(args.author).toEqual(undefined);
|
||||
expect(args.gitUser).toEqual("GitHub");
|
||||
expect(args.gitEmail).toEqual("noreply@github.com");
|
||||
expect(args.folder).toEqual(undefined);
|
||||
expect(args.targetBranch).toEqual("target");
|
||||
expect(args.pullRequest).toEqual("https://localhost/whatever/pulls/1");
|
||||
|
@ -40,6 +57,8 @@ describe("gha args parser", () => {
|
|||
"auth": "bearer-token",
|
||||
"target-branch": "target",
|
||||
"pull-request": "https://localhost/whatever/pulls/1",
|
||||
"git-user": "Me",
|
||||
"git-email": "me@email.com",
|
||||
"title": "New Title",
|
||||
"body": "New Body",
|
||||
"body-prefix": "New Body Prefix",
|
||||
|
@ -49,7 +68,8 @@ describe("gha args parser", () => {
|
|||
const args: Args = parser.parse();
|
||||
expect(args.dryRun).toEqual(true);
|
||||
expect(args.auth).toEqual("bearer-token");
|
||||
expect(args.author).toEqual(undefined);
|
||||
expect(args.gitUser).toEqual("Me");
|
||||
expect(args.gitEmail).toEqual("me@email.com");
|
||||
expect(args.folder).toEqual(undefined);
|
||||
expect(args.targetBranch).toEqual("target");
|
||||
expect(args.pullRequest).toEqual("https://localhost/whatever/pulls/1");
|
||||
|
|
|
@ -33,13 +33,18 @@ describe("pull request config parser", () => {
|
|||
dryRun: false,
|
||||
auth: "",
|
||||
pullRequest: mergedPRUrl,
|
||||
targetBranch: "prod"
|
||||
targetBranch: "prod",
|
||||
gitUser: "GitHub",
|
||||
gitEmail: "noreply@github.com"
|
||||
};
|
||||
|
||||
const configs: Configs = await parser.parseAndValidate(args);
|
||||
|
||||
expect(configs.dryRun).toEqual(false);
|
||||
expect(configs.author).toEqual("gh-user");
|
||||
expect(configs.git).toEqual({
|
||||
user: "GitHub",
|
||||
email: "noreply@github.com"
|
||||
});
|
||||
expect(configs.auth).toEqual("");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
|
@ -68,7 +73,7 @@ describe("pull request config parser", () => {
|
|||
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"]
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
author: "gh-user",
|
||||
author: "GitHub",
|
||||
url: undefined,
|
||||
htmlUrl: undefined,
|
||||
title: "[prod] PR Title",
|
||||
|
@ -96,7 +101,9 @@ describe("pull request config parser", () => {
|
|||
auth: "whatever",
|
||||
pullRequest: mergedPRUrl,
|
||||
targetBranch: "prod",
|
||||
folder: "/tmp/test"
|
||||
folder: "/tmp/test",
|
||||
gitUser: "GitHub",
|
||||
gitEmail: "noreply@github.com"
|
||||
};
|
||||
|
||||
const configs: Configs = await parser.parseAndValidate(args);
|
||||
|
@ -105,6 +112,10 @@ describe("pull request config parser", () => {
|
|||
expect(configs.auth).toEqual("whatever");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual("/tmp/test");
|
||||
expect(configs.git).toEqual({
|
||||
user: "GitHub",
|
||||
email: "noreply@github.com"
|
||||
});
|
||||
});
|
||||
|
||||
test("override author", async () => {
|
||||
|
@ -113,7 +124,8 @@ describe("pull request config parser", () => {
|
|||
auth: "whatever",
|
||||
pullRequest: mergedPRUrl,
|
||||
targetBranch: "prod",
|
||||
author: "another-user"
|
||||
gitUser: "GitHub",
|
||||
gitEmail: "noreply@github.com"
|
||||
};
|
||||
|
||||
const configs: Configs = await parser.parseAndValidate(args);
|
||||
|
@ -121,7 +133,10 @@ describe("pull request config parser", () => {
|
|||
expect(configs.dryRun).toEqual(true);
|
||||
expect(configs.auth).toEqual("whatever");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.author).toEqual("another-user");
|
||||
expect(configs.git).toEqual({
|
||||
user: "GitHub",
|
||||
email: "noreply@github.com"
|
||||
});
|
||||
});
|
||||
|
||||
test("still open pull request", async () => {
|
||||
|
@ -129,7 +144,9 @@ describe("pull request config parser", () => {
|
|||
dryRun: true,
|
||||
auth: "whatever",
|
||||
pullRequest: openPRUrl,
|
||||
targetBranch: "prod"
|
||||
targetBranch: "prod",
|
||||
gitUser: "GitHub",
|
||||
gitEmail: "noreply@github.com"
|
||||
};
|
||||
|
||||
const configs: Configs = await parser.parseAndValidate(args);
|
||||
|
@ -137,7 +154,10 @@ describe("pull request config parser", () => {
|
|||
expect(configs.dryRun).toEqual(true);
|
||||
expect(configs.auth).toEqual("whatever");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.author).toEqual("gh-user");
|
||||
expect(configs.git).toEqual({
|
||||
user: "GitHub",
|
||||
email: "noreply@github.com"
|
||||
});
|
||||
expect(configs.originalPullRequest).toEqual({
|
||||
number: 4444,
|
||||
author: "gh-user",
|
||||
|
@ -171,7 +191,9 @@ describe("pull request config parser", () => {
|
|||
dryRun: true,
|
||||
auth: "whatever",
|
||||
pullRequest: notMergedPRUrl,
|
||||
targetBranch: "prod"
|
||||
targetBranch: "prod",
|
||||
gitUser: "GitHub",
|
||||
gitEmail: "noreply@github.com"
|
||||
};
|
||||
|
||||
expect(async () => await parser.parseAndValidate(args)).rejects.toThrow("Provided pull request is closed and not merged!");
|
||||
|
@ -183,6 +205,8 @@ describe("pull request config parser", () => {
|
|||
auth: "",
|
||||
pullRequest: mergedPRUrl,
|
||||
targetBranch: "prod",
|
||||
gitUser: "Me",
|
||||
gitEmail: "me@email.com",
|
||||
title: "New Title",
|
||||
body: "New Body",
|
||||
bodyPrefix: "New Body Prefix -",
|
||||
|
@ -191,7 +215,10 @@ describe("pull request config parser", () => {
|
|||
const configs: Configs = await parser.parseAndValidate(args);
|
||||
|
||||
expect(configs.dryRun).toEqual(false);
|
||||
expect(configs.author).toEqual("gh-user");
|
||||
expect(configs.git).toEqual({
|
||||
user: "Me",
|
||||
email: "me@email.com"
|
||||
});
|
||||
expect(configs.auth).toEqual("");
|
||||
expect(configs.targetBranch).toEqual("prod");
|
||||
expect(configs.folder).toEqual(process.cwd() + "/bp");
|
||||
|
@ -221,7 +248,7 @@ describe("pull request config parser", () => {
|
|||
commits: ["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"],
|
||||
});
|
||||
expect(configs.backportPullRequest).toEqual({
|
||||
author: "gh-user",
|
||||
author: "Me",
|
||||
url: undefined,
|
||||
htmlUrl: undefined,
|
||||
title: "New Title",
|
||||
|
|
|
@ -69,7 +69,10 @@ afterAll(async () => {
|
|||
|
||||
beforeEach(() => {
|
||||
// create a fresh instance of git before each test
|
||||
git = new GitCLIService("", "author");
|
||||
git = new GitCLIService("", {
|
||||
user: "user",
|
||||
email: "user@email.com"
|
||||
});
|
||||
});
|
||||
|
||||
describe("git cli service", () => {
|
||||
|
|
|
@ -12,6 +12,6 @@ export const resetProcessArgs = () => {
|
|||
export const spyGetInput = (obj: any) => {
|
||||
const mock = jest.spyOn(core, "getInput");
|
||||
mock.mockImplementation((name: string) : string => {
|
||||
return obj[name];
|
||||
return obj[name] ?? "";
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue