From 2efdd98679aa8bebf8d3cca840d2ed75522fbd9f Mon Sep 17 00:00:00 2001 From: Natalia Pozhidaeva Date: Wed, 14 Feb 2024 22:56:29 -0500 Subject: [PATCH] [#1701] Get pre value from the comment (if presented) --- .../com/rultor/agents/github/CommentsTag.java | 21 ++++++---- .../rultor/agents/github/CommentsTagTest.java | 41 +++++++++++++++++++ .../agents/github/ReleaseBinariesTest.java | 1 - 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/rultor/agents/github/CommentsTag.java b/src/main/java/com/rultor/agents/github/CommentsTag.java index 55fae6fbfa..8baa52c6b5 100644 --- a/src/main/java/com/rultor/agents/github/CommentsTag.java +++ b/src/main/java/com/rultor/agents/github/CommentsTag.java @@ -135,7 +135,7 @@ public Iterable 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) @@ -153,17 +153,24 @@ public Iterable 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 xpath = this.profile.read() - .xpath("/p/entry[@key='release']/entry[@key='pre']/text()"); - if (xpath.isEmpty()) { - result = true; + final List comment = req + .xpath("args/arg[@name='pre']/text()"); + if (comment.isEmpty()) { + final List 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) { diff --git a/src/test/java/com/rultor/agents/github/CommentsTagTest.java b/src/test/java/com/rultor/agents/github/CommentsTagTest.java index d50abffc11..e6b2461a2d 100644 --- a/src/test/java/com/rultor/agents/github/CommentsTagTest.java +++ b/src/test/java/com/rultor/agents/github/CommentsTagTest.java @@ -170,6 +170,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( + "

", + "", + "", + "true", + "

" + ) + ); + 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( diff --git a/src/test/java/com/rultor/agents/github/ReleaseBinariesTest.java b/src/test/java/com/rultor/agents/github/ReleaseBinariesTest.java index b46ae99806..84e4631145 100644 --- a/src/test/java/com/rultor/agents/github/ReleaseBinariesTest.java +++ b/src/test/java/com/rultor/agents/github/ReleaseBinariesTest.java @@ -79,7 +79,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