Skip to content
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
@@ -0,0 +1,47 @@
package io.jenkins.plugins.gitlabbranchsource;

import hudson.Extension;
import javax.annotation.Nonnull;
import jenkins.scm.api.trait.SCMNavigatorContext;
import jenkins.scm.api.trait.SCMNavigatorTrait;
import jenkins.scm.api.trait.SCMNavigatorTraitDescriptor;
import jenkins.scm.impl.trait.Selection;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* A {@link Selection} trait that will restrict the discovery of repositories that have been
* archived.
*/
public class ExcludeArchivedRepositoriesTrait extends SCMNavigatorTrait {

/** Constructor for stapler. */
@DataBoundConstructor
public ExcludeArchivedRepositoriesTrait() {}

/** {@inheritDoc} */
@Override
protected void decorateContext(SCMNavigatorContext<?, ?> context) {
super.decorateContext(context);
GitLabSCMNavigatorContext ctx = (GitLabSCMNavigatorContext) context;
ctx.setExcludeArchivedRepositories(true);
}

/** Exclude archived repositories filter */
@Symbol("gitLabExcludeArchivedRepositories")
@Extension
@Selection
public static class DescriptorImpl extends SCMNavigatorTraitDescriptor {

@Override
public Class<? extends SCMNavigatorContext> getContextClass() {
return GitLabSCMNavigatorContext.class;
}

@Nonnull
@Override
public String getDisplayName() {
return Messages.ExcludeArchivedRepositoriesTrait_displayName();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ protected String id() {
@Override
public void visitSources(@NonNull final SCMSourceObserver observer)
throws IOException, InterruptedException {
try (GitLabSCMNavigatorRequest request = new GitLabSCMNavigatorContext()
.withTraits(traits)
.newRequest(this, observer)) {
GitLabSCMNavigatorContext context = new GitLabSCMNavigatorContext()
.withTraits(traits);
try (GitLabSCMNavigatorRequest request = context.newRequest(this, observer)) {
GitLabApi gitLabApi = apiBuilder(serverName);
getGitlabOwner(gitLabApi);
List<Project> projects;
Expand Down Expand Up @@ -266,6 +266,12 @@ public void visitSources(@NonNull final SCMSourceObserver observer)
HyperlinkNote.encodeTo(p.getWebUrl(), p.getName()));
continue;
}
if (p.getArchived() && context.isExcludeArchivedRepositories()) {
observer.getListener().getLogger()
.format("%nIgnoring archived project %s%n",
HyperlinkNote.encodeTo(p.getWebUrl(), p.getName()));
continue;
}
observer.getListener().getLogger().format("%nChecking project %s%n",
HyperlinkNote.encodeTo(p.getWebUrl(), projectName));
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public class GitLabSCMNavigatorContext extends

private int projectNamingStrategy = 1;

/** If true, archived repositories will be ignored. */
private boolean excludeArchivedRepositories;

@NonNull
@Override
public GitLabSCMNavigatorRequest newRequest(@NonNull SCMNavigator navigator,
Expand Down Expand Up @@ -44,4 +47,14 @@ public GitLabSCMNavigatorContext withProjectNamingStrategy(int strategyId) {
this.projectNamingStrategy = strategyId;
return this;
}

/** @return True if archived repositories should be ignored, false if they should be included. */
public boolean isExcludeArchivedRepositories() {
return excludeArchivedRepositories;
}

/** @param excludeArchivedRepositories Set true to exclude archived repositories */
public void setExcludeArchivedRepositories(boolean excludeArchivedRepositories) {
this.excludeArchivedRepositories = excludeArchivedRepositories;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:c="/lib/credentials"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:f2="/org/jenkinsci/plugins/gitlab_branch_source/form">
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
Exclude GitLab repositories that have been archived. If set, no jobs will be created for archived repositories.
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ BranchDiscoveryTrait.authorityDisplayName=Trust origin branches
BranchDiscoveryTrait.displayName=Discover branches
BranchDiscoveryTrait.excludeMRs=Only branches that are not also filed as MRs
BranchDiscoveryTrait.onlyMRs=Only branches that are also filed as MRs
ExcludeArchivedRepositoriesTrait.displayName=Exclude archived repositories
BuildStatusNameCustomPartTrait.displayName=Customize GitLab build status name
ForkMergeRequestDiscoveryTrait.displayName=Discover merge requests from forks
ForkMergeRequestDiscoveryTrait.headAndMerge=Both the current merge request revision and the merge request merged with \
Expand Down