(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:
Akash Rindhe
2021-04-16 23:17:38 +08:00
parent 884248930e
commit 8bd3f391da
2 changed files with 25 additions and 15 deletions

View File

@@ -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));
}
/**

View File

@@ -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)),