forked from jenkinsci/jira-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJiraRestService.java
More file actions
582 lines (518 loc) · 26.7 KB
/
JiraRestService.java
File metadata and controls
582 lines (518 loc) · 26.7 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
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
/*
* Copyright 2015 Hao Cheng Lee
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package hudson.plugins.jira;
import static java.util.logging.Level.FINE;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import com.atlassian.jira.rest.client.api.RestClientException;
import com.atlassian.jira.rest.client.api.domain.BasicIssue;
import com.atlassian.jira.rest.client.api.domain.BasicProject;
import com.atlassian.jira.rest.client.api.domain.BasicUser;
import com.atlassian.jira.rest.client.api.domain.Comment;
import com.atlassian.jira.rest.client.api.domain.Component;
import com.atlassian.jira.rest.client.api.domain.Issue;
import com.atlassian.jira.rest.client.api.domain.IssueFieldId;
import com.atlassian.jira.rest.client.api.domain.IssueType;
import com.atlassian.jira.rest.client.api.domain.Permissions;
import com.atlassian.jira.rest.client.api.domain.Priority;
import com.atlassian.jira.rest.client.api.domain.SearchResult;
import com.atlassian.jira.rest.client.api.domain.Status;
import com.atlassian.jira.rest.client.api.domain.Transition;
import com.atlassian.jira.rest.client.api.domain.User;
import com.atlassian.jira.rest.client.api.domain.Version;
import com.atlassian.jira.rest.client.api.domain.input.ComplexIssueInputFieldValue;
import com.atlassian.jira.rest.client.api.domain.input.FieldInput;
import com.atlassian.jira.rest.client.api.domain.input.IssueInput;
import com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder;
import com.atlassian.jira.rest.client.api.domain.input.TransitionInput;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import hudson.ProxyConfiguration;
import hudson.plugins.jira.extension.ExtendedJiraRestClient;
import hudson.plugins.jira.extension.ExtendedVersion;
import hudson.plugins.jira.extension.ExtendedVersionInput;
import hudson.plugins.jira.model.JiraIssueField;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import jenkins.model.Jenkins;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpHost;
import org.apache.http.client.fluent.Content;
import org.apache.http.client.fluent.Request;
import org.apache.http.client.utils.URIBuilder;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
public class JiraRestService {
private static final Logger LOGGER = Logger.getLogger(JiraRestService.class.getName());
public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd");
/**
* Base URI path for a REST API call. It must be relative to site's base
* URI.
*/
public static final String BASE_API_PATH = "rest/api/2";
static final long BUG_ISSUE_TYPE_ID = 1L;
private final URI uri;
private final ExtendedJiraRestClient jiraRestClient;
private final ObjectMapper objectMapper;
private final String authHeader;
private final String baseApiPath;
private final int timeout;
@Deprecated
public JiraRestService(URI uri, ExtendedJiraRestClient jiraRestClient, String username, String password) {
this(uri, jiraRestClient, username, password, JiraSite.DEFAULT_TIMEOUT);
}
public JiraRestService(
URI uri, ExtendedJiraRestClient jiraRestClient, String username, String password, int timeout) {
this.uri = uri;
this.objectMapper = new ObjectMapper();
this.timeout = timeout;
final String login = username + ":" + password;
try {
byte[] encodeBase64 = Base64.encodeBase64(login.getBytes("UTF-8"));
this.authHeader = "Basic " + new String(encodeBase64, "UTF-8");
} catch (UnsupportedEncodingException e) {
LOGGER.warning("Jira REST encode username:password error. cause: " + e.getMessage());
throw new RuntimeException("failed to encode username:password using Base64");
}
this.jiraRestClient = jiraRestClient;
baseApiPath = buildBaseApiPath(uri);
}
public JiraRestService(URI uri, ExtendedJiraRestClient jiraRestClient, String token, int timeout) {
this.uri = uri;
this.objectMapper = new ObjectMapper();
this.timeout = timeout;
this.authHeader = "Bearer " + token;
this.jiraRestClient = jiraRestClient;
baseApiPath = buildBaseApiPath(uri);
}
private String buildBaseApiPath(URI uri) {
final StringBuilder builder = new StringBuilder();
if (uri.getPath() != null) {
builder.append(uri.getPath());
if (!uri.getPath().endsWith("/")) {
builder.append('/');
}
} else {
builder.append('/');
}
builder.append(BASE_API_PATH);
return builder.toString();
}
public void addComment(String issueId, String commentBody, String groupVisibility, String roleVisibility) {
final URIBuilder builder =
new URIBuilder(uri).setPath(String.format("%s/issue/%s/comment", baseApiPath, issueId));
final Comment comment;
if (StringUtils.isNotBlank(groupVisibility)) {
comment = Comment.createWithGroupLevel(commentBody, groupVisibility);
} else if (StringUtils.isNotBlank(roleVisibility)) {
comment = Comment.createWithRoleLevel(commentBody, roleVisibility);
} else {
comment = Comment.valueOf(commentBody);
}
try {
jiraRestClient.getIssueClient().addComment(builder.build(), comment).get(timeout, TimeUnit.SECONDS);
} catch (RestClientException
| URISyntaxException
| InterruptedException
| ExecutionException
| TimeoutException e) {
LOGGER.log(WARNING, "Jira REST client add comment error. cause: " + e.getMessage(), e);
throw new RestClientException(
"[Jira] Jira REST client add comment error. cause: " + e.getMessage(), e.getCause());
}
}
public Issue getIssue(String issueKey) {
LOGGER.log(FINE, "[Jira] Fetching issue {0}", issueKey);
try {
return jiraRestClient.getIssueClient().getIssue(issueKey).get(timeout, TimeUnit.SECONDS);
} catch (RestClientException | InterruptedException | ExecutionException | TimeoutException e) {
if (e.getCause() != null
&& e.getCause() instanceof RestClientException
&& ((RestClientException) e.getCause()).getStatusCode().isPresent()
&& ((RestClientException) e.getCause()).getStatusCode().get() == 404) {
LOGGER.log(INFO, "Issue '" + issueKey + "' not found in Jira.");
throw new RestClientException("[Jira] Issue '" + issueKey + "' not found in Jira.", e.getCause());
} else {
LOGGER.log(WARNING, "Jira REST client get issue error. cause: " + e.getMessage(), e);
throw new RestClientException(
"[Jira] Jira REST client get issue error. cause: " + e.getMessage(), e.getCause());
}
}
}
public List<IssueType> getIssueTypes() {
try {
return StreamSupport.stream(
jiraRestClient
.getMetadataClient()
.getIssueTypes()
.get(timeout, TimeUnit.SECONDS)
.spliterator(),
false)
.collect(Collectors.toList());
} catch (RestClientException | InterruptedException | ExecutionException | TimeoutException e) {
LOGGER.log(WARNING, "Jira REST client get issue types error. cause: " + e.getMessage(), e);
throw new RestClientException(
"[Jira] Jira REST client get issue types error. cause: " + e.getMessage(), e.getCause());
}
}
public List<Priority> getPriorities() {
try {
return StreamSupport.stream(
jiraRestClient
.getMetadataClient()
.getPriorities()
.get(timeout, TimeUnit.SECONDS)
.spliterator(),
false)
.collect(Collectors.toList());
} catch (RestClientException | InterruptedException | ExecutionException | TimeoutException e) {
LOGGER.log(WARNING, "Jira REST client get priorities error. cause: " + e.getMessage(), e);
throw new RestClientException(
"[Jira] Jira REST client get priorities error. cause: " + e.getMessage(), e.getCause());
}
}
public List<String> getProjectsKeys() {
Iterable<BasicProject> projects = Collections.emptyList();
try {
projects = jiraRestClient.getProjectClient().getAllProjects().get(timeout, TimeUnit.SECONDS);
} catch (RestClientException | InterruptedException | ExecutionException | TimeoutException e) {
LOGGER.log(WARNING, "Jira REST client get project keys error. cause: " + e.getMessage(), e);
throw new RestClientException(
"[Jira] Jira REST client get project keys error. cause: " + e.getMessage(), e.getCause());
}
final List<String> keys = new ArrayList<>();
for (BasicProject project : projects) {
keys.add(project.getKey());
}
return keys;
}
public List<Issue> getIssuesFromJqlSearch(String jqlSearch, Integer maxResults) throws RestClientException {
LOGGER.log(FINE, "[Jira] Executing JQL: {0}", jqlSearch);
try {
Set<String> neededFields = new HashSet<>(
Arrays.asList("summary", "issuetype", "created", "updated", "project", "status", "fixVersions"));
final SearchResult searchResult = jiraRestClient
.getSearchClient()
.searchJql(jqlSearch, maxResults, 0, neededFields)
.get(timeout, TimeUnit.SECONDS);
return StreamSupport.stream(searchResult.getIssues().spliterator(), false)
.collect(Collectors.toList());
} catch (RestClientException
| TimeoutException
| CancellationException
| ExecutionException
| InterruptedException e) {
LOGGER.log(WARNING, "Jira REST client get issue from jql search error. cause: " + e.getMessage(), e);
throw new RestClientException(
"[Jira] Jira REST client get issue from jql search error. cause: " + e.getMessage(), e.getCause());
}
}
public List<ExtendedVersion> getVersions(String projectKey) {
final URIBuilder builder =
new URIBuilder(uri).setPath(String.format("%s/project/%s/versions", baseApiPath, projectKey));
List<Map<String, Object>> decoded = Collections.emptyList();
try {
URI uri = builder.build();
final Content content = buildGetRequest(uri).execute().returnContent();
decoded = objectMapper.readValue(content.asString(), new TypeReference<List<Map<String, Object>>>() {});
} catch (URISyntaxException | IOException e) {
LOGGER.log(WARNING, "Jira REST client get versions error. cause: " + e.getMessage(), e);
throw new RestClientException(
"[Jira] Jira REST client get versions error. cause: " + e.getMessage(), e.getCause());
}
return decoded.stream()
.map(decodedVersion -> {
final DateTime startDate = decodedVersion.containsKey("startDate")
? DATE_TIME_FORMATTER.parseDateTime((String) decodedVersion.get("startDate"))
: null;
final DateTime releaseDate = decodedVersion.containsKey("releaseDate")
? DATE_TIME_FORMATTER.parseDateTime((String) decodedVersion.get("releaseDate"))
: null;
return new ExtendedVersion(
URI.create((String) decodedVersion.get("self")),
Long.parseLong((String) decodedVersion.get("id")),
(String) decodedVersion.get("name"),
(String) decodedVersion.get("description"),
(Boolean) decodedVersion.get("archived"),
(Boolean) decodedVersion.get("released"),
startDate,
releaseDate);
})
.collect(Collectors.toList());
}
public Version addVersion(String projectKey, String versionName) {
final ExtendedVersionInput versionInput =
new ExtendedVersionInput(projectKey, versionName, null, DateTime.now(), null, false, false);
try {
return jiraRestClient
.getExtendedVersionRestClient()
.createExtendedVersion(versionInput)
.get(timeout, TimeUnit.SECONDS);
} catch (RestClientException | InterruptedException | ExecutionException | TimeoutException e) {
LOGGER.log(WARNING, "Jira REST client add version error. cause: " + e.getMessage(), e);
throw new RestClientException(
"[Jira] Jira REST client add version error. cause: " + e.getMessage(), e.getCause());
}
}
public void releaseVersion(String projectKey, ExtendedVersion version) {
final URIBuilder builder =
new URIBuilder(uri).setPath(String.format("%s/version/%s", baseApiPath, version.getId()));
final ExtendedVersionInput versionInput = new ExtendedVersionInput(
projectKey,
version.getName(),
version.getDescription(),
version.getStartDate(),
version.getReleaseDate(),
version.isArchived(),
version.isReleased());
try {
jiraRestClient
.getExtendedVersionRestClient()
.updateExtendedVersion(builder.build(), versionInput)
.get(timeout, TimeUnit.SECONDS);
} catch (RestClientException
| URISyntaxException
| InterruptedException
| ExecutionException
| TimeoutException e) {
LOGGER.log(WARNING, "Jira REST client release version error. cause: " + e.getMessage(), e);
throw new RestClientException(
"[Jira] Jira REST client release version error. cause: " + e.getMessage(), e.getCause());
}
}
@Deprecated
public BasicIssue createIssue(
String projectKey, String description, String assignee, Iterable<String> components, String summary) {
return createIssue(projectKey, description, assignee, components, summary, BUG_ISSUE_TYPE_ID, null);
}
public BasicIssue createIssue(
String projectKey,
String description,
String assignee,
Iterable<String> components,
String summary,
@NonNull Long issueTypeId,
@Nullable Long priorityId) {
IssueInputBuilder builder = new IssueInputBuilder();
builder.setProjectKey(projectKey)
.setDescription(description)
.setIssueTypeId(issueTypeId)
.setSummary(summary);
if (priorityId != null) {
builder.setPriorityId(priorityId);
}
if (StringUtils.isNotBlank(assignee)) {
final Map<String, Object> valuesMap = new HashMap<>(2);
valuesMap.put("name", assignee); // server
valuesMap.put("accountId", assignee); // cloud
// Need to use "accountId" as specified here:
//
// https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-user-privacy-api-migration-guide/
//
// See upstream fix for setAssigneeName:
//
// https://bitbucket.org/atlassian/jira-rest-java-client/pull-requests/104/change-field-name-from-name-to-id-for/diff
builder.setFieldInput(
new FieldInput(IssueFieldId.ASSIGNEE_FIELD, new ComplexIssueInputFieldValue(valuesMap)));
}
if (StreamSupport.stream(components.spliterator(), false).count() > 0) {
builder.setComponentsNames(components);
}
final IssueInput issueInput = builder.build();
try {
return jiraRestClient.getIssueClient().createIssue(issueInput).get(timeout, TimeUnit.SECONDS);
} catch (RestClientException | InterruptedException | ExecutionException | TimeoutException e) {
LOGGER.log(WARNING, "Jira REST createIssue error: " + e.getMessage(), e);
throw new RestClientException("[Jira] Jira REST createIssue error. cause: " + e.getMessage(), e.getCause());
}
}
public User getUser(String username) {
try {
return jiraRestClient.getUserClient().getUser(username).get(timeout, TimeUnit.SECONDS);
} catch (RestClientException | InterruptedException | ExecutionException | TimeoutException e) {
if (e.getCause() != null
&& e.getCause() instanceof RestClientException
&& ((RestClientException) e.getCause()).getStatusCode().isPresent()
&& ((RestClientException) e.getCause()).getStatusCode().get() == 404) {
LOGGER.log(INFO, "User '" + username + "' not found in Jira.");
throw new RestClientException("[Jira] User '" + username + "' not found in Jira.", e.getCause());
} else {
LOGGER.log(WARNING, "Jira REST client get user error. cause: " + e.getMessage(), e);
throw new RestClientException(
"[Jira] Jira REST client get user error. cause: " + e.getMessage(), e.getCause());
}
}
}
public void updateIssue(String issueKey, List<Version> fixVersions) {
final IssueInput issueInput =
new IssueInputBuilder().setFixVersions(fixVersions).build();
try {
jiraRestClient.getIssueClient().updateIssue(issueKey, issueInput).get(timeout, TimeUnit.SECONDS);
} catch (RestClientException | InterruptedException | ExecutionException | TimeoutException e) {
LOGGER.log(WARNING, "Jira REST client update issue error. cause: " + e.getMessage(), e);
throw new RestClientException(
"[Jira] Jira REST client update issue error. cause: " + e.getMessage(), e.getCause());
}
}
public void setIssueLabels(String issueKey, List<String> labels) {
final IssueInput issueInput = new IssueInputBuilder()
.setFieldValue(IssueFieldId.LABELS_FIELD.id, labels)
.build();
try {
jiraRestClient.getIssueClient().updateIssue(issueKey, issueInput).get(timeout, TimeUnit.SECONDS);
} catch (RestClientException | InterruptedException | ExecutionException | TimeoutException e) {
LOGGER.log(WARNING, "Jira REST client update labels error for issue " + issueKey, e);
throw new RestClientException(
"[Jira] Jira REST client update labels error for issue: " + issueKey + ". cause: " + e.getMessage(),
e.getCause());
}
}
public void setIssueFields(String issueKey, List<JiraIssueField> fields) {
IssueInputBuilder builder = new IssueInputBuilder();
for (JiraIssueField field : fields) {
builder.setFieldValue(field.getId(), field.getValue());
}
final IssueInput issueInput = builder.build();
try {
jiraRestClient.getIssueClient().updateIssue(issueKey, issueInput).get(timeout, TimeUnit.SECONDS);
} catch (RestClientException | InterruptedException | ExecutionException | TimeoutException e) {
LOGGER.log(WARNING, "Jira REST client update fields error for issue " + issueKey, e);
throw new RestClientException(
"[Jira] Jira REST client update fields error for issue: " + issueKey + ". cause: " + e.getMessage(),
e.getCause());
}
}
public Issue progressWorkflowAction(String issueKey, Integer actionId) {
final TransitionInput transitionInput = new TransitionInput(actionId);
final Issue issue = getIssue(issueKey);
try {
jiraRestClient.getIssueClient().transition(issue, transitionInput).get(timeout, TimeUnit.SECONDS);
} catch (RestClientException | InterruptedException | ExecutionException | TimeoutException e) {
LOGGER.log(WARNING, "Jira REST client process workflow action error. cause: " + e.getMessage(), e);
throw new RestClientException(
"[Jira] Jira REST client process workflow action error. cause: " + e.getMessage(), e.getCause());
}
return issue;
}
public List<Transition> getAvailableActions(String issueKey) {
final Issue issue = getIssue(issueKey);
try {
final Iterable<Transition> transitions =
jiraRestClient.getIssueClient().getTransitions(issue).get(timeout, TimeUnit.SECONDS);
return StreamSupport.stream(transitions.spliterator(), false).collect(Collectors.toList());
} catch (RestClientException | InterruptedException | ExecutionException | TimeoutException e) {
LOGGER.log(WARNING, "Jira REST client get available actions error. cause: " + e.getMessage(), e);
throw new RestClientException(
"[Jira] Jira REST client get available actions error. cause: " + e.getMessage(), e.getCause());
}
}
public List<Status> getStatuses() {
try {
final Iterable<Status> statuses =
jiraRestClient.getMetadataClient().getStatuses().get(timeout, TimeUnit.SECONDS);
return StreamSupport.stream(statuses.spliterator(), false).collect(Collectors.toList());
} catch (RestClientException | InterruptedException | ExecutionException | TimeoutException e) {
LOGGER.log(WARNING, "Jira REST client get statuses error. cause: " + e.getMessage(), e);
throw new RestClientException(
"[Jira] Jira REST client get statuses error. cause: " + e.getMessage(), e.getCause());
}
}
public List<Component> getComponents(String projectKey) {
final URIBuilder builder =
new URIBuilder(uri).setPath(String.format("%s/project/%s/components", baseApiPath, projectKey));
try {
final Content content = buildGetRequest(builder.build()).execute().returnContent();
final List<Map<String, Object>> decoded =
objectMapper.readValue(content.asString(), new TypeReference<List<Map<String, Object>>>() {});
final List<Component> components = new ArrayList<>();
for (final Map<String, Object> decodeComponent : decoded) {
BasicUser lead = null;
if (decodeComponent.containsKey("lead")) {
final Map<String, Object> decodedLead = (Map<String, Object>) decodeComponent.get("lead");
lead = new BasicUser(
URI.create((String) decodedLead.get("self")),
(String) decodedLead.get("name"),
(String) decodedLead.get("displayName"),
(String) decodedLead.get("accountId"));
}
final Component component = new Component(
URI.create((String) decodeComponent.get("self")),
Long.parseLong((String) decodeComponent.get("id")),
(String) decodeComponent.get("name"),
(String) decodeComponent.get("description"),
lead);
components.add(component);
}
return components;
} catch (URISyntaxException | IOException e) {
LOGGER.log(WARNING, "Jira REST client process workflow action error. cause: " + e.getMessage(), e);
throw new RestClientException(
"[Jira] Jira REST client process workflow action error. cause: " + e.getMessage(), e.getCause());
}
}
private Request buildGetRequest(URI uri) {
Request request = Request.Get(uri);
ProxyConfiguration proxyConfiguration = Jenkins.get().proxy;
if (proxyConfiguration != null) {
final HttpHost proxyHost = new HttpHost(proxyConfiguration.name, proxyConfiguration.port);
boolean shouldByPassProxy = proxyConfiguration.getNoProxyHostPatterns().stream()
.anyMatch(it -> it.matcher(uri.getHost()).matches());
if (!shouldByPassProxy) {
request.viaProxy(proxyHost);
}
}
return request.connectTimeout(timeoutInMilliseconds())
.socketTimeout(timeoutInMilliseconds())
.addHeader("Authorization", authHeader)
.addHeader("Content-Type", "application/json");
}
protected int timeoutInMilliseconds() {
return (int) TimeUnit.SECONDS.toMillis(timeout);
}
public String getBaseApiPath() {
return baseApiPath;
}
/**
* Get User's permissions
*/
public Permissions getMyPermissions() {
return jiraRestClient
.getExtendedMyPermissionsRestClient()
.getMyPermissions()
.claim();
}
}