From 7067ce6eec9767528bca799309cc32386cb70abe Mon Sep 17 00:00:00 2001 From: Nicolas Widart Date: Wed, 15 May 2019 22:56:06 +0200 Subject: [PATCH 01/13] Adding a method to get all closed issues --- .../issuebot/github/GitHubOperations.java | 9 +++++++ .../issuebot/github/GitHubTemplate.java | 7 +++++ .../issuebot/github/GitHubTemplateTests.java | 27 +++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/src/main/java/io/spring/issuebot/github/GitHubOperations.java b/src/main/java/io/spring/issuebot/github/GitHubOperations.java index b7e19d7..dc58974 100644 --- a/src/main/java/io/spring/issuebot/github/GitHubOperations.java +++ b/src/main/java/io/spring/issuebot/github/GitHubOperations.java @@ -32,6 +32,15 @@ public interface GitHubOperations { */ Page getIssues(String organization, String repository); + /** + * Returns the closed issues in the {@code repository} owned by the given + * {@code organization}. + * @param organization the name of the organization + * @param repository the name of the repository + * @return the issues + */ + Page getClosedIssues(String organization, String repository); + /** * Returns the comments that have been made on the given {@code issue}. * @param issue the issue diff --git a/src/main/java/io/spring/issuebot/github/GitHubTemplate.java b/src/main/java/io/spring/issuebot/github/GitHubTemplate.java index acd5e19..d457292 100644 --- a/src/main/java/io/spring/issuebot/github/GitHubTemplate.java +++ b/src/main/java/io/spring/issuebot/github/GitHubTemplate.java @@ -113,6 +113,13 @@ public Page getIssues(String organization, String repository) { return getPage(url, Issue[].class); } + @Override + public Page getClosedIssues(String organization, String repository) { + String url = "https://api.github.com/repos/" + organization + "/" + repository + + "/issues?state=closed"; + return getPage(url, Issue[].class); + } + @Override public Page getComments(Issue issue) { return getPage(issue.getCommentsUrl(), Comment[].class); diff --git a/src/test/java/io/spring/issuebot/github/GitHubTemplateTests.java b/src/test/java/io/spring/issuebot/github/GitHubTemplateTests.java index 06170b0..a7043af 100644 --- a/src/test/java/io/spring/issuebot/github/GitHubTemplateTests.java +++ b/src/test/java/io/spring/issuebot/github/GitHubTemplateTests.java @@ -80,6 +80,16 @@ public void singlePageOfIssues() { assertThat(issues.next()).isNull(); } + @Test + public void singlePageOfClosedIssue() { + this.server.expect(requestTo("https://api.github.com/repos/org/repo/issues?state=closed")) + .andExpect(method(HttpMethod.GET)).andExpect(basicAuth()) + .andRespond(withResource("issues-page-one.json")); + Page issues = this.gitHub.getClosedIssues("org", "repo"); + assertThat(issues.getContent()).hasSize(15); + assertThat(issues.next()).isNull(); + } + @Test public void multiplePagesOfIssues() { HttpHeaders headers = new HttpHeaders(); @@ -97,6 +107,23 @@ public void multiplePagesOfIssues() { assertThat(pageTwo.getContent()).hasSize(15); } + @Test + public void multiplePagesOfClosedIssues() { + HttpHeaders headers = new HttpHeaders(); + headers.set("Link", "; rel=\"next\""); + this.server.expect(requestTo("https://api.github.com/repos/org/repo/issues?state=closed")) + .andExpect(method(HttpMethod.GET)).andExpect(basicAuth()) + .andRespond(withResource("issues-page-one.json", + "Link:; rel=\"next\"")); + this.server.expect(requestTo("/page-two")).andExpect(method(HttpMethod.GET)) + .andExpect(basicAuth()).andRespond(withResource("issues-page-two.json")); + Page pageOne = this.gitHub.getClosedIssues("org", "repo"); + assertThat(pageOne.getContent()).hasSize(15); + Page pageTwo = pageOne.next(); + assertThat(pageTwo).isNotNull(); + assertThat(pageTwo.getContent()).hasSize(15); + } + @Test public void rateLimited() { long reset = System.currentTimeMillis(); From 92514ed59f12136950572ab35c0684d9bfd87178 Mon Sep 17 00:00:00 2001 From: Nicolas Widart Date: Thu, 16 May 2019 09:23:03 +0200 Subject: [PATCH 02/13] Adding the issue state field (open/closed) --- .../issuebot/github/GitHubTemplate.java | 4 +-- .../java/io/spring/issuebot/github/Issue.java | 20 ++++++++++++-- .../issuebot/RepositoryMonitorTests.java | 26 +++++++++++++++---- .../feedback/FeedbackIssueListenerTests.java | 18 ++++++------- .../StandardFeedbackListenerTests.java | 2 +- .../issuebot/github/GitHubTemplateTests.java | 20 +++++++------- .../LabelApplyingTriageListenerTests.java | 2 +- .../triage/LabelledTriageFilterTests.java | 6 ++--- .../MilestoneAppliedTriageFilterTests.java | 4 +-- ...OpenedByCollaboratorTriageFilterTests.java | 4 +-- .../triage/TriageIssueListenerTests.java | 13 ++++++++-- 11 files changed, 80 insertions(+), 39 deletions(-) diff --git a/src/main/java/io/spring/issuebot/github/GitHubTemplate.java b/src/main/java/io/spring/issuebot/github/GitHubTemplate.java index d457292..602b9ea 100644 --- a/src/main/java/io/spring/issuebot/github/GitHubTemplate.java +++ b/src/main/java/io/spring/issuebot/github/GitHubTemplate.java @@ -156,7 +156,7 @@ public Issue addLabel(Issue issue, String labelName) { } return new Issue(issue.getUrl(), issue.getCommentsUrl(), issue.getEventsUrl(), issue.getLabelsUrl(), issue.getUser(), Arrays.asList(response.getBody()), - issue.getMilestone(), issue.getPullRequest()); + issue.getMilestone(), issue.getPullRequest(), issue.getState()); } @Override @@ -178,7 +178,7 @@ public Issue removeLabel(Issue issue, String labelName) { } return new Issue(issue.getUrl(), issue.getCommentsUrl(), issue.getEventsUrl(), issue.getLabelsUrl(), issue.getUser(), Arrays.asList(response.getBody()), - issue.getMilestone(), issue.getPullRequest()); + issue.getMilestone(), issue.getPullRequest(), issue.getState()); } @Override diff --git a/src/main/java/io/spring/issuebot/github/Issue.java b/src/main/java/io/spring/issuebot/github/Issue.java index f81d11a..ea25241 100644 --- a/src/main/java/io/spring/issuebot/github/Issue.java +++ b/src/main/java/io/spring/issuebot/github/Issue.java @@ -44,6 +44,8 @@ public class Issue { private final PullRequest pullRequest; + private final String state; + /** * Creates a new {@code Issue}. * @param url the url of the issue in the GitHub API @@ -54,6 +56,7 @@ public class Issue { * @param labels the labels applied to the issue * @param milestone the milestone applied to the issue * @param pullRequest details of the pull request (if this issue is a pull request) + * @param state the state of the issue, open or closed */ @JsonCreator public Issue(@JsonProperty("url") String url, @@ -62,7 +65,8 @@ public Issue(@JsonProperty("url") String url, @JsonProperty("labels_url") String labelsUrl, @JsonProperty("user") User user, @JsonProperty("labels") List