Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed May 16, 2023
2 parents ae1d5d4 + 0ca319d commit 2d13ab4
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 9 deletions.
26 changes: 25 additions & 1 deletion src/main/java/com/rultor/agents/github/CommentsTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.io.IOException;
import java.net.URI;
import java.util.Date;
import java.util.Optional;
import java.util.ResourceBundle;
import lombok.EqualsAndHashCode;
import lombok.ToString;
Expand Down Expand Up @@ -115,7 +116,7 @@ public Iterable<Directive> process(final XML xml) throws IOException {
final Release.Smart rel = new Release.Smart(
rels.create(tag.trim())
);
rel.name(issue.title());
rel.name(CommentsTag.title(req, issue));
rel.prerelease(true);
rel.body(
String.format(
Expand All @@ -131,6 +132,29 @@ public Iterable<Directive> process(final XML xml) throws IOException {
return new Directives();
}

/**
* Get title.
* @param request Request to get title from
* @param issue Issue to get title from as fallback
* @return Title
* @throws IOException In case of problem communicating with repo.
*/
private static String title(
final XML request,
final Issue.Smart issue
) throws IOException {
final Optional<String> title = request.xpath(
"args/arg[@name='title']/text()"
).stream().findFirst();
final String res;
if (title.isPresent()) {
res = title.get();
} else {
res = issue.title();
}
return res;
}

/**
* Get previous release time.
* @param repo Repo in which to find the releases.
Expand Down
58 changes: 53 additions & 5 deletions src/test/java/com/rultor/agents/github/CommentsTagTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ public void createsReleaseMessage() throws Exception {
final String tag = "v1.5";
final Talk talk = CommentsTagTest.talk(issue, tag);
agent.execute(talk);
final Release.Smart smart = new Release.Smart(
new Releases.Smart(repo.releases()).find(tag)
);
final String body = smart.body();
MatcherAssert.assertThat(
new Release.Smart(
new Releases.Smart(repo.releases()).find(tag)
).body(),
body,
Matchers.allOf(
Matchers.containsString("Released by Rultor"),
Matchers.containsString(
Expand All @@ -117,6 +119,52 @@ public void createsReleaseMessage() throws Exception {
);
}

/**
* CommentsTag can create a proper release title.
* @throws Exception In case of error.
*/
@Test
public void createsReleaseTitleFromIssue() throws Exception {
final Repo repo = new MkGithub().randomRepo();
final Issue issue = repo.issues().create("Issue title", "");
final Agent agent = new CommentsTag(repo.github());
final String tag = "v1.6";
agent.execute(CommentsTagTest.talk(issue, tag));
MatcherAssert.assertThat(
new Release.Smart(
new Releases.Smart(repo.releases()).find(tag)
).name(),
Matchers.equalTo("Issue title")
);
}

/**
* CommentsTag can create a proper release title.
* @throws Exception In case of error.
*/
@Test
public void createsReleaseTitleFromTalk() throws Exception {
final Repo repo = new MkGithub().randomRepo();
final Issue issue = repo.issues().create("Title from issue", "");
final Agent agent = new CommentsTag(repo.github());
final String tag = "v1.7";
final Talk talk = CommentsTagTest.talk(issue, tag);
final String title = "Custom Title";
talk.modify(
new Directives().xpath("/talk/request/args")
.add("arg")
.attr("name", "title")
.set(title)
);
agent.execute(talk);
MatcherAssert.assertThat(
new Release.Smart(
new Releases.Smart(repo.releases()).find(tag)
).name(),
Matchers.equalTo(title)
);
}

/**
* Make a talk with this tag.
* @param issue The issue
Expand All @@ -140,9 +188,9 @@ private static Talk talk(final Issue issue, final String tag)
.add("author").set("yegor256").up()
.add("type").set("release").up()
.add("success").set("true").up()
.add("args").add("arg").attr("name", "tag").set(tag)
.add("args")
.add("arg").attr("name", "tag").set(tag).up()
);
return talk;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public final class QnParametrizedTest {
public void fetchesParams() throws Exception {
final Repo repo = new MkGithub().randomRepo();
final Issue issue = repo.issues().create("", "");
issue.comments().post("hey, tag=`1.9` and server is `p5`");
issue.comments().post(
"hey, tag=`1.9` and server is `p5`, title is `Version 1.9.0`"
);
final Question origin = new Question() {
@Override
public Req understand(final Comment.Smart comment, final URI home) {
Expand All @@ -87,9 +89,10 @@ public Iterable<Directive> dirs() {
).xml(),
XhtmlMatchers.hasXPaths(
"/request[type='xxx']",
"/request/args[count(arg) = 3]",
"/request/args[count(arg) = 4]",
"/request/args/arg[@name='tag' and .='1.9']",
"/request/args/arg[@name='server' and .='p5']"
"/request/args/arg[@name='server' and .='p5']",
"/request/args/arg[@name='title' and .='Version 1.9.0']"
)
);
}
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/com/rultor/agents/github/qtn/QnReleaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,30 @@ public void denyOutdatedTag() throws Exception {
);
}

/**
* QnRelease can accept release title.
* @throws Exception In case of error
*/
@Test
public void allowsToSetReleaseTitle() throws Exception {
final Repo repo = new MkGithub().randomRepo();
final Issue issue = repo.issues().create("", "");
issue.comments().post("release `1.8`, title `Version 1.8.0`");
MatcherAssert.assertThat(
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']"
)
);
}

}

0 comments on commit 2d13ab4

Please sign in to comment.