From f1760bef4e97ec202d144565a211509ee0f12ab0 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 19 Jun 2017 22:22:08 +0100 Subject: [PATCH] Label an issue for triage even if a collaborator has commented on it --- config/checkstyle/checkstyle-header.txt | 2 +- .../CommentedByCollaboratorTriageFilter.java | 69 -------------- .../issuebot/triage/TriageConfiguration.java | 7 +- ...mentedByCollaboratorTriageFilterTests.java | 93 ------------------- 4 files changed, 3 insertions(+), 168 deletions(-) delete mode 100644 src/main/java/io/spring/issuebot/triage/CommentedByCollaboratorTriageFilter.java delete mode 100644 src/test/java/io/spring/issuebot/triage/CommentedByCollaboratorTriageFilterTests.java diff --git a/config/checkstyle/checkstyle-header.txt b/config/checkstyle/checkstyle-header.txt index 82be24b..0d44e7c 100644 --- a/config/checkstyle/checkstyle-header.txt +++ b/config/checkstyle/checkstyle-header.txt @@ -1,5 +1,5 @@ ^\Q/*\E$ -^\Q * Copyright \E2015\Q the original author or authors.\E$ +^\Q * Copyright \E2015(-20\d\d)?\Q the original author or authors.\E$ ^\Q *\E$ ^\Q * Licensed under the Apache License, Version 2.0 (the "License");\E$ ^\Q * you may not use this file except in compliance with the License.\E$ diff --git a/src/main/java/io/spring/issuebot/triage/CommentedByCollaboratorTriageFilter.java b/src/main/java/io/spring/issuebot/triage/CommentedByCollaboratorTriageFilter.java deleted file mode 100644 index 7fdaf8b..0000000 --- a/src/main/java/io/spring/issuebot/triage/CommentedByCollaboratorTriageFilter.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.issuebot.triage; - -import java.util.Collections; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import io.spring.issuebot.github.Comment; -import io.spring.issuebot.github.GitHubOperations; -import io.spring.issuebot.github.Issue; -import io.spring.issuebot.github.Page; - -/** - * A {@code TriageFilter} that considers an issue as having been triaged if a collaborator - * has commented on it. - * - * @author Andy Wilkinson - */ -final class CommentedByCollaboratorTriageFilter implements TriageFilter { - - private static final Logger log = LoggerFactory - .getLogger(CommentedByCollaboratorTriageFilter.class); - - private final List collaborators; - - private final GitHubOperations gitHub; - - CommentedByCollaboratorTriageFilter(List collaborators, - GitHubOperations gitHub) { - this.collaborators = collaborators == null ? Collections.emptyList() - : collaborators; - this.gitHub = gitHub; - } - - @Override - public boolean triaged(Issue issue) { - Page page = this.gitHub.getComments(issue); - while (page != null) { - for (Comment comment : page.getContent()) { - if (this.collaborators.contains(comment.getUser().getLogin())) { - log.debug("{} has been triaged. It was commented on by {}", issue, - comment.getUser()); - return true; - } - } - page = page.next(); - } - - return false; - } - -} diff --git a/src/main/java/io/spring/issuebot/triage/TriageConfiguration.java b/src/main/java/io/spring/issuebot/triage/TriageConfiguration.java index 8100f4c..ec92263 100644 --- a/src/main/java/io/spring/issuebot/triage/TriageConfiguration.java +++ b/src/main/java/io/spring/issuebot/triage/TriageConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,10 +41,7 @@ class TriageConfiguration { Arrays.asList( new OpenedByCollaboratorTriageFilter( gitHubProperties.getRepository().getCollaborators()), - new LabelledTriageFilter(), new MilestoneAppliedTriageFilter(), - new CommentedByCollaboratorTriageFilter( - gitHubProperties.getRepository().getCollaborators(), - gitHubOperations)), + new LabelledTriageFilter(), new MilestoneAppliedTriageFilter()), new LabelApplyingTriageListener(gitHubOperations, triageProperties.getLabel())); } diff --git a/src/test/java/io/spring/issuebot/triage/CommentedByCollaboratorTriageFilterTests.java b/src/test/java/io/spring/issuebot/triage/CommentedByCollaboratorTriageFilterTests.java deleted file mode 100644 index 42f5ee3..0000000 --- a/src/test/java/io/spring/issuebot/triage/CommentedByCollaboratorTriageFilterTests.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.spring.issuebot.triage; - -import java.util.Arrays; -import java.util.Collections; - -import org.junit.Test; - -import io.spring.issuebot.github.Comment; -import io.spring.issuebot.github.GitHubOperations; -import io.spring.issuebot.github.Issue; -import io.spring.issuebot.github.Page; -import io.spring.issuebot.github.User; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link CommentedByCollaboratorTriageFilter}. - * - * @author Andy Wilkinson - * - */ -public class CommentedByCollaboratorTriageFilterTests { - - private final GitHubOperations gitHub = mock(GitHubOperations.class); - - private final TriageFilter filter = new CommentedByCollaboratorTriageFilter( - Arrays.asList("Adam", "Brenda", "Charlie"), this.gitHub); - - private final Issue issue = new Issue(null, null, null, null, null, null, null, null); - - @Test - @SuppressWarnings("unchecked") - public void noComments() { - Page pageOne = mock(Page.class); - given(pageOne.getContent()).willReturn(Collections.emptyList()); - given(this.gitHub.getComments(this.issue)).willReturn(pageOne); - assertThat(this.filter.triaged(this.issue), is(false)); - } - - @Test - @SuppressWarnings("unchecked") - public void noCommentsByCollaborators() { - Page pageOne = mock(Page.class); - given(pageOne.getContent()) - .willReturn(Arrays.asList(new Comment(new User("Debbie"), null))); - given(this.gitHub.getComments(this.issue)).willReturn(pageOne); - assertThat(this.filter.triaged(this.issue), is(false)); - } - - @Test - @SuppressWarnings("unchecked") - public void commentByCollaboratorOnFirstPage() { - Page pageOne = mock(Page.class); - given(pageOne.getContent()) - .willReturn(Arrays.asList(new Comment(new User("Brenda"), null))); - given(this.gitHub.getComments(this.issue)).willReturn(pageOne); - assertThat(this.filter.triaged(this.issue), is(true)); - } - - @Test - @SuppressWarnings("unchecked") - public void commentByCollaboratorOnLaterPage() { - Page pageOne = mock(Page.class); - given(pageOne.getContent()) - .willReturn(Arrays.asList(new Comment(new User("Debbie"), null))); - Page pageTwo = mock(Page.class); - given(pageTwo.getContent()) - .willReturn(Arrays.asList(new Comment(new User("Brenda"), null))); - given(pageOne.next()).willReturn(pageTwo); - given(this.gitHub.getComments(this.issue)).willReturn(pageOne); - assertThat(this.filter.triaged(this.issue), is(true)); - } - -}