Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Feb 15, 2024
2 parents f2f1e29 + 2efdd98 commit 74e5a70
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
21 changes: 14 additions & 7 deletions src/main/java/com/rultor/agents/github/CommentsTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public Iterable<Directive> process(final XML xml) throws IOException {
rels.create(tag.trim())
);
rel.name(CommentsTag.title(req, issue));
rel.prerelease(this.isPrerelease());
rel.prerelease(this.isPrerelease(req));
rel.body(
String.format(
// @checkstyle LineLength (1 line)
Expand All @@ -152,17 +152,24 @@ public Iterable<Directive> process(final XML xml) throws IOException {
/**
* Check if release is prerelease.
* True if profile does not specify release.pre=false.
* @param req Comment's xml
* @return True if prerelease, false otherwise.
*/
private boolean isPrerelease() {
private boolean isPrerelease(final XML req) {
try {
final boolean result;
final List<String> xpath = this.profile.read()
.xpath("/p/entry[@key='release']/entry[@key='pre']/text()");
if (xpath.isEmpty()) {
result = true;
final List<String> comment = req
.xpath("args/arg[@name='pre']/text()");
if (comment.isEmpty()) {
final List<String> xpath = this.profile.read()
.xpath("/p/entry[@key='release']/entry[@key='pre']/text()");
if (xpath.isEmpty()) {
result = true;
} else {
result = "true".equals(xpath.get(0).trim());
}
} else {
result = "true".equals(xpath.get(0).trim());
result = "true".equals(comment.get(0).trim());
}
return result;
} catch (final IOException exception) {
Expand Down
41 changes: 41 additions & 0 deletions src/test/java/com/rultor/agents/github/CommentsTagTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,47 @@ void createsReleaseTitleFromTalk() throws Exception {
*/
@Test
void createsLatestRelease() throws IOException {
final Repo repo = new MkGithub().randomRepo();
final Issue issue = repo.issues()
.create(
"Latest Release",
"This issue is created for latest release"
);
final Agent agent = new CommentsTag(
repo.github(),
new Profile.Fixed(
"<p>",
"<entry key='release'>",
"<entry key='pre'>",
"true",
"</entry></entry></p>"
)
);
final String tag = "v1.1.latest";
final Talk talk = CommentsTagTest.talk(issue, tag);
talk.modify(
new Directives().xpath("/talk/request/args")
.add("arg")
.attr("name", "pre")
.set("false")
);
agent.execute(talk);
MatcherAssert.assertThat(
"We expect latest release to be created (not pre)",
new Release.Smart(
new Releases.Smart(repo.releases()).find(tag)
).prerelease(),
Matchers.is(false)
);
}

/**
* CommentsTag can create latest release if profile specify 'pre: true',
* but 'pre: false' is written in the comment.
* @throws IOException In case of error.
*/
@Test
void createsLatestReleaseFromTalk() throws IOException {
final Repo repo = new MkGithub().randomRepo();
final Issue issue = repo.issues()
.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ void attachesBinaryToRelease(
dir.getAbsolutePath(), "repo", target, name.replace("${tag}", tag)
);
bin.mkdirs();
new SecureRandom();
final byte[] content = SecureRandom.getSeed(100);
new LengthOf(new TeeInput(content, bin)).value();
final Talk talk = ReleaseBinariesTest
Expand Down

0 comments on commit 74e5a70

Please sign in to comment.