Skip to content

Choosen Tuleap project is not saved after Tuleap job configuration saving #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.interceptor.RequirePOST;

import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.io.IOException;
import java.util.*;
Expand All @@ -55,29 +54,29 @@ public class TuleapSCMNavigator extends SCMNavigator {

private static final String TULEAP_FORK_PARTIAL_PATH = "/u/";

private String projectId;
private String tuleapProjectId;
private List<SCMTrait<? extends SCMTrait<?>>> traits;
private String credentialsId;
private String apiUri, gitBaseUri;
private Map<String, TuleapGitRepository> repositories = new HashMap<>();
private TuleapProject project;

@DataBoundConstructor
public TuleapSCMNavigator(String projectId) {
this.projectId = projectId;
public TuleapSCMNavigator(String tuleapProjectId) {
this.tuleapProjectId = tuleapProjectId;
}

@NonNull
@Override
protected String id() {
return TuleapConfiguration.get().getDomainUrl() + "::" + projectId;
return TuleapConfiguration.get().getDomainUrl() + "::" + tuleapProjectId;
}

@Override
public void visitSources(SCMSourceObserver observer) throws IOException, InterruptedException {
TaskListener listener = observer.getListener();

listener.getLogger().printf("Visit Sources of %s...%n", getprojectId());
listener.getLogger().printf("Visit Sources of %s...%n", getTuleapProjectId());
TuleapAccessToken credentials = TuleapConnector.lookupScanCredentials((Item) observer.getContext(),
getApiUri(), credentialsId);

Expand All @@ -86,20 +85,20 @@ public void visitSources(SCMSourceObserver observer) throws IOException, Interru
WitnessImpl witness = new WitnessImpl(listener, this);
Optional<TuleapProject> project = TuleapClientCommandConfigurer.<Optional<TuleapProject>>newInstance(getApiUri())
.withCredentials(credentials)
.withCommand(new TuleapClientRawCmd.ProjectById(projectId))
.withCommand(new TuleapClientRawCmd.ProjectById(tuleapProjectId))
.configure()
.call();
if (project.isPresent()) {
this.project = project.get();
} else {
//Should never happen though
listener.getLogger().format("No project match projectId " + projectId + "... it's weird%n");
listener.getLogger().format("No project match projectId " + tuleapProjectId + "... it's weird%n");
return;
}
Stream<TuleapGitRepository> repos = TuleapClientCommandConfigurer.<Stream<TuleapGitRepository>>newInstance
(getApiUri())
.withCredentials(credentials)
.withCommand(new TuleapClientRawCmd.AllRepositoriesByProject(projectId))
.withCommand(new TuleapClientRawCmd.AllRepositoriesByProject(tuleapProjectId))
.configure()
.call();

Expand All @@ -123,14 +122,14 @@ public void visitSources(SCMSourceObserver observer) throws IOException, Interru
@Override
protected List<Action> retrieveActions(@NonNull SCMNavigatorOwner owner, @CheckForNull SCMNavigatorEvent event,
@NonNull TaskListener listener) throws IOException, InterruptedException {
listener.getLogger().printf("Looking up details of %s...%n", getprojectId());
listener.getLogger().printf("Looking up details of %s...%n", getTuleapProjectId());
List<Action> actions = new ArrayList<>();

final TuleapAccessToken credentials = lookupScanCredentials((Item) owner, getApiUri(), credentialsId);
Optional<TuleapProject> project = TuleapClientCommandConfigurer
.<Optional<TuleapProject>>newInstance(getApiUri())
.withCredentials(credentials)
.withCommand(new TuleapClientRawCmd.ProjectById(projectId))
.withCommand(new TuleapClientRawCmd.ProjectById(tuleapProjectId))
.configure()
.call();
if (project.isPresent()) {
Expand Down Expand Up @@ -213,15 +212,15 @@ public String getGitBaseUri() {
/**
* Gets the Id of the project who's repositories will be navigated.
*
* @return the Idof the project who's repositories will be navigated.
* @return the Id of the project who's repositories will be navigated.
*/
public String getprojectId() {
return projectId;
public String getTuleapProjectId() {
return this.tuleapProjectId;
}

@DataBoundSetter
public void setProjectId(final String projectId) {
this.projectId = projectId;
public void setTuleapProjectId(final String tuleapProjectId) {
this.tuleapProjectId = tuleapProjectId;
}

public Map<String, TuleapGitRepository> getRepositories() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import hudson.security.ACLContext;
import jenkins.branch.MultiBranchProject;
import jenkins.branch.OrganizationFolder;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.tuleap_git_branch_source.TuleapSCMNavigator;
import org.jenkinsci.plugins.tuleap_git_branch_source.webhook.TuleapWebHookCause;
import org.jenkinsci.plugins.tuleap_git_branch_source.webhook.TuleapWebhookRetriggerRepositoryScanCause;
Expand Down Expand Up @@ -42,7 +41,7 @@ public void triggerConcernedJob(WebHookRepresentation representation) throws Rep
.filter(organizationFolder -> organizationFolder.getSCMNavigators().get(0).getClass().equals(TuleapSCMNavigator.class))
.filter(organizationFolder -> {
TuleapSCMNavigator tuleapSCMNavigator = (TuleapSCMNavigator) organizationFolder.getSCMNavigators().get(0);
String projectId = tuleapSCMNavigator.getprojectId();
String projectId = tuleapSCMNavigator.getTuleapProjectId();
return representation.getTuleapProjectId().equals(projectId);
})
.findFirst();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jenkinsci.plugins.tuleap_git_branch_source;

import jenkins.scm.api.SCMNavigator;
import jenkins.scm.api.trait.SCMTrait;
import jenkins.scm.impl.trait.RegexSCMSourceFilterTrait;
import jenkins.scm.impl.trait.WildcardSCMSourceFilterTrait;
Expand All @@ -21,7 +20,7 @@ public class TuleapSCMNavigatorConfigurationLoadingTest extends TuleapBranchSour
public void new_project_by_default(){

assertThat(instance.id(), is("https://www.tuleap.example.test::3280"));
assertThat(instance.getprojectId(), is("3280"));
assertThat(instance.getTuleapProjectId(), is("3280"));
assertThat(instance.getCredentialsId(), is("fe09fd0e-7287-44a1-b0b5-746accd227c1"));
assertThat(instance.getApiUri(), is("https://www.tuleap.example.test/api"));
assertThat(instance.getGitBaseUri(), is("https://www.tuleap.example.test/plugins/git/"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void testThrowsTuleapProjectNotFoundExceptionWhenThereIsNoTuleapOrganizat
TuleapSCMNavigator tuleapNavigator = mock(TuleapSCMNavigator.class);
tuleapScmNavigatorList.add(tuleapNavigator);
when(tuleapFolderWithAUnwantedName.getSCMNavigators()).thenReturn(tuleapScmNavigatorList);
when(tuleapNavigator.getprojectId()).thenReturn("204");
when(tuleapNavigator.getTuleapProjectId()).thenReturn("204");

WebHookRepresentation representation = mock(WebHookRepresentation.class);
when(representation.getTuleapProjectId()).thenReturn("8");
Expand All @@ -67,7 +67,7 @@ public void testThrowRepositoryNotFoundExceptionWhenTheRepositoryDoesNotExist()
TuleapSCMNavigator tuleapNavigator = mock(TuleapSCMNavigator.class);
tuleapScmNavigatorList.add(tuleapNavigator);
when(tuleapFolder.getSCMNavigators()).thenReturn(tuleapScmNavigatorList);
when(tuleapNavigator.getprojectId()).thenReturn("204");
when(tuleapNavigator.getTuleapProjectId()).thenReturn("204");

Stream<OrganizationFolder> stream = Stream.<OrganizationFolder>builder().add(tuleapFolder).build();
when(this.organizationFolderRetriever.retrieveTuleapOrganizationFolders()).thenReturn(stream);
Expand Down Expand Up @@ -99,7 +99,7 @@ public void testThrowBranchNotFoundExceptionWhenTheBranchDoesNotExistEvenAfterAR
TuleapSCMNavigator tuleapNavigator = mock(TuleapSCMNavigator.class);
tuleapScmNavigatorList.add(tuleapNavigator);
when(tuleapFolder.getSCMNavigators()).thenReturn(tuleapScmNavigatorList);
when(tuleapNavigator.getprojectId()).thenReturn("204");
when(tuleapNavigator.getTuleapProjectId()).thenReturn("204");


Stream<OrganizationFolder> stream = Stream.<OrganizationFolder>builder().add(tuleapFolder).build();
Expand Down Expand Up @@ -129,7 +129,7 @@ public void testThrowRepositoryScanFailedExceptionWhenTheRescanOfTheRepositoryFa
TuleapSCMNavigator tuleapNavigator = mock(TuleapSCMNavigator.class);
tuleapScmNavigatorList.add(tuleapNavigator);
when(tuleapFolder.getSCMNavigators()).thenReturn(tuleapScmNavigatorList);
when(tuleapNavigator.getprojectId()).thenReturn("204");
when(tuleapNavigator.getTuleapProjectId()).thenReturn("204");


Stream<OrganizationFolder> stream = Stream.<OrganizationFolder>builder().add(tuleapFolder).build();
Expand Down Expand Up @@ -157,7 +157,7 @@ public void testTheBuildIsScheduledWhenTheBranchAlreadyExist() throws TuleapProj
TuleapSCMNavigator tuleapNavigator = mock(TuleapSCMNavigator.class);
tuleapScmNavigatorList.add(tuleapNavigator);
when(tuleapFolder.getSCMNavigators()).thenReturn(tuleapScmNavigatorList);
when(tuleapNavigator.getprojectId()).thenReturn("204");
when(tuleapNavigator.getTuleapProjectId()).thenReturn("204");

Stream<OrganizationFolder> stream = Stream.<OrganizationFolder>builder().add(tuleapFolder).build();
when(this.organizationFolderRetriever.retrieveTuleapOrganizationFolders()).thenReturn(stream);
Expand Down Expand Up @@ -187,7 +187,7 @@ public void testTheBuildIsScheduledWhenTheBranchIsDiscoverAfterRepositoryRescan(
TuleapSCMNavigator tuleapNavigator = mock(TuleapSCMNavigator.class);
tuleapScmNavigatorList.add(tuleapNavigator);
when(tuleapFolder.getSCMNavigators()).thenReturn(tuleapScmNavigatorList);
when(tuleapNavigator.getprojectId()).thenReturn("204");
when(tuleapNavigator.getTuleapProjectId()).thenReturn("204");

Stream<OrganizationFolder> stream = Stream.<OrganizationFolder>builder().add(tuleapFolder).build();
when(this.organizationFolderRetriever.retrieveTuleapOrganizationFolders()).thenReturn(stream);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<org.jenkinsci.plugins.tuleap__git__branch__source.TuleapSCMNavigator>
<projectId>3280</projectId>
<tuleapProjectId>3280</tuleapProjectId>
<traits>
<jenkins.scm.impl.trait.WildcardSCMSourceFilterTrait>
<includes>*</includes>
Expand Down