diff --git a/src/main/java/com/rultor/agents/github/qtn/QnRelease.java b/src/main/java/com/rultor/agents/github/qtn/QnRelease.java index a87fb3db27..bbfcd439f1 100644 --- a/src/main/java/com/rultor/agents/github/qtn/QnRelease.java +++ b/src/main/java/com/rultor/agents/github/qtn/QnRelease.java @@ -60,8 +60,7 @@ public final class QnRelease implements Question { /** * Pattern matching the version tag of the release enclosed by backticks. */ - private static final Pattern QUESTION_PATTERN = - Pattern.compile("`(.+)`"); + private static final Pattern QUESTION_PATTERN = Pattern.compile("`(.+)`"); /** * Message bundle. @@ -84,25 +83,7 @@ public Req understand(final Comment.Smart comment, final String name = matcher.group(1); final ReleaseTag release = new ReleaseTag(issue.repo(), name); if (release.allowed()) { - new Answer(comment).post( - true, - String.format( - QnRelease.PHRASES.getString("QnRelease.start"), - home.toASCIIString() - ) - ); - req = new Req.Simple( - "release", - new ImmutableMap.Builder() - .put("head_branch", "master") - .put( - "head", - String.format( - "git@github.com:%s.git", - comment.issue().repo().coordinates() - ) - ).build() - ); + req = QnRelease.affirmative(comment, home); } else { new Answer(comment).post( false, @@ -115,13 +96,39 @@ public Req understand(final Comment.Smart comment, req = Req.EMPTY; } } else { - new Answer(comment).post( - false, - QnRelease.PHRASES.getString("QnRelease.missing-tag") - ); - req = Req.EMPTY; + req = QnRelease.affirmative(comment, home); } return req; } + /** + * Confirms that Rultor is starting the release process. + * @param comment Comment that triggered the release + * @param home URI of the release tail + * @return Req.Simple containing the release parameters + * @throws IOException on error + */ + private static Req affirmative(final Comment.Smart comment, + final URI home) throws IOException { + new Answer(comment).post( + true, + String.format( + QnRelease.PHRASES.getString("QnRelease.start"), + home.toASCIIString() + ) + ); + return new Req.Simple( + "release", + new ImmutableMap.Builder() + .put("head_branch", "master") + .put( + "head", + String.format( + "git@github.com:%s.git", + comment.issue().repo().coordinates() + ) + ).build() + ); + } + } diff --git a/src/main/resources/phrases_en_US.properties b/src/main/resources/phrases_en_US.properties index b51e5c1eca..2c6d51f6ed 100644 --- a/src/main/resources/phrases_en_US.properties +++ b/src/main/resources/phrases_en_US.properties @@ -36,9 +36,6 @@ QnMerge.base-is-gone=Base repository is gone, can't merge into it QnDeploy.start=OK, I'll try to deploy now. You can check the progress [here](%s) QnRelease.start=OK, I will release it now. Please check the progress [here](%s) -QnRelease.missing-tag=No release tag specified, please provide a release version.\n \ - More information on the release command can be found \ - [here](http://doc.rultor.com/basics.html). QnRelease.invalid-tag=Invalid release tag `%s` specified. There is already a \ release `%s` newer than the given release in this \ repository. diff --git a/src/test/java/com/rultor/agents/github/qtn/QnReleaseTest.java b/src/test/java/com/rultor/agents/github/qtn/QnReleaseTest.java index 66bb7687e2..c03b183913 100644 --- a/src/test/java/com/rultor/agents/github/qtn/QnReleaseTest.java +++ b/src/test/java/com/rultor/agents/github/qtn/QnReleaseTest.java @@ -61,7 +61,7 @@ public final class QnReleaseTest { public void buildsRequest() throws Exception { final Repo repo = new MkGithub().randomRepo(); final Issue issue = repo.issues().create("", ""); - issue.comments().post("release `1.7`"); + issue.comments().post("release"); MatcherAssert.assertThat( new Xembler( new Directives().add("request").append( @@ -80,36 +80,43 @@ public void buildsRequest() throws Exception { } /** - * QnRelease can deny release when tag is outdated. + * QnRelease can build a release request when the requested version is newer + * than the last release. * @throws Exception In case of error */ @Test - public void denyOutdatedTag() throws Exception { + public void allowsNewerTag() throws Exception { final Repo repo = new MkGithub().randomRepo(); final Issue issue = repo.issues().create("", ""); - repo.releases().create("1.7"); - issue.comments().post("release `1.6`"); - MatcherAssert.assertThat( - new QnRelease().understand( - new Comment.Smart(issue.comments().get(1)), new URI("#") - ), - Matchers.is(Req.EMPTY) - ); + repo.releases().create("1.5"); + issue.comments().post("release `1.7`"); MatcherAssert.assertThat( - new Comment.Smart(issue.comments().get(2)).body(), - Matchers.containsString("There is already a release `1.7`") + new Xembler( + new Directives().add("request").append( + new QnRelease().understand( + new Comment.Smart(issue.comments().get(1)), new URI("#") + ).dirs() + ) + ).xml(), + XhtmlMatchers.hasXPaths( + "/request[type='release']", + "/request/args[count(arg) = 2]", + "/request/args/arg[@name='head']", + "/request/args/arg[@name='head_branch']" + ) ); } /** - * QnRelease can deny release when tag name is not given. + * QnRelease can deny release when tag is outdated. * @throws Exception In case of error */ @Test - public void denyMissingTag() throws Exception { - final Issue issue = new MkGithub().randomRepo().issues() - .create("", ""); - issue.comments().post("release"); + public void denyOutdatedTag() throws Exception { + final Repo repo = new MkGithub().randomRepo(); + final Issue issue = repo.issues().create("", ""); + repo.releases().create("1.7"); + issue.comments().post("release `1.6`"); MatcherAssert.assertThat( new QnRelease().understand( new Comment.Smart(issue.comments().get(1)), new URI("#") @@ -118,7 +125,7 @@ public void denyMissingTag() throws Exception { ); MatcherAssert.assertThat( new Comment.Smart(issue.comments().get(2)).body(), - Matchers.containsString("No release tag specified") + Matchers.containsString("There is already a release `1.7`") ); }