Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MkChecks implementation #1622

Merged
merged 3 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<artifactId>guava</artifactId>
<version>31.1-jre</version>
</dependency>
<dependency>
<groupId>org.cactoos</groupId>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@volodya-lombrozo can't you use Guava instead? It's already in the list of dependencies and provides the same functionality of turning an Iterable to a List.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yegor256 Done. Could you have a look, again, please?

<artifactId>cactoos</artifactId>
<version>0.55.0</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
Expand Down
186 changes: 185 additions & 1 deletion src/main/java/com/jcabi/github/Check.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
*/
package com.jcabi.github;

import java.io.IOException;
import java.util.Arrays;
import java.util.Locale;

/**
* Github check.
*
Expand All @@ -42,7 +46,187 @@ public interface Check {
/**
* Checks whether Check was successful.
* @return True if Check was successful.
* @throws IOException If there is any I/O problem.
*/
boolean successful() throws IOException;

/**
* Check status.
* You can read more about it
* @checkstyle LineLengthCheck (1 lines)
* <a href="https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#list-check-runs-for-a-git-reference"> here </a>
*/
enum Status {
/**
* Queued.
*/
QUEUED("queued"),

/**
* In progress.
*/
IN_PROGRESS("in_progress"),

/**
* Completed.
*/
COMPLETED("completed");

/**
* Status.
*/
private final String status;

/**
* Ctor.
* @param stat Status.
*/
Status(final String stat) {
this.status = stat;
}

/**
* Status.
* @return Status.
*/
public String value() {
return this.status;
}

/**
* Get status from string.
* @param value String value.
* @return Status.
*/
public static Status fromString(final String value) {
return Arrays.stream(Status.values())
.filter(stat -> stat.same(value))
.findFirst()
.orElseThrow(
() -> new IllegalArgumentException(
String.format("Invalid value %s for status", value)
)
);
}

/**
* Check if check is finished.
* @return True if check is finished.
*/
boolean finished() {
return this == Status.COMPLETED;
}

/**
* Check if status is the same as value.
* @param value Value.
* @return True if status is the same as value.
*/
boolean same(final String value) {
return this.status.equals(value.toLowerCase(Locale.ROOT));
}
}

/**
* Check conclusion.
* You can read more about it
* @checkstyle LineLengthCheck (1 lines)
* <a href="https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#list-check-runs-for-a-git-reference"> here </a>
*/
boolean successful();
enum Conclusion {

/**
* Action required.
*/
ACTION_REQUIRED("action_required"),

/**
* Cancelled.
*/
CANCELLED("cancelled"),

/**
* Failure.
*/
FAILURE("failure"),

/**
* Neutral.
*/
NEUTRAL("neutral"),

/**
* Success.
*/
SUCCESS("success"),

/**
* Skipped.
*/
SKIPPED("skipped"),

/**
* Stale.
*/
STALE("stale"),

/**
* Timed out.
*/
TIMED_OUT("timed_out");

/**
* Conclusion.
*/
private final String conclusion;

/**
* Ctor.
* @param con Conclusion.
*/
Conclusion(final String con) {
this.conclusion = con;
}

/**
* Get conclusion from string.
* @param value String value.
* @return Conclusion.
*/
public static Conclusion fromString(final String value) {
return Arrays.stream(Conclusion.values())
.filter(stat -> stat.same(value))
.findFirst()
.orElseThrow(
() -> new IllegalArgumentException(
String.format("Invalid value %s for conclusion", value)
)
);
}

/**
* Conclusion.
* @return Conclusion.
*/
public String value() {
return this.conclusion;
}

/**
* Check if check is successful.
* @return True if check is successful.
*/
boolean successful() {
return this == Conclusion.SUCCESS;
}

/**
* Check if conclusion is the same as value.
* @param value Value to compare.
* @return True if conclusion is the same as value.
*/
boolean same(final String value) {
return this.conclusion.equals(value.toLowerCase(Locale.ROOT));
}
}
}
Loading