From bfd0941e6aea0c5fd9d65176581f41b56d8ad9cd Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 14 Dec 2015 12:31:42 +0000 Subject: [PATCH] Ensure that the feedback reminder comment is only posted once --- .../feedback/FeedbackConfiguration.java | 1 + .../issuebot/feedback/FeedbackProperties.java | 5 ++++ .../feedback/StandardFeedbackListener.java | 22 +++++++++++++-- src/main/resources/application.yml | 1 + .../StandardFeedbackListenerTests.java | 28 ++++++++++++++----- 5 files changed, 48 insertions(+), 9 deletions(-) diff --git a/src/main/java/io/spring/issuebot/feedback/FeedbackConfiguration.java b/src/main/java/io/spring/issuebot/feedback/FeedbackConfiguration.java index e3a3689..fc93bf4 100644 --- a/src/main/java/io/spring/issuebot/feedback/FeedbackConfiguration.java +++ b/src/main/java/io/spring/issuebot/feedback/FeedbackConfiguration.java @@ -42,6 +42,7 @@ class FeedbackConfiguration { new StandardFeedbackListener(gitHub, feedbackProperties.getProvidedLabel(), feedbackProperties.getRequiredLabel(), + feedbackProperties.getReminderLabel(), feedbackProperties.getReminderComment(), feedbackProperties.getCloseComment())); } diff --git a/src/main/java/io/spring/issuebot/feedback/FeedbackProperties.java b/src/main/java/io/spring/issuebot/feedback/FeedbackProperties.java index b941f23..ad65f6d 100644 --- a/src/main/java/io/spring/issuebot/feedback/FeedbackProperties.java +++ b/src/main/java/io/spring/issuebot/feedback/FeedbackProperties.java @@ -42,6 +42,11 @@ final class FeedbackProperties { */ private String providedLabel; + /** + * Name of the label that is applied when the feedback reminder comment has been made. + */ + private String reminderLabel; + /** * The text of the comment that is added as a reminder that feedback is required. */ diff --git a/src/main/java/io/spring/issuebot/feedback/StandardFeedbackListener.java b/src/main/java/io/spring/issuebot/feedback/StandardFeedbackListener.java index a4633f8..6f09d6a 100644 --- a/src/main/java/io/spring/issuebot/feedback/StandardFeedbackListener.java +++ b/src/main/java/io/spring/issuebot/feedback/StandardFeedbackListener.java @@ -20,6 +20,7 @@ import java.time.OffsetDateTime; import io.spring.issuebot.github.GitHubOperations; import io.spring.issuebot.github.Issue; +import io.spring.issuebot.github.Label; /** * Standard implementation of {@link FeedbackListener}. @@ -34,15 +35,19 @@ final class StandardFeedbackListener implements FeedbackListener { private final String requiredLabel; + private final String reminderLabel; + private final String reminderComment; private final String closeComment; StandardFeedbackListener(GitHubOperations gitHub, String providedLabel, - String requiredLabel, String reminderComment, String closeComment) { + String requiredLabel, String reminderLabel, String reminderComment, + String closeComment) { this.gitHub = gitHub; this.providedLabel = providedLabel; this.requiredLabel = requiredLabel; + this.reminderLabel = reminderLabel; this.reminderComment = reminderComment; this.closeComment = closeComment; } @@ -59,7 +64,7 @@ final class StandardFeedbackListener implements FeedbackListener { if (requestTime.plusDays(14).isBefore(now)) { close(issue); } - else if (requestTime.plusDays(7).isBefore(now)) { + else if (requestTime.plusDays(7).isBefore(now) && reminderRequired(issue)) { remind(issue); } } @@ -68,10 +73,23 @@ final class StandardFeedbackListener implements FeedbackListener { this.gitHub.addComment(issue, this.closeComment); this.gitHub.close(issue); this.gitHub.removeLabel(issue, this.requiredLabel); + this.gitHub.removeLabel(issue, this.reminderLabel); + } + + private boolean reminderRequired(Issue issue) { + if (issue.getLabels() != null) { + for (Label label : issue.getLabels()) { + if (this.reminderLabel.equals(label.getName())) { + return false; + } + } + } + return true; } private void remind(Issue issue) { this.gitHub.addComment(issue, this.reminderComment); + this.gitHub.addLabel(issue, this.reminderLabel); } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index d8765ee..6b53bbd 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -13,6 +13,7 @@ issuebot: feedback: required_label: waiting-for-feedback provided_label: feedback-provided + reminder_label: 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/feedback/StandardFeedbackListenerTests.java b/src/test/java/io/spring/issuebot/feedback/StandardFeedbackListenerTests.java index f97135e..d2251ce 100644 --- a/src/test/java/io/spring/issuebot/feedback/StandardFeedbackListenerTests.java +++ b/src/test/java/io/spring/issuebot/feedback/StandardFeedbackListenerTests.java @@ -17,11 +17,14 @@ package io.spring.issuebot.feedback; import java.time.OffsetDateTime; +import java.util.Arrays; +import java.util.Collections; import org.junit.Test; import io.spring.issuebot.github.GitHubOperations; import io.spring.issuebot.github.Issue; +import io.spring.issuebot.github.Label; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -37,15 +40,17 @@ public class StandardFeedbackListenerTests { private final GitHubOperations gitHub = mock(GitHubOperations.class); private final FeedbackListener listener = new StandardFeedbackListener(this.gitHub, - "provided", "required", "reminder", "closing"); + "feedback-provided", "feedback-required", "feedback-reminder", + "Please provide requested feedback", "Closing due to lack of feedback"); - private final Issue issue = new Issue(null, null, null, null, null, null, null, null); + private final Issue issue = new Issue(null, null, null, null, null, + Collections.