Skip to content

Commit

Permalink
#585 adapt reopenedIssue event method for PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Oct 10, 2020
1 parent 25fb639 commit 1667395
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,19 @@ public void reopenedIssue(final Event event) {
);
if(task == null) {
project.tasks().register(issue);
issue.comments().post(
String.format(
final String reply;
if(issue.isPullRequest()) {
reply = String.format(
project.language().reply("reopenedPullRequest.comment"),
issue.author()
);
} else {
reply = String.format(
project.language().reply("reopened.comment"),
issue.author()
)
);
);
}
issue.comments().post(reply);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 0.0.1
* @checkstyle ExecutableStatementCount (1000 lines)
* @checkstyle ExecutableStatementCount (1500 lines)
*/
public final class StoredProjectManagerTestCase {

Expand Down Expand Up @@ -320,6 +320,7 @@ public void handlesTaskFinishedReopenedIssueEvent() {
Mockito.mock(Storage.class)
);
final Issue issue = Mockito.mock(Issue.class);
Mockito.when(issue.isPullRequest()).thenReturn(Boolean.FALSE);
Mockito.when(issue.issueId()).thenReturn("1");
Mockito.when(issue.author()).thenReturn("mihai");
Mockito.when(issue.repoFullName()).thenReturn("mihai/test");
Expand All @@ -339,7 +340,7 @@ public void handlesTaskFinishedReopenedIssueEvent() {
new Event() {
@Override
public String type() {
return "reopened";
return Type.REOPENED_ISSUE;
}

@Override
Expand All @@ -364,13 +365,79 @@ public Project project() {
Mockito.verify(comments, Mockito.times(1))
.post(
"@mihai thanks for reopening this, "
+ "I'll find someone to take a look at it again. \n"
+ "I'll find someone to take a look at it. \n"
+ "However, please keep in mind that reopening tickets "
+ "is a bad practice. "
+ "Next time, please open a new ticket."
);
}

/**
* StoredProjectManager can handle a reopened PR event when the initial
* Task associated with it has been finished (in this case we
* register a new task and leave a comment).
*/
@Test
public void handlesTaskFinishedReopenedPullRequestEvent() {
final ProjectManager manager = new StoredProjectManager(
1,
"123",
"zoeself",
Provider.Names.GITHUB,
"123token",
BigDecimal.valueOf(50),
Mockito.mock(Storage.class)
);
final Issue issue = Mockito.mock(Issue.class);
Mockito.when(issue.isPullRequest()).thenReturn(Boolean.TRUE);
Mockito.when(issue.issueId()).thenReturn("1");
Mockito.when(issue.author()).thenReturn("mihai");
Mockito.when(issue.repoFullName()).thenReturn("mihai/test");
Mockito.when(issue.provider()).thenReturn("github");
final Comments comments = Mockito.mock(Comments.class);
Mockito.when(comments.post(Mockito.anyString())).thenReturn(null);
Mockito.when(issue.comments()).thenReturn(comments);

final Project project = Mockito.mock(Project.class);
final Tasks tasks = Mockito.mock(Tasks.class);
Mockito.when(
tasks.getById("1", "mihai/test", "github")
).thenReturn(null);
Mockito.when(project.tasks()).thenReturn(tasks);
Mockito.when(project.language()).thenReturn(new English());
manager.reopenedIssue(
new Event() {
@Override
public String type() {
return Type.REOPENED_ISSUE;
}

@Override
public Issue issue() {
return issue;
}

@Override
public Comment comment() {
return null;
}

@Override
public Project project() {
return project;
}

}
);
Mockito.verify(tasks, Mockito.times(1))
.register(issue);
Mockito.verify(comments, Mockito.times(1))
.post(
"@mihai thanks for reopening this PR, "
+ "I'll find someone to review it soon."
);
}

/**
* StoredProjectManager can handle a reopened Issue event when the current
* Task is still ongoing (doesn't do anything, actually).
Expand Down
3 changes: 2 additions & 1 deletion self-core-impl/src/test/resources/responses_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ hello.comment=Hi @%s! I'm the Project Manager of this project. I take care of Is
I work primarily at Github, but I'll also start working at GitLab and BitBucket soon.
newIssue.comment=@%s thank you for reporting this. I'll assign someone to take care of it soon.
newPullRequest.comment=@%s thank you for your Pull Request. I'll assign someone to review it soon.
reopened.comment=@%s thanks for reopening this, I'll find someone to take a look at it again. \n\
reopened.comment=@%s thanks for reopening this, I'll find someone to take a look at it. \n\
However, please keep in mind that reopening tickets is a bad practice. Next time, please \
open a new ticket.
reopenedPullRequest.comment=@%s thanks for reopening this PR, I'll find someone to review it soon.
noAssigneeFound.comment=@%s I couldn't find any assignee for this task. This is either because there are \
no contributors with role ``%s`` available or because the project does not have enough funds.\n\n\
Please, make sure there is at least one available contributor with the required role and \
Expand Down

0 comments on commit 1667395

Please sign in to comment.