Skip to content

Commit

Permalink
[yegor256#1459] Fix style errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pnatashap committed Feb 7, 2024
1 parent 66dd744 commit b848de8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 102 deletions.
98 changes: 19 additions & 79 deletions src/main/java/com/rultor/agents/github/qtn/CheckablePull.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([email protected])
* @author Natalia Pozhidaeva ([email protected])
* @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<Commit> commits() throws IOException {
return pull.commits();
}

@Override
public Iterable<JsonObject> 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;
}

/**
Expand All @@ -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;
Expand All @@ -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;
}
}
47 changes: 24 additions & 23 deletions src/main/java/com/rultor/agents/github/qtn/QnMerge.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b848de8

Please sign in to comment.