Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Add "branch" optional parameter to MTA analysis
Browse files Browse the repository at this point in the history
Signed-off-by: Roy Golan <rgolan@redhat.com>
  • Loading branch information
rgolangh committed Jun 13, 2023
1 parent a13b6c5 commit 4ed1942
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<App> result = mtaClient.create(new App(0, appName, new Repository("git", repo)));
Result<App> result = mtaClient.create(new App(0, appName, new Repository("git", repo, branch)));

if (result == null) {
// unexpected
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ public interface TestConsts {

String REPO_URL = "https://example.org/git/repo";

String REPO_BRANCH = "v0.1.0";

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4ed1942

Please sign in to comment.