-
Notifications
You must be signed in to change notification settings - Fork 156
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
if (comment.body().contains("stop")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xupyprmv there is already code related to stopping in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mkordas There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xupyprmv can we state which command it was (release, merge, deploy)? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -47,6 +49,16 @@ | |
* @since 1.3 | ||
*/ | ||
public final class ReportsTest { | ||
/** | ||
* Message bundle. | ||
*/ | ||
private static final ResourceBundle PHRASES = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"
); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mkordas fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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. | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xupyprmv inline this one as well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mkordas done There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xupyprmv where in this test we simulate failure? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mkordas In line:
I added comment with There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xupyprmv please inline this variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mkordas done There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xupyprmv can we make full assertion here about entire string? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mkordas I think current variant is better then variant with full check:
Or not? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
"" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xupyprmv why do we repace There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mkordas fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mkordas fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xupyprmv please move indentation back 4 characters There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mkordas fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
@@ -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; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
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
, somessage
would mean the sameThere was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xupyprmv thank you