Skip to content

Commit b51d3ab

Browse files
ExtendedGitHubClient.java
- add support for delete operations to parse json responses ExtendedIssueService.java - the removeLabel() method now calls the new delete() to parse the response returned by this operation. This fixed jenkinsci#52 Thanks @longwave for tracking this down
1 parent c03464e commit b51d3ab

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

src/main/java/org/jenkinsci/plugins/pipeline/github/client/ExtendedGitHubClient.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.eclipse.egit.github.core.client.GitHubClient;
44
import org.eclipse.egit.github.core.client.GitHubRequest;
55
import org.eclipse.egit.github.core.client.GitHubResponse;
6-
import org.eclipse.egit.github.core.client.RequestException;
76

87
import java.io.IOException;
98
import java.io.UncheckedIOException;
@@ -62,22 +61,6 @@ public <V> V put(final String uri, final Object params, final Type type, final S
6261
return this.sendJson(request, params, type);
6362
}
6463

65-
public void delete(final String uri, final Object params, final String accept) throws IOException {
66-
HttpURLConnection request = this.createDelete(uri);
67-
if (accept != null) {
68-
request.setRequestProperty("Accept", accept);
69-
}
70-
if (params != null) {
71-
this.sendParams(request, params);
72-
}
73-
74-
int code = request.getResponseCode();
75-
this.updateRateLimits(request);
76-
if (!this.isEmpty(code)) {
77-
throw new RequestException(this.parseError(this.getStream(request)), code);
78-
}
79-
}
80-
8164
// duplicated here because it's private in the super class.
8265
private <V> V sendJson(final HttpURLConnection request, final Object params, final Type type) throws IOException {
8366
this.sendParams(request, params);
@@ -101,4 +84,21 @@ public GitHubResponse getUnchecked(final GitHubRequest request) {
10184
}
10285
}
10386

87+
public <V> V delete(final String uri, final Type type, final String accept) throws IOException {
88+
HttpURLConnection request = this.createDelete(uri);
89+
if (accept != null) {
90+
request.setRequestProperty("Accept", accept);
91+
}
92+
93+
int code = request.getResponseCode();
94+
this.updateRateLimits(request);
95+
if (this.isOk(code)) {
96+
return type != null ? this.parseJson(this.getStream(request), type) : null;
97+
} else if (this.isEmpty(code)) {
98+
return null;
99+
} else {
100+
throw this.createException(this.getStream(request), code, request.getResponseMessage());
101+
}
102+
}
103+
104104
}

src/main/java/org/jenkinsci/plugins/pipeline/github/client/ExtendedIssueService.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ public List<Label> addLabels(final IRepositoryIdProvider repository,
141141
return getClient().post(uri.toString(), labels, (new TypeToken<List<Label>>() {}).getType());
142142
}
143143

144-
public void removeLabel(final IRepositoryIdProvider repository,
145-
final int issueNumber,
146-
final String label) throws IOException {
144+
public List<Label> removeLabel(final IRepositoryIdProvider repository,
145+
final int issueNumber,
146+
final String label) throws IOException {
147147
final String repoId = this.getId(repository);
148148
final StringBuilder uri = new StringBuilder("/repos");
149149
uri.append('/').append(repoId);
@@ -156,7 +156,8 @@ public void removeLabel(final IRepositoryIdProvider repository,
156156
.replace("+", "%20")
157157
.replace(".", "%2E");
158158
uri.append(encodedLabel);
159-
getClient().delete(uri.toString());
159+
160+
return getClient().delete(uri.toString(), (new TypeToken<List<Label>>() {}).getType(), null);
160161
}
161162

162163
}

0 commit comments

Comments
 (0)