Skip to content

Commit

Permalink
feat(#1758): fix all the qulice suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Dec 14, 2023
1 parent 7d76496 commit f0ca3e2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
20 changes: 12 additions & 8 deletions src/main/java/com/rultor/agents/github/CommentsTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,19 @@ public CommentsTag(final Github ghub) {

/**
* Constructor.
* @param github Github client
* @param profile Profile
* @param ghub Github client
* @param config Profile
*/
public CommentsTag(
final Github github,
final Profile profile
final Github ghub,
final Profile config
) {
super(
"/talk/wire[github-repo and github-issue]",
"/talk/request[@id and type='release' and success='true']"
);
this.github = github;
this.profile = profile;
this.github = ghub;
this.profile = config;
}

@Override
Expand Down Expand Up @@ -154,16 +154,20 @@ public Iterable<Directive> process(final XML xml) throws IOException {

/**
* Check if release is prerelease.
* True if profile does not specify release.pre=false.
* @return True if prerelease, false otherwise.
*/
private boolean isPrerelease() {
try {
final boolean result;
final List<String> xpath = this.profile.read()
.xpath("/p/entry[@key='release']/entry[@key='pre']/text()");
if (xpath.isEmpty()) {
return true;
result = true;
} else {
result = "true".equals(xpath.get(0).trim());
}
return "true".equals(xpath.get(0).trim());
return result;
} catch (final IOException exception) {
throw new IllegalStateException(
String.format(
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/rultor/spi/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ public Fixed() {

/**
* Ctor.
* @param xml Xml lines
* @param lines Xml lines
*/
public Fixed(String... xml) {
this(new XMLDocument(String.join("", xml)));
public Fixed(final String... lines) {
this(new XMLDocument(String.join("", lines)));
}

/**
Expand Down
22 changes: 10 additions & 12 deletions src/test/java/com/rultor/agents/github/CommentsTagTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.jcabi.github.Releases;
import com.jcabi.github.Repo;
import com.jcabi.github.mock.MkGithub;
import com.jcabi.xml.XMLDocument;
import com.rultor.spi.Agent;
import com.rultor.spi.Profile;
import com.rultor.spi.Talk;
Expand Down Expand Up @@ -169,7 +168,7 @@ public void createsReleaseTitleFromTalk() throws Exception {

/**
* CommentsTag can create latest release if profile specify 'pre: false'.
* @throws Exception In case of error.
* @throws IOException In case of error.
*/
@Test
public void createsLatestRelease() throws IOException {
Expand All @@ -182,17 +181,18 @@ public void createsLatestRelease() throws IOException {
final Agent agent = new CommentsTag(
repo.github(),
new Profile.Fixed(
"<p><entry key='release'><entry key='pre'>false</entry></entry></p>"
"<p>",
"<entry key='release'>",
"<entry key='pre'>",
"false",
"</entry></entry></p>"
)
);
final String tag = "v1.1.latest";
final Talk talk = CommentsTagTest.talk(issue, tag);
agent.execute(talk);
MatcherAssert.assertThat(
String.format(
"We expect that release with tag '%s' is the latest final release (not a pre-release)",
tag
),
"We expect latest release to be created (not pre)",
new Release.Smart(
new Releases.Smart(repo.releases()).find(tag)
).prerelease(),
Expand All @@ -201,7 +201,8 @@ public void createsLatestRelease() throws IOException {
}

/**
* CommentsTag can create pre-release by default if profile specify anything.
* CommentsTag can create pre-release by default.
* Check the default behaviour if profile specifies anything.
* @throws IOException In case of error.
*/
@Test
Expand All @@ -217,10 +218,7 @@ public void createsPreReleaseByDefault() throws IOException {
final Talk talk = CommentsTagTest.talk(issue, tag);
agent.execute(talk);
MatcherAssert.assertThat(
String.format(
"We expect that release with tag '%s' is the pre-release by default if profile does not specify 'pre: false'",
tag
),
"We expect pre-release to be created by default",
new Release.Smart(
new Releases.Smart(repo.releases()).find(tag)
).prerelease(),
Expand Down

0 comments on commit f0ca3e2

Please sign in to comment.