Label an issue for triage even if a collaborator has commented on it

This commit is contained in:
Andy Wilkinson
2017-06-19 22:22:08 +01:00
parent 6635419080
commit f1760bef4e
4 changed files with 3 additions and 168 deletions

View File

@@ -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$

View File

@@ -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<String> collaborators;
private final GitHubOperations gitHub;
CommentedByCollaboratorTriageFilter(List<String> collaborators,
GitHubOperations gitHub) {
this.collaborators = collaborators == null ? Collections.emptyList()
: collaborators;
this.gitHub = gitHub;
}
@Override
public boolean triaged(Issue issue) {
Page<Comment> 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;
}
}

View File

@@ -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()));
}

View File

@@ -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<Comment> 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<Comment> 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<Comment> 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<Comment> pageOne = mock(Page.class);
given(pageOne.getContent())
.willReturn(Arrays.asList(new Comment(new User("Debbie"), null)));
Page<Comment> 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));
}
}