mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-10 08:21:21 +00:00
(feat) Return GHLabel list instead of void on GHIssue#addLabels #1050
Includes BridgeMethod annotation to keep binary compatibility (https://github.com/hub4j/github-api/issues/1050)
This commit is contained in:
@@ -328,13 +328,15 @@ public class GHIssue extends GHObject implements Reactable {
|
||||
*
|
||||
* Labels that are already present on the target are ignored.
|
||||
*
|
||||
* @return the complete list of labels including the new additions
|
||||
* @param names
|
||||
* Names of the label
|
||||
* @throws IOException
|
||||
* the io exception
|
||||
*/
|
||||
public void addLabels(String... names) throws IOException {
|
||||
_addLabels(Arrays.asList(names));
|
||||
@WithBridgeMethods(void.class)
|
||||
public List<GHLabel> addLabels(String... names) throws IOException {
|
||||
return _addLabels(Arrays.asList(names));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -342,13 +344,15 @@ public class GHIssue extends GHObject implements Reactable {
|
||||
*
|
||||
* Labels that are already present on the target are ignored.
|
||||
*
|
||||
* @return the complete list of labels including the new additions
|
||||
* @param labels
|
||||
* the labels
|
||||
* @throws IOException
|
||||
* the io exception
|
||||
*/
|
||||
public void addLabels(GHLabel... labels) throws IOException {
|
||||
addLabels(Arrays.asList(labels));
|
||||
@WithBridgeMethods(void.class)
|
||||
public List<GHLabel> addLabels(GHLabel... labels) throws IOException {
|
||||
return addLabels(Arrays.asList(labels));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -356,17 +360,23 @@ public class GHIssue extends GHObject implements Reactable {
|
||||
*
|
||||
* Labels that are already present on the target are ignored.
|
||||
*
|
||||
* @return the complete list of labels including the new additions
|
||||
* @param labels
|
||||
* the labels
|
||||
* @throws IOException
|
||||
* the io exception
|
||||
*/
|
||||
public void addLabels(Collection<GHLabel> labels) throws IOException {
|
||||
_addLabels(GHLabel.toNames(labels));
|
||||
@WithBridgeMethods(void.class)
|
||||
public List<GHLabel> addLabels(Collection<GHLabel> labels) throws IOException {
|
||||
return _addLabels(GHLabel.toNames(labels));
|
||||
}
|
||||
|
||||
private void _addLabels(Collection<String> names) throws IOException {
|
||||
root.createRequest().with("labels", names).method("POST").withUrlPath(getIssuesApiRoute() + "/labels").send();
|
||||
private List<GHLabel> _addLabels(Collection<String> names) throws IOException {
|
||||
return Arrays.asList(root.createRequest()
|
||||
.with("labels", names)
|
||||
.method("POST")
|
||||
.withUrlPath(getIssuesApiRoute() + "/labels")
|
||||
.fetch(GHLabel[].class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -440,16 +440,17 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
|
||||
String addedLabel2 = "addLabels_label_name_2";
|
||||
String addedLabel3 = "addLabels_label_name_3";
|
||||
|
||||
p.addLabels(addedLabel1);
|
||||
Collection<GHLabel> resultingLabels = p.addLabels(addedLabel1);
|
||||
assertEquals(1, resultingLabels.size());
|
||||
assertThat(resultingLabels, containsInAnyOrder(hasProperty("name", equalTo(addedLabel1))));
|
||||
|
||||
int requestCount = mockGitHub.getRequestCount();
|
||||
p.addLabels(addedLabel2, addedLabel3);
|
||||
resultingLabels = p.addLabels(addedLabel2, addedLabel3);
|
||||
// multiple labels can be added with one api call
|
||||
assertThat(mockGitHub.getRequestCount(), equalTo(requestCount + 1));
|
||||
|
||||
Collection<GHLabel> labels = getRepository().getPullRequest(p.getNumber()).getLabels();
|
||||
assertEquals(3, labels.size());
|
||||
assertThat(labels,
|
||||
assertEquals(3, resultingLabels.size());
|
||||
assertThat(resultingLabels,
|
||||
containsInAnyOrder(hasProperty("name", equalTo(addedLabel1)),
|
||||
hasProperty("name", equalTo(addedLabel2)),
|
||||
hasProperty("name", equalTo(addedLabel3))));
|
||||
@@ -471,9 +472,8 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
|
||||
GHPullRequest p2 = getRepository().getPullRequest(p1.getNumber());
|
||||
p2.addLabels(addedLabel2);
|
||||
|
||||
p1.addLabels(addedLabel1);
|
||||
Collection<GHLabel> labels = p1.addLabels(addedLabel1);
|
||||
|
||||
Collection<GHLabel> labels = getRepository().getPullRequest(p1.getNumber()).getLabels();
|
||||
assertEquals(2, labels.size());
|
||||
assertThat(labels,
|
||||
containsInAnyOrder(hasProperty("name", equalTo(addedLabel1)),
|
||||
|
||||
Reference in New Issue
Block a user