From 4ed1942d56d477a9db95a9ecae40d5c525ca87f1 Mon Sep 17 00:00:00 2001 From: Roy Golan Date: Tue, 13 Jun 2023 15:37:28 +0300 Subject: [PATCH] Add "branch" optional parameter to MTA analysis Signed-off-by: Roy Golan --- .../tasks/migrationtoolkit/CreateApplicationTask.java | 6 ++++-- .../tasks/migrationtoolkit/MTAApplicationClient.java | 2 +- .../migrationtoolkit/CreateApplicationTaskTest.java | 10 ++++++---- .../tasks/migrationtoolkit/GetApplicationTaskTest.java | 5 +++-- .../parodos/tasks/migrationtoolkit/TestConsts.java | 2 ++ .../migrationtoolkit/MigrationAssessmentWorkflow.java | 4 +++- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/migrationtoolkit/CreateApplicationTask.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/migrationtoolkit/CreateApplicationTask.java index 5ee15b127..919492e6c 100644 --- a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/migrationtoolkit/CreateApplicationTask.java +++ b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/migrationtoolkit/CreateApplicationTask.java @@ -39,21 +39,23 @@ public CreateApplicationTask(URI serverURL, String bearerToken) { */ @Override public WorkReport execute(WorkContext workContext) { - String appName, repo; + String appName, repo, branch; try { appName = getOptionalParameterValue("applicationName", ""); repo = getRequiredParameterValue("repositoryURL"); + if (mtaClient == null) { var serverUrl = getOptionalParameterValue("serverURL", null); var bearerToken = getOptionalParameterValue("bearerToken", null); this.mtaClient = new MTAClient(URI.create(serverUrl), bearerToken); } + branch = getOptionalParameterValue("branch", null); } catch (MissingParameterException e) { return new DefaultWorkReport(WorkStatus.FAILED, workContext, e); } - Result result = mtaClient.create(new App(0, appName, new Repository("git", repo))); + Result result = mtaClient.create(new App(0, appName, new Repository("git", repo, branch))); if (result == null) { // unexpected diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/migrationtoolkit/MTAApplicationClient.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/migrationtoolkit/MTAApplicationClient.java index a637702c7..28a0e9afe 100644 --- a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/migrationtoolkit/MTAApplicationClient.java +++ b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/migrationtoolkit/MTAApplicationClient.java @@ -1,6 +1,6 @@ package com.redhat.parodos.tasks.migrationtoolkit; -record Repository(String kind, String url) { +record Repository(String kind, String url, String branch) { } record App(int id, String name, Repository repository) { diff --git a/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/migrationtoolkit/CreateApplicationTaskTest.java b/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/migrationtoolkit/CreateApplicationTaskTest.java index 1e8c84663..bc28eaf83 100644 --- a/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/migrationtoolkit/CreateApplicationTaskTest.java +++ b/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/migrationtoolkit/CreateApplicationTaskTest.java @@ -16,6 +16,7 @@ import static com.redhat.parodos.tasks.migrationtoolkit.TestConsts.APP_ID; import static com.redhat.parodos.tasks.migrationtoolkit.TestConsts.APP_NAME; +import static com.redhat.parodos.tasks.migrationtoolkit.TestConsts.REPO_BRANCH; import static com.redhat.parodos.tasks.migrationtoolkit.TestConsts.REPO_URL; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.any; @@ -76,9 +77,10 @@ public void createFails() { public void createCompletes() { ctx.put("applicationName", APP_NAME); ctx.put("repositoryURL", REPO_URL); + ctx.put("branch", REPO_URL); - when(mockClient.create(any())) - .thenReturn(new Result.Success<>(new App(APP_ID, APP_NAME, new Repository("git", REPO_URL)))); + when(mockClient.create(any())).thenReturn( + new Result.Success<>(new App(APP_ID, APP_NAME, new Repository("git", REPO_URL, REPO_BRANCH)))); WorkContextDelegate.write(ctx, WorkContextDelegate.ProcessType.WORKFLOW_EXECUTION, WorkContextDelegate.Resource.ID, UUID.randomUUID()); underTest.preExecute(ctx); @@ -87,11 +89,11 @@ public void createCompletes() { assertThat(execute.getError()).isNull(); assertThat(execute.getStatus()).isEqualTo(WorkStatus.COMPLETED); assertThat(execute.getWorkContext().get("application")) - .isEqualTo(new App(APP_ID, APP_NAME, new Repository("git", REPO_URL))); + .isEqualTo(new App(APP_ID, APP_NAME, new Repository("git", REPO_URL, REPO_BRANCH))); // 0 is wanted explicitly because it is an empty ID for the server request. (IDs // are generated by the server) - verify(mockClient, times(1)).create(new App(0, APP_NAME, new Repository("git", REPO_URL))); + verify(mockClient, times(1)).create(new App(0, APP_NAME, new Repository("git", REPO_URL, REPO_BRANCH))); } } diff --git a/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/migrationtoolkit/GetApplicationTaskTest.java b/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/migrationtoolkit/GetApplicationTaskTest.java index c1ca4ac42..06abacdaa 100644 --- a/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/migrationtoolkit/GetApplicationTaskTest.java +++ b/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/migrationtoolkit/GetApplicationTaskTest.java @@ -16,6 +16,7 @@ import static com.redhat.parodos.tasks.migrationtoolkit.TestConsts.APP_ID; import static com.redhat.parodos.tasks.migrationtoolkit.TestConsts.APP_NAME; +import static com.redhat.parodos.tasks.migrationtoolkit.TestConsts.REPO_BRANCH; import static com.redhat.parodos.tasks.migrationtoolkit.TestConsts.REPO_URL; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; @@ -74,8 +75,8 @@ public void failsGettingAppNotFound() { @Test @SneakyThrows public void getByName() { - when(mockClient.get(anyString())) - .thenReturn(new Result.Success<>(new App(APP_ID, APP_NAME, new Repository("git", REPO_URL)))); + when(mockClient.get(anyString())).thenReturn( + new Result.Success<>(new App(APP_ID, APP_NAME, new Repository("git", REPO_URL, REPO_BRANCH)))); ctx.put("applicationName", APP_NAME); WorkContextDelegate.write(ctx, WorkContextDelegate.ProcessType.WORKFLOW_EXECUTION, WorkContextDelegate.Resource.ID, UUID.randomUUID()); diff --git a/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/migrationtoolkit/TestConsts.java b/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/migrationtoolkit/TestConsts.java index 37d883fc3..ef71e069d 100644 --- a/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/migrationtoolkit/TestConsts.java +++ b/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/migrationtoolkit/TestConsts.java @@ -8,4 +8,6 @@ public interface TestConsts { String REPO_URL = "https://example.org/git/repo"; + String REPO_BRANCH = "v0.1.0"; + } diff --git a/workflow-examples/src/main/java/com/redhat/parodos/examples/prebuilt/migrationtoolkit/MigrationAssessmentWorkflow.java b/workflow-examples/src/main/java/com/redhat/parodos/examples/prebuilt/migrationtoolkit/MigrationAssessmentWorkflow.java index aa3371251..d94e4c044 100644 --- a/workflow-examples/src/main/java/com/redhat/parodos/examples/prebuilt/migrationtoolkit/MigrationAssessmentWorkflow.java +++ b/workflow-examples/src/main/java/com/redhat/parodos/examples/prebuilt/migrationtoolkit/MigrationAssessmentWorkflow.java @@ -88,7 +88,9 @@ WorkFlowOption defaultOption() { @Parameter(key = "repositoryURL", description = "The repository with the code to analyze", type = WorkParameterType.URL, optional = false), @Parameter(key = "applicationName", description = "The name of the application to analyze", - type = WorkParameterType.TEXT, optional = false) }) + type = WorkParameterType.TEXT, optional = false), + @Parameter(key = "branch", description = "The repository branch to analyze", type = WorkParameterType.TEXT, + optional = true) }) public WorkFlow AnalyzeApplicationAssessment(CreateApplicationTask createApplicationTask, GetApplicationTask getAppTask, SubmitAnalysisTask submitAnalysisTask) { return aNewSequentialFlow().named("AnalyzeApplicationAssessment").execute(createApplicationTask)