From b848de8d1df17c7a66668115757347ffb9df70f9 Mon Sep 17 00:00:00 2001 From: Natalia Pozhidaeva Date: Tue, 6 Feb 2024 23:08:29 -0500 Subject: [PATCH] [#1459] Fix style errors --- .../agents/github/qtn/CheckablePull.java | 98 ++++--------------- .../com/rultor/agents/github/qtn/QnMerge.java | 47 ++++----- 2 files changed, 43 insertions(+), 102 deletions(-) diff --git a/src/main/java/com/rultor/agents/github/qtn/CheckablePull.java b/src/main/java/com/rultor/agents/github/qtn/CheckablePull.java index 0e8ddf0ad4..da64288fb5 100644 --- a/src/main/java/com/rultor/agents/github/qtn/CheckablePull.java +++ b/src/main/java/com/rultor/agents/github/qtn/CheckablePull.java @@ -30,97 +30,35 @@ package com.rultor.agents.github.qtn; import com.jcabi.aspects.Immutable; -import com.jcabi.github.*; -import javax.json.JsonObject; +import com.jcabi.github.Check; +import com.jcabi.github.Pull; import java.io.IOException; +import javax.json.JsonObject; import lombok.EqualsAndHashCode; import lombok.ToString; /** * Checkable pull request. * - * @author Yegor Bugayenko (yegor256@gmail.com) + * @author Natalia Pozhidaeva (p.natasha.p@gmail.com) + * @version $Id$ * @since 2.0 */ @Immutable @ToString @EqualsAndHashCode -public class CheckablePull implements Pull { +final class CheckablePull { /** * Pull request. */ - private Pull pull; + private final transient Pull pull; /** * Ctor. - * @param pull Pull to validate + * @param ghpull Pull to validate */ - public CheckablePull(final Pull pull) { - this.pull = pull; - } - @Override - public Repo repo() { - return pull.repo(); - } - - @Override - public int number() { - return pull.number(); - } - - @Override - public PullRef base() throws IOException { - return pull.base(); - } - - @Override - public PullRef head() throws IOException { - return pull.head(); - } - - @Override - public Iterable commits() throws IOException { - return pull.commits(); - } - - @Override - public Iterable files() throws IOException { - return pull.files(); - } - - @Override - public void merge(String s) throws IOException { - pull.merge(s); - } - - @Override - public MergeState merge(String s, String s1) throws IOException { - return pull.merge(s, s1); - } - - @Override - public PullComments comments() throws IOException { - return pull.comments(); - } - - @Override - public Checks checks() throws IOException { - return pull.checks(); - } - - @Override - public void patch(JsonObject jsonObject) throws IOException { - pull.patch(jsonObject); - } - - @Override - public JsonObject json() throws IOException { - return pull.json(); - } - - @Override - public int compareTo(Pull o) { - return pull.compareTo(o); + public CheckablePull(final Pull ghpull) { + this.pull = ghpull; } /** @@ -130,7 +68,7 @@ public int compareTo(Pull o) { */ public boolean allChecksSuccessful() throws IOException { boolean result = true; - for (final Check check : pull.checks().all()) { + for (final Check check : this.pull.checks().all()) { if (!check.successful()) { result = false; break; @@ -141,16 +79,18 @@ public boolean allChecksSuccessful() throws IOException { /** * Checks if file is affected by pull request. - * @param fileName File name to check + * @param file File name to check * @return True if all checks are successful * @throws IOException If fails */ - public boolean containsFile(String fileName) throws IOException { - for (final JsonObject file : pull.files()) { - if (file.getString("filename").equals(fileName)) { - return true; + public boolean containsFile(final String file) throws IOException { + boolean result = false; + for (final JsonObject jfile : this.pull.files()) { + if (jfile.getString("filename").equalsIgnoreCase(file)) { + result = true; + break; } } - return false; + return result; } } diff --git a/src/main/java/com/rultor/agents/github/qtn/QnMerge.java b/src/main/java/com/rultor/agents/github/qtn/QnMerge.java index be1790a000..5a585c7c04 100644 --- a/src/main/java/com/rultor/agents/github/qtn/QnMerge.java +++ b/src/main/java/com/rultor/agents/github/qtn/QnMerge.java @@ -30,7 +30,6 @@ package com.rultor.agents.github.qtn; import com.jcabi.aspects.Immutable; -import com.jcabi.github.Check; import com.jcabi.github.Comment; import com.jcabi.github.Issue; import com.jcabi.github.Pull; @@ -77,32 +76,34 @@ public Req understand(final Comment.Smart comment, this, "merge request found in %s#%d, comment #%d", issue.repo().coordinates(), issue.number(), comment.number() ); - final CheckablePull mr = new CheckablePull(issue.pull()); - if (mr.containsFile(".rultor.yml")) { + final CheckablePull pull = new CheckablePull(issue.pull()); + if (pull.containsFile(".rultor.yml")) { new Answer(comment).post( false, - QnMerge.PHRASES.getString("QnMerge.system-files-affected") + QnMerge.PHRASES + .getString("QnMerge.system-files-affected") ); req = Req.DONE; - } else if (mr.allChecksSuccessful()) { - new Answer(comment).post( - true, - String.format( - QnMerge.PHRASES.getString("QnMerge.start"), - home.toASCIIString() - ) - ); - req = QnMerge.pack( - comment, - issue.repo().pulls().get(issue.number()) - ); - } else { - new Answer(comment).post( - false, - QnMerge.PHRASES.getString("QnMerge.checks-are-failed") - ); - req = Req.DONE; - } + } else + if (pull.allChecksSuccessful()) { + new Answer(comment).post( + true, + String.format( + QnMerge.PHRASES.getString("QnMerge.start"), + home.toASCIIString() + ) + ); + req = QnMerge.pack( + comment, + issue.repo().pulls().get(issue.number()) + ); + } else { + new Answer(comment).post( + false, + QnMerge.PHRASES.getString("QnMerge.checks-are-failed") + ); + req = Req.DONE; + } } else { new Answer(comment).post( false,