Skip to content
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

Introduce new dedicated SCMM branch discovery trait #52

Merged
merged 2 commits into from
May 5, 2023
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 @@ -10,6 +10,14 @@

import javax.annotation.Nonnull;

/**
* @deprecated This class has been replaced with the {@link ScmManagerBranchDiscoveryTrait}. The
* name of this class has not been unique and this led to issues in the automated generation of
* build jobs.
*
* @see ScmManagerBranchDiscoveryTrait
*/
@Deprecated
public class BranchDiscoveryTrait extends SCMSourceTrait {

@DataBoundConstructor
Expand All @@ -34,7 +42,7 @@ public static class DescriptorImpl extends ScmManagerSourceTraitDescriptor {
@Nonnull
@Override
public String getDisplayName() {
return "Branch Discovery";
return "Deprecated SCM-Manager Branch Discovery";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static FormValidation validateCredentialsId(ScmManagerApiFactory apiFactory, SCM
}

static FormValidation checkServerUrl(ScmManagerApiFactory apiFactory, String value) throws InterruptedException, ExecutionException {
String trimmedValue = value.trim();
String trimmedValue = value == null? null: value.trim();
if (Strings.isNullOrEmpty(trimmedValue)) {
return FormValidation.error("server url is required");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.cloudogu.scmmanager.scm;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import jenkins.scm.api.SCMHeadCategory;
import jenkins.scm.api.trait.SCMSourceContext;
import jenkins.scm.api.trait.SCMSourceTrait;
import jenkins.scm.impl.trait.Discovery;
import org.kohsuke.stapler.DataBoundConstructor;

import javax.annotation.Nonnull;

public class ScmManagerBranchDiscoveryTrait extends SCMSourceTrait {

@DataBoundConstructor
public ScmManagerBranchDiscoveryTrait() {
}

@Override
protected void decorateContext(SCMSourceContext<?, ?> context) {
ScmManagerSourceContext scmContext = (ScmManagerSourceContext) context;
scmContext.wantBranches(true);
}

@Override
protected boolean includeCategory(@NonNull SCMHeadCategory category) {
return category.isUncategorized();
}

@Extension
@Discovery
public static class DescriptorImpl extends ScmManagerSourceTraitDescriptor {

@Nonnull
@Override
public String getDisplayName() {
return "SCM-Manager Branch Discovery";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private List<SCMSourceTraitDescriptor> findAllAvailableTraits() {
@NonNull
public List<SCMSourceTrait> getTraitsDefaults() {
return Arrays.asList(
new BranchDiscoveryTrait(),
new ScmManagerBranchDiscoveryTrait(),
new PullRequestDiscoveryTrait(false)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ private static Collection<Identification> readIdentifications(JSONObject form) {
}

boolean matches(String serverUrl) {
if (serverUrl != null) {
return serverUrl.startsWith(this.serverUrl) || identifications.stream().anyMatch(i -> i.matches(serverUrl));
}
return false;
return serverUrl != null && (serverUrl.startsWith(this.serverUrl) || identifications.stream().anyMatch(i -> i.matches(serverUrl)));
}

String getServerUrl() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.cloudogu.scmmanager.scm.jobdsl;

import com.cloudogu.scmmanager.scm.BranchDiscoveryTrait;
import com.cloudogu.scmmanager.scm.PullRequestDiscoveryTrait;
import com.cloudogu.scmmanager.scm.ScmManagerBranchDiscoveryTrait;
import com.cloudogu.scmmanager.scm.TagDiscoveryTrait;
import jenkins.scm.api.trait.SCMSourceTrait;

Expand Down Expand Up @@ -29,7 +29,7 @@ public void discoverTags(boolean discoverTags) {
public List<SCMSourceTrait> getTraits() {
List<SCMSourceTrait> traits = new ArrayList<>();
if (discoverBranches) {
traits.add(new BranchDiscoveryTrait());
traits.add(new ScmManagerBranchDiscoveryTrait());
}
if (discoverPullRequest) {
traits.add(new PullRequestDiscoveryTrait());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.cloudogu.scmmanager.scm.jobdsl;

import com.cloudogu.scmmanager.scm.BranchDiscoveryTrait;
import com.cloudogu.scmmanager.scm.PullRequestDiscoveryTrait;
import com.cloudogu.scmmanager.scm.ScmManagerBranchDiscoveryTrait;
import com.cloudogu.scmmanager.scm.ScmManagerSvnNavigatorTrait;
import com.cloudogu.scmmanager.scm.Subversion;
import com.cloudogu.scmmanager.scm.TagDiscoveryTrait;
Expand Down Expand Up @@ -63,7 +63,7 @@ public void discoverSvn(@DslContext(SubversionContext.class) Runnable closure) {
public List<SCMTrait<? extends SCMTrait<?>>> getTraits() {
List<SCMTrait<? extends SCMTrait<?>>> traits = new ArrayList<>();
if (discoverBranches) {
traits.add(new BranchDiscoveryTrait());
traits.add(new ScmManagerBranchDiscoveryTrait());
}
if (discoverPullRequest) {
traits.add(new PullRequestDiscoveryTrait());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.cloudogu.scmmanager.scm.jobdsl;

import com.cloudogu.scmmanager.scm.BranchDiscoveryTrait;
import com.cloudogu.scmmanager.scm.PullRequestDiscoveryTrait;
import com.cloudogu.scmmanager.scm.ScmManagerBranchDiscoveryTrait;
import com.cloudogu.scmmanager.scm.ScmManagerSource;
import com.cloudogu.scmmanager.scm.ScmManagerSvnSource;
import com.cloudogu.scmmanager.scm.Subversion;
Expand All @@ -23,7 +23,9 @@

import static com.cloudogu.scmmanager.scm.jobdsl.Asserts.assertContainsOnlyInstancesOf;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class BranchSourcesExtensionTest {
Expand All @@ -50,7 +52,7 @@ public void shouldCreateSourceWithoutRepositoryFetch() throws ExecutionException
assertThat(source.getRepository()).isEqualTo("hitchhiker/hog/git");
assertThat(source.getId()).isEqualTo("42");
assertContainsOnlyInstancesOf(source.getTraits(),
BranchDiscoveryTrait.class, PullRequestDiscoveryTrait.class, TagDiscoveryTrait.class
ScmManagerBranchDiscoveryTrait.class, PullRequestDiscoveryTrait.class, TagDiscoveryTrait.class
);
verifyNoMoreInteractions(apiFactory);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.cloudogu.scmmanager.scm.jobdsl;

import com.cloudogu.scmmanager.scm.BranchDiscoveryTrait;
import com.cloudogu.scmmanager.scm.PullRequestDiscoveryTrait;
import com.cloudogu.scmmanager.scm.ScmManagerBranchDiscoveryTrait;
import com.cloudogu.scmmanager.scm.ScmManagerNavigator;
import com.cloudogu.scmmanager.scm.ScmManagerSvnNavigatorTrait;
import com.cloudogu.scmmanager.scm.TagDiscoveryTrait;
Expand Down Expand Up @@ -33,7 +33,7 @@ public void shouldCreateNavigator() {
assertThat(scmNavigator.getCredentialsId()).isEqualTo("secret");
assertThat(scmNavigator.getNamespace()).isEqualTo("spaceships");
assertContainsOnlyInstancesOf(scmNavigator.getTraits(),
BranchDiscoveryTrait.class, PullRequestDiscoveryTrait.class
ScmManagerBranchDiscoveryTrait.class, PullRequestDiscoveryTrait.class
);
}

Expand Down