From dfa379328f6c80b490400e500383e2a5e445ae6c Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 10 Jan 2017 11:37:29 -0500 Subject: [PATCH] Support new label names containing colons --- mvnw | 0 .../io/spring/issuebot/github/GitHubTemplate.java | 10 +++++++++- src/main/resources/application.yml | 8 ++++---- .../spring/issuebot/github/GitHubTemplateTests.java | 11 +++++++++++ 4 files changed, 24 insertions(+), 5 deletions(-) mode change 100644 => 100755 mvnw diff --git a/mvnw b/mvnw old mode 100644 new mode 100755 diff --git a/src/main/java/io/spring/issuebot/github/GitHubTemplate.java b/src/main/java/io/spring/issuebot/github/GitHubTemplate.java index faca601..aa1e27f 100644 --- a/src/main/java/io/spring/issuebot/github/GitHubTemplate.java +++ b/src/main/java/io/spring/issuebot/github/GitHubTemplate.java @@ -19,6 +19,7 @@ package io.spring.issuebot.github; import java.io.IOException; import java.lang.reflect.Type; import java.net.URI; +import java.net.URISyntaxException; import java.nio.charset.Charset; import java.util.Arrays; import java.util.Collections; @@ -153,9 +154,16 @@ public class GitHubTemplate implements GitHubOperations { @Override public Issue removeLabel(Issue issue, String labelName) { + String encodedName; + try { + encodedName = new URI(null, null, labelName, null).toString(); + } + catch (URISyntaxException ex) { + throw new RuntimeException(ex); + } ResponseEntity response = this.rest.exchange( new RequestEntity(HttpMethod.DELETE, URI.create( - issue.getLabelsUrl().replace("{/name}", "/" + labelName))), + issue.getLabelsUrl().replace("{/name}", "/" + encodedName))), Label[].class); if (response.getStatusCode() != HttpStatus.OK) { log.warn("Failed to remove label from issue. Response status: " diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3be366b..6c0e311 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -10,11 +10,11 @@ issuebot: - snicoll - wilkinsona triage: - label: waiting-for-triage + label: "status: waiting-for-triage" feedback: - required_label: waiting-for-feedback - provided_label: feedback-provided - reminder_label: feedback-reminder + required_label: "status: waiting-for-feedback" + provided_label: "status: feedback-provided" + reminder_label: "status: feedback-reminder" reminder_comment: > If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue diff --git a/src/test/java/io/spring/issuebot/github/GitHubTemplateTests.java b/src/test/java/io/spring/issuebot/github/GitHubTemplateTests.java index 605585b..b599a37 100644 --- a/src/test/java/io/spring/issuebot/github/GitHubTemplateTests.java +++ b/src/test/java/io/spring/issuebot/github/GitHubTemplateTests.java @@ -179,6 +179,17 @@ public class GitHubTemplateTests { assertThat(modifiedIssue.getLabels(), hasSize(0)); } + @Test + public void removeLabelWithNameThatRequiresEncodingFromIssue() { + this.server.expect(requestTo("labels/status:%20foo")).andExpect(method(HttpMethod.DELETE)) + .andExpect(basicAuth()) + .andRespond(withSuccess("[]", MediaType.APPLICATION_JSON)); + Issue issue = new Issue(null, null, null, "labels{/name}", null, null, null, + null); + Issue modifiedIssue = this.gitHub.removeLabel(issue, "status: foo"); + assertThat(modifiedIssue.getLabels(), hasSize(0)); + } + @Test public void addCommentToIssue() { this.server.expect(requestTo("commentsUrl")).andExpect(method(HttpMethod.POST))