-
Notifications
You must be signed in to change notification settings - Fork 355
/
Copy pathBitbucketSCMSourceContext.java
389 lines (357 loc) · 13.6 KB
/
BitbucketSCMSourceContext.java
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
/*
* The MIT License
*
* Copyright (c) 2017, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.cloudbees.jenkins.plugins.bitbucket;
import com.cloudbees.jenkins.plugins.bitbucket.hooks.WebhookConfiguration;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.model.TaskListener;
import java.util.EnumSet;
import java.util.Set;
import jenkins.scm.api.SCMHeadObserver;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.SCMSourceCriteria;
import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy;
import jenkins.scm.api.trait.SCMSourceContext;
/**
* The {@link SCMSourceContext} for bitbucket.
*
* @since 2.2.0
*/
public class BitbucketSCMSourceContext extends SCMSourceContext<BitbucketSCMSourceContext, BitbucketSCMSourceRequest> {
/**
* {@code true} if the {@link BitbucketSCMSourceRequest} will need information about branches.
*/
private boolean wantBranches;
/**
* {@code true} if the {@link BitbucketSCMSourceRequest} will need information about tags.
*/
private boolean wantTags;
/**
* {@code true} if the {@link BitbucketSCMSourceRequest} will need information about origin pull requests.
*/
private boolean wantOriginPRs;
/**
* {@code true} if the {@link BitbucketSCMSourceRequest} will need information about fork pull requests.
*/
private boolean wantForkPRs;
/**
* {@code true} if all pull requests from public repositories should be ignored.
*/
private boolean skipPublicPRs;
/**
* Set of {@link ChangeRequestCheckoutStrategy} to create for each origin pull request.
*/
@NonNull
private final Set<ChangeRequestCheckoutStrategy> originPRStrategies = EnumSet.noneOf(ChangeRequestCheckoutStrategy.class);
/**
* Set of {@link ChangeRequestCheckoutStrategy} to create for each fork pull request.
*/
@NonNull
private final Set<ChangeRequestCheckoutStrategy> forkPRStrategies = EnumSet.noneOf(ChangeRequestCheckoutStrategy.class);
/**
* The {@link WebhookRegistration} to use in this context.
*/
@NonNull
private WebhookRegistration webhookRegistration = WebhookRegistration.SYSTEM;
/**
* The {@link WebhookConfiguration} to use in this context.
*/
@NonNull
private WebhookConfiguration webhookConfiguration = new WebhookConfiguration();
/**
* {@code true} if notifications should be disabled in this context.
*/
private boolean notificationsDisabled;
/**
* {@code true} if unstable builds should be considered as successful by Bitbucket.
*/
private boolean sendSuccessNotificationForUnstableBuild;
/**
* {@code true} if need to include Jenkins URL to the build status name and key.
*/
private boolean buildStatusIncludeJenkinsURL;
/**
* Constructor.
*
* @param criteria (optional) criteria.
* @param observer the {@link SCMHeadObserver}.
*/
public BitbucketSCMSourceContext(@CheckForNull SCMSourceCriteria criteria,
@NonNull SCMHeadObserver observer) {
super(criteria, observer);
}
/**
* Returns {@code true} if the {@link BitbucketSCMSourceRequest} will need information about branches.
*
* @return {@code true} if the {@link BitbucketSCMSourceRequest} will need information about branches.
*/
public final boolean wantBranches() {
return wantBranches;
}
/**
* Returns {@code true} if the {@link BitbucketSCMSourceRequest} will need information about tags.
*
* @return {@code true} if the {@link BitbucketSCMSourceRequest} will need information about tags.
*/
public final boolean wantTags() {
return wantTags;
}
/**
* Returns {@code true} if the {@link BitbucketSCMSourceRequest} will need information about pull requests.
*
* @return {@code true} if the {@link BitbucketSCMSourceRequest} will need information about pull requests.
*/
public final boolean wantPRs() {
return wantOriginPRs || wantForkPRs;
}
/**
* Returns {@code true} if the {@link BitbucketSCMSourceRequest} will need information about origin pull requests.
*
* @return {@code true} if the {@link BitbucketSCMSourceRequest} will need information about origin pull requests.
*/
public final boolean wantOriginPRs() {
return wantOriginPRs;
}
/**
* Returns {@code true} if the {@link BitbucketSCMSourceRequest} will need information about fork pull requests.
*
* @return {@code true} if the {@link BitbucketSCMSourceRequest} will need information about fork pull requests.
*/
public final boolean wantForkPRs() {
return wantForkPRs;
}
/**
* Returns {@code true} if pull requests from public repositories should be skipped.
*
* @return {@code true} if pull requests from public repositories should be skipped.
*/
public final boolean skipPublicPRs() {
return skipPublicPRs;
}
/**
* Returns the set of {@link ChangeRequestCheckoutStrategy} to create for each origin pull request.
*
* @return the set of {@link ChangeRequestCheckoutStrategy} to create for each origin pull request.
*/
@NonNull
public final Set<ChangeRequestCheckoutStrategy> originPRStrategies() {
return originPRStrategies;
}
/**
* Returns the set of {@link ChangeRequestCheckoutStrategy} to create for each fork pull request.
*
* @return the set of {@link ChangeRequestCheckoutStrategy} to create for each fork pull request.
*/
@NonNull
public final Set<ChangeRequestCheckoutStrategy> forkPRStrategies() {
return forkPRStrategies;
}
/**
* Returns the {@link WebhookRegistration} mode.
*
* @return the {@link WebhookRegistration} mode.
*/
@NonNull
public final WebhookRegistration webhookRegistration() {
return webhookRegistration;
}
/**
* Returns the {@link WebhookConfiguration} configuration.
*
* @return the {@link WebhookConfiguration} configuration.
*/
@NonNull
public final WebhookConfiguration webhookConfiguration() {
return webhookConfiguration;
}
/**
* Returns {@code true} if notifications should be disabled.
*
* @return {@code true} if notifications should be disabled.
*/
public final boolean notificationsDisabled() {
return notificationsDisabled;
}
/**
* Returns {@code true} if unstable builds should be passed as successful to Bitbucket.
*
* @return {@code true} if unstable builds should be passed as successful to Bitbucket.
*/
public final boolean sendSuccessNotificationForUnstableBuild() {
return sendSuccessNotificationForUnstableBuild;
}
/**
* Returns {@code true} if should include Jenkins URL to a build status name and key.
*
* @return {@code false} if should NOT include Jenkins URL to a build status name and key.
*/
public final boolean buildStatusIncludeJenkinsURL() {
return buildStatusIncludeJenkinsURL;
}
/**
* Adds a requirement for branch details to any {@link BitbucketSCMSourceRequest} for this context.
*
* @param include {@code true} to add the requirement or {@code false} to leave the requirement as is (makes
* simpler with method chaining)
* @return {@code this} for method chaining.
*/
@NonNull
public final BitbucketSCMSourceContext wantBranches(boolean include) {
wantBranches = wantBranches || include;
return this;
}
/**
* Adds a requirement for tag details to any {@link BitbucketSCMSourceRequest} for this context.
*
* @param include {@code true} to add the requirement or {@code false} to leave the requirement as is (makes
* simpler with method chaining)
* @return {@code this} for method chaining.
*/
@NonNull
public final BitbucketSCMSourceContext wantTags(boolean include) {
wantTags = wantTags || include;
return this;
}
/**
* Adds a requirement for origin pull request details to any {@link BitbucketSCMSourceRequest} for this context.
*
* @param include {@code true} to add the requirement or {@code false} to leave the requirement as is (makes
* simpler with method chaining)
* @return {@code this} for method chaining.
*/
@NonNull
public final BitbucketSCMSourceContext wantOriginPRs(boolean include) {
wantOriginPRs = wantOriginPRs || include;
return this;
}
/**
* Adds a requirement for fork pull request details to any {@link BitbucketSCMSourceRequest} for this context.
*
* @param include {@code true} to add the requirement or {@code false} to leave the requirement as is (makes
* simpler with method chaining)
* @return {@code this} for method chaining.
*/
@NonNull
public final BitbucketSCMSourceContext wantForkPRs(boolean include) {
wantForkPRs = wantForkPRs || include;
return this;
}
/**
* Controls the skipping of pull requests from public repositories.
*
* @param skipPublicPRs {@code true} if pull requests from public repositories should be skipped.
* @return {@code this} for method chaining.
*/
public final BitbucketSCMSourceContext skipPublicPRs(boolean skipPublicPRs) {
this.skipPublicPRs = skipPublicPRs;
return this;
}
/**
* Defines the {@link ChangeRequestCheckoutStrategy} instances to create for each origin pull request.
*
* @param strategies the strategies.
* @return {@code this} for method chaining.
*/
@NonNull
public final BitbucketSCMSourceContext withOriginPRStrategies(
@NonNull Set<ChangeRequestCheckoutStrategy> strategies) {
originPRStrategies.addAll(strategies);
return this;
}
/**
* Defines the {@link ChangeRequestCheckoutStrategy} instances to create for each fork pull request.
*
* @param strategies the strategies.
* @return {@code this} for method chaining.
*/
@NonNull
public final BitbucketSCMSourceContext withForkPRStrategies(
@NonNull Set<ChangeRequestCheckoutStrategy> strategies) {
forkPRStrategies.addAll(strategies);
return this;
}
/**
* Defines the {@link WebhookRegistration} mode to use in this context.
*
* @param configuration the webhook configuration.
* @return {@code this} for method chaining.
*/
@NonNull
public final BitbucketSCMSourceContext webhookConfiguration(WebhookConfiguration configuration) {
webhookConfiguration = configuration;
return this;
}
/**
* Defines the {@link WebhookRegistration} mode to use in this context.
*
* @param mode the mode.
* @return {@code this} for method chaining.
*/
@NonNull
public final BitbucketSCMSourceContext webhookRegistration(WebhookRegistration mode) {
webhookRegistration = mode;
return this;
}
/**
* Defines the notification mode to use in this context.
*
* @param disabled {@code true} to disable automatic notifications.
* @return {@code this} for method chaining.
*/
@NonNull
public final BitbucketSCMSourceContext withNotificationsDisabled(boolean disabled) {
this.notificationsDisabled = disabled;
return this;
}
/**
* Defines behaviour of unstable builds in Bitbucket.
*
* @param isUnstableBuildSuccess {@code true} to consider unstable builds successful when notifying Bitbucket.
* @return {@code this} for method chaining.
*/
@NonNull
public final BitbucketSCMSourceContext withSendSuccessNotificationForUnstableBuild(boolean isUnstableBuildSuccess) {
this.sendSuccessNotificationForUnstableBuild = isUnstableBuildSuccess;
return this;
}
/**
* Defines behaviour of build status name and key.
*
* @param buildStatusIncludeJenkinsURL {@code true} to inluce Jenkins URL to the build status key/name.
* @return {@code this} for method chaining.
*/
@NonNull
public final BitbucketSCMSourceContext withBuildStatusIncludeJenkinsURL(boolean buildStatusIncludeJenkinsURL) {
this.buildStatusIncludeJenkinsURL = buildStatusIncludeJenkinsURL;
return this;
}
/**
* {@inheritDoc}
*/
@NonNull
@Override
public BitbucketSCMSourceRequest newRequest(@NonNull SCMSource scmSource, TaskListener taskListener) {
return new BitbucketSCMSourceRequest((BitbucketSCMSource) scmSource, this, taskListener);
}
}