Skip to content

Commit

Permalink
#1245 StoredProjectManager#issueLabelsChanged check if task exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
criske committed Oct 15, 2021
1 parent 8135326 commit c0ad62e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -664,19 +664,29 @@ public void issueLabelsChanged(final Event event) {
issue.isPullRequest()
);

final int newEstimation = issue.estimation().minutes();
final int oldEstimation = task.estimation();

if(oldEstimation != newEstimation){
task.updateEstimation(newEstimation);
LOG.debug(String.format(
"Task [#%s-%s-%s] updated its estimation from %s min. "
+ "to %s min.",
if(task != null) {
final int newEstimation = issue.estimation().minutes();
final int oldEstimation = task.estimation();

if (oldEstimation != newEstimation) {
task.updateEstimation(newEstimation);
LOG.debug(String.format(
"Task [#%s-%s-%s] updated its estimation from %s min. "
+ "to %s min.",
issue.issueId(),
issue.repoFullName(),
issue.provider(),
oldEstimation,
newEstimation
));
}
} else {
LOG.error(String.format(
"Issue [#%s-%s-%s] is not registered yet as a task. "
+ "Skipping handling issue labels changes...",
issue.issueId(),
issue.repoFullName(),
issue.provider(),
oldEstimation,
newEstimation
issue.provider()
));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1869,4 +1869,48 @@ public void handlesIssueLabelsChangesOfEstimation() {
Mockito.verify(task, Mockito.times(1)).updateEstimation(30);
}

/**
* A PM can skip handling issue labels changes if task associated with issue
* is not found.
*/
@Test
public void skipHandlingIssueLabelsChanges() {
final ProjectManager manager = new StoredProjectManager(
1,
"123",
"zoeself",
Provider.Names.GITHUB,
"123token",
8,
5,
Mockito.mock(Storage.class)
);
final Event event = Mockito.mock(Event.class);
final Issue issue = Mockito.mock(Issue.class);
final Project project = Mockito.mock(Project.class);
final Tasks tasks = Mockito.mock(Tasks.class);
final Task task = Mockito.mock(Task.class);

Mockito.when(event.issue()).thenReturn(issue);
Mockito.when(event.project()).thenReturn(project);
Mockito.when(project.tasks()).thenReturn(tasks);

Mockito.when(issue.issueId()).thenReturn("123");
Mockito.when(issue.provider()).thenReturn(Provider.Names.GITHUB);
Mockito.when(issue.repoFullName()).thenReturn("john/test");
Mockito.when(issue.estimation()).thenReturn(() -> 30);

Mockito.when(tasks.getById(
"not-this-issue-123",
"john/test",
Provider.Names.GITHUB,
false
)).thenReturn(task);

manager.issueLabelsChanged(event);

Mockito.verify(task, Mockito.never())
.updateEstimation(Mockito.anyInt());
}

}

0 comments on commit c0ad62e

Please sign in to comment.