Skip to content

Commit

Permalink
Merge pull request #1266 from amihaiemil/1265
Browse files Browse the repository at this point in the history
#1265 started refactoring of estimation update to use Steps
  • Loading branch information
amihaiemil committed Oct 30, 2021
2 parents 6c094af + 8546959 commit 3edc272
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.selfxdsd.core.managers;

import com.selfxdsd.api.Event;
import com.selfxdsd.api.Issue;
import com.selfxdsd.api.Project;
import com.selfxdsd.api.Task;
import com.selfxdsd.api.pm.PreconditionCheck;
import com.selfxdsd.api.pm.Step;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Step which checks if an Issue's estimation has been changed.
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 0.0.96
* @todo #1265:30min Write some unit tests for this class.
*/
public final class IssueEstimationChanged extends PreconditionCheck {

/**
* Logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(
IssueEstimationChanged.class
);

/**
* Ctor.
* @param onTrue Step that should be performed next if the check is true.
* @param onFalse Step that should be performed next if the check is false.
*/
public IssueEstimationChanged(final Step onTrue, final Step onFalse) {
super(onTrue, onFalse);
}

@Override
public void perform(final Event event) {
final Issue issue = event.issue();
final String issueId = issue.issueId();
final Project project = event.project();
final Task task = project.tasks().getById(
issueId,
project.repoFullName(),
project.provider(),
issue.isPullRequest()
);
final int oldEstimation = task.estimation();
final int newEstimation = issue.estimation().minutes();
if (oldEstimation != newEstimation) {
LOG.debug(String.format(
"The estimation of Issue [#%s-%s-%s] has changed from %s min. "
+ "to %s min.",
issue.issueId(),
issue.repoFullName(),
issue.provider(),
oldEstimation,
newEstimation
));
this.onTrue().perform(event);
} else {
LOG.debug(String.format(
"The estimation of Issue [#%s-%s-%s] was NOT changed.",
issue.issueId(),
issue.repoFullName(),
issue.provider()
));
this.onFalse().perform(event);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
* @checkstyle ClassFanOutComplexity (1000 lines)
* @checkstyle ClassDataAbstractionCoupling (1000 lines)
* @since 0.0.1
* @todo #1265:30min In method issueLabelsChanged, use the step IssueIsClosed
* before doing anything else. We shouldn't act on labeled/unlabeled if the
* Issue is closed.
* @todo #1265:30min Send a comment after updating a task's estimation inside
* issueLabelsChanged.
*/
public final class StoredProjectManager implements ProjectManager {

Expand Down Expand Up @@ -656,41 +661,20 @@ public void renamedProject(final Event event) {

@Override
public void issueLabelsChanged(final Event event) {
final Issue issue = event.issue();
final Task task = event.project()
.tasks()
.getById(
issue.issueId(),
issue.repoFullName(),
issue.provider(),
issue.isPullRequest()
);

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()
));
}
final Step steps = new TaskIsRegistered(
new IssueEstimationChanged(
new UpdateTaskEstimation(
sendReply -> LOG.debug("Send updated estimation comment.")
),
notChanged -> LOG.debug(
"Nothing to do on Issue label change."
)
),
isNotRegistered -> LOG.debug(
"Issue is NOT registered as a Task. Doing nothing."
)
);
steps.perform(event);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright (c) 2020-2021, Self XDSD Contributors
* All rights reserved.
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"),
* to read the Software only. Permission is hereby NOT GRANTED to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software.
* <p>
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.selfxdsd.core.managers;

import com.selfxdsd.api.Event;
import com.selfxdsd.api.pm.Intermediary;
import com.selfxdsd.api.pm.Step;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Step which updates a Task's estimation.
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 0.0.96
* @todo #1265:60min Implement and test the method perform from this class.
* It should simply update a task's estimation and forward to the next step.
*/
public final class UpdateTaskEstimation extends Intermediary {

/**
* Logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(
UpdateTaskEstimation.class
);

/**
* Ctor.
* @param next The next step to perform.
*/
public UpdateTaskEstimation(final Step next) {
super(next);
}

@Override
public void perform(final Event event) {
throw new UnsupportedOperationException("Not yet implemented.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.selfxdsd.core.projects.English;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;

Expand Down Expand Up @@ -1828,8 +1829,11 @@ public void unableToRegisterToken() {

/**
* A PM can update a task estimation if issue estimation has changed.
* @todo #1265:60min Unignore/update this test once the whole functionality
* is refactored to use Steps.
*/
@Test
@Ignore
public void handlesIssueLabelsChangesOfEstimation() {
final ProjectManager manager = new StoredProjectManager(
1,
Expand Down

0 comments on commit 3edc272

Please sign in to comment.