From b97e8a2c389d945024e87c5adaaff4800d3ad62b Mon Sep 17 00:00:00 2001 From: Akash Rindhe Date: Fri, 16 Apr 2021 23:35:23 +0800 Subject: [PATCH] (feat) Return GHLabel list instead of void on GHIssue#removeLabel(s) #1050 Includes BridgeMethod annotation to keep binary compatibility (https://github.com/hub4j/github-api/issues/1050) --- src/main/java/org/kohsuke/github/GHIssue.java | 33 +++++++++++++------ .../org/kohsuke/github/GHPullRequestTest.java | 3 +- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index c897e03b7..a379d2f6e 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -384,13 +384,18 @@ public class GHIssue extends GHObject implements Reactable { * * Attempting to remove a label that is not present throws {@link GHFileNotFoundException}. * + * @return the remaining list of labels * @param name * the name * @throws IOException * the io exception, throws {@link GHFileNotFoundException} if label was not present. */ - public void removeLabel(String name) throws IOException { - root.createRequest().method("DELETE").withUrlPath(getIssuesApiRoute() + "/labels", name).send(); + @WithBridgeMethods(void.class) + public List removeLabel(String name) throws IOException { + return Arrays.asList(root.createRequest() + .method("DELETE") + .withUrlPath(getIssuesApiRoute() + "/labels", name) + .fetch(GHLabel[].class)); } /** @@ -398,13 +403,15 @@ public class GHIssue extends GHObject implements Reactable { * * Attempting to remove labels that are not present on the target are ignored. * + * @return the remaining list of labels * @param names * the names * @throws IOException * the io exception */ - public void removeLabels(String... names) throws IOException { - _removeLabels(Arrays.asList(names)); + @WithBridgeMethods(void.class) + public List removeLabels(String... names) throws IOException { + return _removeLabels(Arrays.asList(names)); } /** @@ -412,14 +419,16 @@ public class GHIssue extends GHObject implements Reactable { * * Attempting to remove labels that are not present on the target are ignored. * + * @return the remaining list of labels * @param labels * the labels * @throws IOException * the io exception * @see #removeLabels(String...) #removeLabels(String...) */ - public void removeLabels(GHLabel... labels) throws IOException { - removeLabels(Arrays.asList(labels)); + @WithBridgeMethods(void.class) + public List removeLabels(GHLabel... labels) throws IOException { + return removeLabels(Arrays.asList(labels)); } /** @@ -427,23 +436,27 @@ public class GHIssue extends GHObject implements Reactable { * * Attempting to remove labels that are not present on the target are ignored. * + * @return the remaining list of labels * @param labels * the labels * @throws IOException * the io exception */ - public void removeLabels(Collection labels) throws IOException { - _removeLabels(GHLabel.toNames(labels)); + @WithBridgeMethods(void.class) + public List removeLabels(Collection labels) throws IOException { + return _removeLabels(GHLabel.toNames(labels)); } - private void _removeLabels(Collection names) throws IOException { + private List _removeLabels(Collection names) throws IOException { + List remainingLabels = Collections.emptyList(); for (String name : names) { try { - removeLabel(name); + remainingLabels = removeLabel(name); } catch (GHFileNotFoundException e) { // when trying to remove multiple labels, we ignore already removed } } + return remainingLabels; } /** diff --git a/src/test/java/org/kohsuke/github/GHPullRequestTest.java b/src/test/java/org/kohsuke/github/GHPullRequestTest.java index c1f888405..b8a3d17f8 100644 --- a/src/test/java/org/kohsuke/github/GHPullRequestTest.java +++ b/src/test/java/org/kohsuke/github/GHPullRequestTest.java @@ -493,11 +493,10 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest { assertEquals(3, labels.size()); int requestCount = mockGitHub.getRequestCount(); - p.removeLabels(label2, label3); + labels = p.removeLabels(label2, label3); // each label deleted is a separate api call assertThat(mockGitHub.getRequestCount(), equalTo(requestCount + 2)); - labels = getRepository().getPullRequest(p.getNumber()).getLabels(); assertEquals(1, labels.size()); assertEquals(label1, labels.iterator().next().getName());