Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#864 Correctly handle situation when report is created for stopped command. #1046

Merged
merged 5 commits into from
Mar 10, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/main/java/com/rultor/agents/github/Reports.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,17 @@ public Iterable<Directive> process(final XML xml) throws IOException {
msg.append(Reports.tail(req));
}
final int number = Integer.parseInt(req.xpath("@id").get(0));
new Answer(Reports.origin(issue, number)).post(success, msg.toString());
final Comment.Smart comment = Reports.origin(issue, number);
final String message;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv we already have variable msg, so message would mean the same

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkordas I refactored code according to this remark

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv thank you

if (comment.body().contains("stop")) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv there is already code related to stopping in QnStop.java, why do we need this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkordas QnStop is used to create response like OK, I'll try to stop current task. But In current issue we deal with case when we return report, not answer on stop command.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv all right, makes sense

message = String.format(
Reports.PHRASES.getString("Reports.stop-fails"),
msg.toString()
);
} else {
message = msg.toString();
}
new Answer(comment).post(success, message);
Logger.info(this, "issue #%d reported: %B", issue.number(), success);
return new Directives()
.xpath("/talk/request[success]")
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/phrases_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ QnVersion.intro=My current version is %s, \

Reports.success=Done! FYI, the full log is [here](%s) (took me %[ms]s)
Reports.failure=Oops, I failed. You can see the full log [here](%s) (spent %[ms]s)
Reports.stop-fails=Sorry, I failed to stop the previous command, however it has next result: %s
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv can we state which command it was (release, merge, deploy)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkordas We have only information that command ends with success/failure. And from last comment we cannot determine command (because it was stop command).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv can't we get more information (just asking, maybe we really can't)


CommentsTag.duplicate=Release `%s` already exists! I can't duplicate it, \
but I posted a comment there. In the future, try to avoid duplicate releases
Expand Down
66 changes: 58 additions & 8 deletions src/test/java/com/rultor/agents/github/ReportsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import com.jcabi.matchers.XhtmlMatchers;
import com.rultor.spi.Agent;
import com.rultor.spi.Talk;
import java.io.IOException;
import java.util.ResourceBundle;
import org.hamcrest.MatcherAssert;
import org.junit.Test;
import org.xembly.Directives;
Expand All @@ -47,6 +49,16 @@
* @since 1.3
*/
public final class ReportsTest {
/**
* Message bundle.
*/
private static final ResourceBundle PHRASES =
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv we usually indent code like that:

    private static final ResourceBundle PHRASES = ResourceBundle.getBundle(
        "phrases"
    );

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkordas fixed

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv 👍

ResourceBundle.getBundle("phrases");

/**
* Xpath to check that talk was executed correctly.
*/
private static final String XPATH = "/talk[not(request)]";

/**
* Reports can report a result of a request.
Expand All @@ -56,9 +68,52 @@ public final class ReportsTest {
public void reportsRequestResult() throws Exception {
final Repo repo = new MkGithub().randomRepo();
final Issue issue = repo.issues().create("", "");
final Talk talk = ReportsTest.example(repo, issue);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv inline this one as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkordas done

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv thanks!

final Agent agent = new Reports(repo.github());
agent.execute(talk);
MatcherAssert.assertThat(
talk.read(),
XhtmlMatchers.hasXPath(XPATH)
);
}

/**
* Reports can report a result of a request, when stop command fails.
* @throws Exception In case of error.
*/
@Test
public void reportsRequestResultWhenStopFails() throws Exception {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv where in this test we simulate failure?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkordas In line:

final Issue issue = repo.issues().create("Bug", "stop it please");

I added comment with stop command. So Reports creates report on command that was tried to stop.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv now I see, thanks

final Repo repo = new MkGithub().randomRepo();
final Issue issue = repo.issues().create("Bug", "stop it please");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv please inline this variable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkordas done

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv looks ok now

final Talk talk = ReportsTest.example(repo, issue);
final Agent agent = new Reports(repo.github());
final Talk talk = new Talk.InFile();
talk.modify(
agent.execute(talk);
MatcherAssert.assertThat(
talk.read(),
XhtmlMatchers.hasXPath(XPATH)
);
MatcherAssert.assertThat(
"Comment contains warning about stop request",
repo.issues().get(1).comments().get(1).toString().contains(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv can we make full assertion here about entire string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkordas I think current variant is better then variant with full check:

 MatcherAssert.assertThat(
            "Comment contains warning about stop request",
            repo.issues().get(1).comments().get(1).toString().equals(
                String.format(
                    "%s %s",
                    ReportsTest.PHRASES.getString("Reports.stop-fails"),
                    Logger.format(
                        ReportsTest.PHRASES.getString("Reports.success"),
                        "http://www.rultor.com/t/1-1",
                        1260000L
                    )
                )
            )
        );

Or not?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv I see the benefit of full check - more clarity what would be the result for the end user

ReportsTest.PHRASES.getString("Reports.stop-fails").replace(
"%s",
""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv why do we repace %s with empty string here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkordas fixed

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv nice

)
)
);
}

/**
* Create Talk, that will be used to test Reports.
* @param repo Repository
* @param issue Issue
* @return Example of Talk
* @throws IOException In case of error.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv dot at the end of this line is not needed, it will be soon prohibited by Qulice

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkordas fixed

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv thank you, looks better

*/
private static Talk example(final Repo repo, final Issue issue)
throws IOException {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv please move indentation back 4 characters

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkordas fixed

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xupyprmv looks good

final Talk result = new Talk.InFile();
result.modify(
new Directives().xpath("/talk").add("wire")
.add("href").set("http://test").up()
.add("github-repo").set(repo.coordinates().toString()).up()
Expand All @@ -70,11 +125,6 @@ public void reportsRequestResult() throws Exception {
.add("type").set("something").up()
.add("args")
);
agent.execute(talk);
MatcherAssert.assertThat(
talk.read(),
XhtmlMatchers.hasXPath("/talk[not(request)]")
);
return result;
}

}