Skip to content

Commit

Permalink
yegor256#960 removed handling of no tag given in release command from…
Browse files Browse the repository at this point in the history
… this PR, this is not in the scope of the issue.
  • Loading branch information
original-brownbear committed Mar 2, 2016
1 parent fb18b8b commit e7b8a16
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 48 deletions.
59 changes: 33 additions & 26 deletions src/main/java/com/rultor/agents/github/qtn/QnRelease.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<String, String>()
.put("head_branch", "master")
.put(
"head",
String.format(
"[email protected]:%s.git",
comment.issue().repo().coordinates()
)
).build()
);
req = QnRelease.affirmative(comment, home);
} else {
new Answer(comment).post(
false,
Expand All @@ -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<String, String>()
.put("head_branch", "master")
.put(
"head",
String.format(
"[email protected]:%s.git",
comment.issue().repo().coordinates()
)
).build()
);
}

}
3 changes: 0 additions & 3 deletions src/main/resources/phrases_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
45 changes: 26 additions & 19 deletions src/test/java/com/rultor/agents/github/qtn/QnReleaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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("#")
Expand All @@ -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`")
);
}

Expand Down

0 comments on commit e7b8a16

Please sign in to comment.