-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathGitHubSCMSourceStatusChecksTrait.java
More file actions
199 lines (172 loc) · 5.92 KB
/
GitHubSCMSourceStatusChecksTrait.java
File metadata and controls
199 lines (172 loc) · 5.92 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package io.jenkins.plugins.checks.github.status;
import io.jenkins.plugins.checks.github.GitHubChecksGlobalConfig;
import org.apache.commons.lang3.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
import org.jenkinsci.plugins.github_branch_source.GitHubSCMSource;
import org.jenkinsci.plugins.github_branch_source.GitHubSCMSourceContext;
import hudson.Extension;
import hudson.util.FormValidation;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.trait.SCMSourceContext;
import jenkins.scm.api.trait.SCMSourceTrait;
import jenkins.scm.api.trait.SCMSourceTraitDescriptor;
import io.jenkins.plugins.checks.status.AbstractStatusChecksProperties;
/**
* Traits to control {@link AbstractStatusChecksProperties} for jobs using
* {@link GitHubSCMSource}.
*/
@SuppressWarnings("PMD.DataClass")
public class GitHubSCMSourceStatusChecksTrait extends SCMSourceTrait implements GitHubStatusChecksConfigurations {
private boolean skip = false;
private boolean skipNotifications = false;
private boolean unstableBuildNeutral = false;
private String name = "Jenkins";
private boolean suppressLogs = false;
private boolean skipProgressUpdates = DescriptorImpl.defaultSkipProgressUpdates;
public GitHubChecksGlobalConfig globalConfig = GitHubChecksGlobalConfig.get();
public boolean enforceSkipProgressUpdates = GitHubChecksGlobalConfig.get().isEnforceSkipProgressUpdates();
/**
* Constructor for stapler.
*/
@DataBoundConstructor
public GitHubSCMSourceStatusChecksTrait() {
super();
}
/**
* Defines the status checks name which is also used as identifier for GitHub checks.
*
* @return the name of status checks
*/
@Override
public String getName() {
return name;
}
/**
* Defines whether to skip publishing status checks.
*
* @return true to skip publishing checks
*/
@Override
public boolean isSkip() {
return skip;
}
@Override
public boolean isUnstableBuildNeutral() {
return unstableBuildNeutral;
}
/**
* Defines whether to skip notifications from {@link org.jenkinsci.plugins.github_branch_source.GitHubBuildStatusNotification}
* which utilizes the <a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#statuses">GitHub Status API</a>.
*
* @return true to skip notifications
*/
public boolean isSkipNotifications() {
return skipNotifications;
}
@Override
public boolean isEnforceSkipProgressUpdates() { return enforceSkipProgressUpdates; }
@Override
public boolean isSuppressLogs() {
return suppressLogs;
}
@Override
public boolean isSkipProgressUpdates() {
return skipProgressUpdates;
}
@DataBoundSetter
public void setSkipProgressUpdates(final boolean skipProgressUpdates) {
this.skipProgressUpdates = skipProgressUpdates;
}
/**
* Set the name of the status checks.
*
* @param name
* name of the checks
*/
@DataBoundSetter
public void setName(final String name) {
this.name = name;
}
/**
* Set if skip publishing status checks.
*
* @param skip
* true if skip
*/
@DataBoundSetter
public void setSkip(final boolean skip) {
this.skip = skip;
}
@DataBoundSetter
public void setUnstableBuildNeutral(final boolean unstableBuildNeutral) {
this.unstableBuildNeutral = unstableBuildNeutral;
}
@DataBoundSetter
public void setSkipNotifications(final boolean skipNotifications) {
this.skipNotifications = skipNotifications;
}
@DataBoundSetter
public void setSuppressLogs(final boolean suppressLogs) {
this.suppressLogs = suppressLogs;
}
@Override
protected void decorateContext(final SCMSourceContext<?, ?> context) {
if (isSkipNotifications() && context instanceof GitHubSCMSourceContext) {
((GitHubSCMSourceContext)context).withNotificationsDisabled(true);
}
}
/**
* Descriptor implementation for {@link GitHubSCMSourceStatusChecksTrait}.
*/
@Extension
public static class DescriptorImpl extends SCMSourceTraitDescriptor {
public static final boolean defaultSkipProgressUpdates;
public static final boolean enforceSkipProgressUpdates;
static {
enforceSkipProgressUpdates = GitHubChecksGlobalConfig.get().isEnforceSkipProgressUpdates();
defaultSkipProgressUpdates = true;
}
/**
* Returns the display name.
*
* @return "Status Checks Properties"
*/
@Override
public String getDisplayName() {
return "Status Checks Properties";
}
/**
* The {@link GitHubSCMSourceStatusChecksTrait} is only applicable to {@link GitHubSCMSourceContext}.
*
* @return {@link GitHubSCMSourceContext}.class
*/
@Override
public Class<? extends SCMSourceContext> getContextClass() {
return GitHubSCMSourceContext.class;
}
/**
* The {@link GitHubSCMSourceStatusChecksTrait} is only applicable to {@link GitHubSCMSource}.
*
* @return {@link GitHubSCMSource}.class
*/
@Override
public Class<? extends SCMSource> getSourceClass() {
return GitHubSCMSource.class;
}
/**
* Checks if the name of status checks is valid.
*
* @param name
* name of status checks
* @return ok if the name is not empty
*/
public FormValidation doCheckName(@QueryParameter final String name) {
if (StringUtils.isBlank(name)) {
return FormValidation.error("Name should not be empty!");
}
return FormValidation.ok();
}
}
}