From 8306396300f55b22173ab98cc9a159cf291ba01d Mon Sep 17 00:00:00 2001 From: Shubh Bapna <38372682+shubhbapna@users.noreply.github.com> Date: Fri, 10 Feb 2023 05:16:37 -0500 Subject: [PATCH] use group from user input when using branch flow (#380) * use input.group when using branch flow * added unit tests --- src/service/checkout/checkout-service.ts | 2 +- src/service/config/configuration-service.ts | 4 ++++ .../service/config/configuration-service.test.ts | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/service/checkout/checkout-service.ts b/src/service/checkout/checkout-service.ts index 7b59679b..bc7c5862 100644 --- a/src/service/checkout/checkout-service.ts +++ b/src/service/checkout/checkout-service.ts @@ -122,7 +122,7 @@ export class CheckoutService { // target branch is guaranteed to exist since base always exist mappedBranch: getMappedTarget(starterNode.project, starterNode.mapping, node.project, node.mapping, originalTarget.branch!), name: node.project.split("/")[1], - group: node.project.split("/")[0], + group: this.config.getGroupName() ?? node.project.split("/")[0], }; const originalSource = this.config.getSourceProject(); diff --git a/src/service/config/configuration-service.ts b/src/service/config/configuration-service.ts index 7e58866f..3ae3598e 100644 --- a/src/service/config/configuration-service.ts +++ b/src/service/config/configuration-service.ts @@ -213,4 +213,8 @@ export class ConfigurationService { getEventUrl(): string { return this.getFlowType() === FlowType.BRANCH ? "" : this.configuration.gitEventData.html_url; } + + getGroupName(): string | undefined { + return this.getFlowType() === FlowType.BRANCH ? this.configuration.parsedInputs.group : undefined; + } } diff --git a/test/unitary/service/config/configuration-service.test.ts b/test/unitary/service/config/configuration-service.test.ts index aa5489ac..4bb07291 100644 --- a/test/unitary/service/config/configuration-service.test.ts +++ b/test/unitary/service/config/configuration-service.test.ts @@ -365,4 +365,16 @@ describe("methods", () => { .mockImplementationOnce(() => ({ html_url: expected } as EventData)); expect(config.getEventUrl()).toBe(expected); }); + + test.each([ + ["branch flow", FlowType.BRANCH, "group"], + ["non branch flow", FlowType.CROSS_PULL_REQUEST, undefined], + ])("getGroupName", (title: string, flowType: FlowType, group?: string) => { + currentInput = { + ...defaultInputValues, + CLISubCommand: flowType, + group + }; + expect(config.getGroupName()).toBe(group); + }); });