This repository was archived by the owner on Dec 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathGitLabSCMBranchBuildStrategy.java
More file actions
101 lines (79 loc) · 3.58 KB
/
GitLabSCMBranchBuildStrategy.java
File metadata and controls
101 lines (79 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package argelbargel.jenkins.plugins.gitlab_branch_source;
import argelbargel.jenkins.plugins.gitlab_branch_source.heads.GitLabSCMBranchHead;
import argelbargel.jenkins.plugins.gitlab_branch_source.heads.GitLabSCMMergeRequestHead;
import hudson.Extension;
import jenkins.branch.BranchBuildStrategy;
import jenkins.branch.BranchBuildStrategyDescriptor;
import jenkins.branch.BranchSource;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.SCMSourceDescriptor;
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.mixin.TagSCMHead;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
public class GitLabSCMBranchBuildStrategy extends BranchBuildStrategy {
static final GitLabSCMBranchBuildStrategy INSTANCE = new GitLabSCMBranchBuildStrategy();
@Override
public boolean isAutomaticBuild(SCMSource source, SCMHead head) {
if (source instanceof GitLabSCMSource) {
return isAutomaticBuild((GitLabSCMSource) source, head);
}
return !TagSCMHead.class.isInstance(head);
}
@SuppressWarnings("SimplifiableIfStatement")
private boolean isAutomaticBuild(GitLabSCMSource source, SCMHead head) {
if (head instanceof TagSCMHead) {
return source.getSourceSettings().getTagMonitorStrategy().getBuild();
}
if (head instanceof GitLabSCMBranchHead) {
return !((GitLabSCMBranchHead) head).hasMergeRequest() || source.getSourceSettings().getBranchMonitorStrategy().getBuildBranchesWithMergeRequests();
}
if (head instanceof GitLabSCMMergeRequestHead) {
return isAutomaticBuild(source, (GitLabSCMMergeRequestHead) head);
}
return true;
}
@Override
public boolean isAutomaticBuild(SCMSource source, SCMHead head, SCMRevision var3, SCMRevision var4)
{
if (source instanceof GitLabSCMSource) {
return isAutomaticBuild((GitLabSCMSource) source, head);
}
return !TagSCMHead.class.isInstance(head);
}
private boolean isAutomaticBuild(GitLabSCMSource source, GitLabSCMMergeRequestHead head) {
if (!head.isMerged()) {
return true;
}
if (head.isMergeable()) {
return true;
}
boolean fromOrigin = source.getProjectId() == head.getProjectId();
return (fromOrigin && !source.getSourceSettings().getOriginMonitorStrategy().getBuildOnlyMergeableMerged()) || (!fromOrigin && !source.getSourceSettings().getForksMonitorStrategy().getBuildOnlyMergeableMerged());
}
boolean isApplicable(BranchSource branchSource) {
return branchSource.getSource() instanceof GitLabSCMSource;
}
private GitLabSCMBranchBuildStrategy() { /* singleton */ }
@Extension
public static class DescriptorImpl extends BranchBuildStrategyDescriptor {
@Nonnull
@Override
public String getDisplayName() {
return Messages.GitLabSCMBranchBuildStrategy_DisplayName();
}
@Override
public boolean isApplicable(@Nonnull SCMSourceDescriptor sourceDescriptor) {
// TODO: HACK ALERT! the source configuration will not be displayed correctly (it hangs)
// when the strategy is listed in the sources configuration. thus we have to disable it here
return false;
}
@Override
public BranchBuildStrategy newInstance(@CheckForNull StaplerRequest req, @Nonnull JSONObject formData) throws FormException {
return INSTANCE;
}
}
}