Skip to content

Commit

Permalink
Add checks to Pull interface
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Mar 17, 2023
1 parent 76d0248 commit 8d14d76
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 18 deletions.
43 changes: 40 additions & 3 deletions src/main/java/com/jcabi/github/Pull.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ void merge(String msg)
* @throws IOException IOException If there is any I/O problem
*/
MergeState merge(String msg,
String sha) throws IOException;
String sha
) throws IOException;

/**
* Get Pull Comments.
Expand All @@ -123,13 +124,21 @@ MergeState merge(String msg,
*/
PullComments comments() throws IOException;

/**
* Get Pull Checks.
* @return Checks.
* @throws IOException If there is any I/O problem.
* @see <a href="https://developer.github.com/v3/checks/runs/">Checks API</a>
*/
Checks checks() throws IOException;

/**
* Smart pull request with extra features.
*/
@Immutable
@ToString
@Loggable(Loggable.DEBUG)
@EqualsAndHashCode(of = { "pull", "jsn" })
@EqualsAndHashCode(of = {"pull", "jsn"})
final class Smart implements Pull {
/**
* Encapsulated pull request.
Expand All @@ -139,6 +148,7 @@ final class Smart implements Pull {
* SmartJson object for convenient JSON parsing.
*/
private final transient SmartJson jsn;

/**
* Public ctor.
* @param pll Pull request
Expand All @@ -149,6 +159,7 @@ public Smart(
this.pull = pll;
this.jsn = new SmartJson(pll);
}

/**
* Is it open?
* @return TRUE if it's open
Expand All @@ -157,6 +168,7 @@ public Smart(
public boolean isOpen() throws IOException {
return Issue.OPEN_STATE.equals(this.state());
}

/**
* Get its state.
* @return State of pull request
Expand All @@ -165,6 +177,7 @@ public boolean isOpen() throws IOException {
public String state() throws IOException {
return this.jsn.text("state");
}

/**
* Change its state.
* @param state State of pull request
Expand All @@ -177,6 +190,7 @@ public void state(
Json.createObjectBuilder().add("state", state).build()
);
}

/**
* Get its title.
* @return Title of pull request
Expand All @@ -185,6 +199,7 @@ public void state(
public String title() throws IOException {
return this.jsn.text("title");
}

/**
* Change its title.
* @param text Title of pull request
Expand All @@ -197,6 +212,7 @@ public void title(
Json.createObjectBuilder().add("title", text).build()
);
}

/**
* Get its body.
* @return Body of pull request
Expand All @@ -205,6 +221,7 @@ public void title(
public String body() throws IOException {
return this.jsn.text("body");
}

/**
* Change its body.
* @param text Body of pull request
Expand All @@ -217,6 +234,7 @@ public void body(
Json.createObjectBuilder().add("body", text).build()
);
}

/**
* Get its URL.
* @return URL of pull request
Expand All @@ -225,6 +243,7 @@ public void body(
public URL url() throws IOException {
return new URL(this.jsn.text("url"));
}

/**
* Get its HTML URL.
* @return URL of pull request
Expand All @@ -233,6 +252,7 @@ public URL url() throws IOException {
public URL htmlUrl() throws IOException {
return new URL(this.jsn.text("html_url"));
}

/**
* When this pull request was created.
* @return Date of creation
Expand All @@ -247,6 +267,7 @@ public Date createdAt() throws IOException {
throw new IllegalStateException(ex);
}
}

/**
* When this pull request was updated.
* @return Date of update
Expand All @@ -261,6 +282,7 @@ public Date updatedAt() throws IOException {
throw new IllegalStateException(ex);
}
}

/**
* When this pull request was closed.
* @return Date of closing
Expand All @@ -275,6 +297,7 @@ public Date closedAt() throws IOException {
throw new IllegalStateException(ex);
}
}

/**
* When this pull request was merged.
* @return Date of merging
Expand Down Expand Up @@ -310,6 +333,7 @@ public User author() throws IOException {
public Issue issue() {
return this.pull.repo().issues().get(this.pull.number());
}

/**
* Get comments count.
* @return Count of comments
Expand All @@ -319,22 +343,27 @@ public Issue issue() {
public int commentsCount() throws IOException {
return this.jsn.number("comments");
}

@Override
public Repo repo() {
return this.pull.repo();
}

@Override
public int number() {
return this.pull.number();
}

@Override
public Iterable<Commit> commits() throws IOException {
return this.pull.commits();
}

@Override
public Iterable<JsonObject> files() throws IOException {
return this.pull.files();
}

@Override
public void merge(
final String msg
Expand All @@ -345,7 +374,8 @@ public void merge(
@Override
public MergeState merge(
final String msg,
final String sha)
final String sha
)
throws IOException {
return this.pull.merge(msg, sha);
}
Expand All @@ -355,16 +385,23 @@ public PullComments comments() throws IOException {
return this.pull.comments();
}

@Override
public Checks checks() throws IOException {
return this.pull.checks();
}

@Override
public JsonObject json() throws IOException {
return this.pull.json();
}

@Override
public void patch(
final JsonObject json
) throws IOException {
this.pull.patch(json);
}

@Override
public int compareTo(
final Pull obj
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/jcabi/github/RtPull.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ public PullComments comments() {
return new RtPullComments(this.entry, this);
}

@Override
public Checks checks() throws IOException {
return new RtChecks(this.entry, this);
}

@Override
public PullRef base() throws IOException {
return new RtPullRef(
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/com/jcabi/github/mock/MkChecks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright (c) 2013-2023, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.github.mock;

import com.jcabi.github.Check;
import com.jcabi.github.Checks;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;

/**
* Mock Github Checks.
*
* @author Volodya Lombrozo (volodya.lombrozo@gmail.com)
* @version $Id$
* @since 1.6.0
*/
public final class MkChecks implements Checks {
@Override
public Collection<Check> all() throws IOException {
return Collections.emptyList();
}
}
19 changes: 14 additions & 5 deletions src/main/java/com/jcabi/github/mock/MkPull.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import com.jcabi.aspects.Immutable;
import com.jcabi.aspects.Loggable;
import com.jcabi.github.Checks;
import com.jcabi.github.Commit;
import com.jcabi.github.Coordinates;
import com.jcabi.github.MergeState;
Expand All @@ -53,12 +54,13 @@
* Mock Github pull.
* @author Yegor Bugayenko (yegor256@gmail.com)
* @version $Id$
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
* @since 0.5
*/
@Immutable
@Loggable(Loggable.DEBUG)
@ToString
@EqualsAndHashCode(of = { "storage", "self", "coords", "num" })
@EqualsAndHashCode(of = {"storage", "self", "coords", "num"})
@SuppressWarnings("PMD.TooManyMethods")
final class MkPull implements Pull {
/**
Expand Down Expand Up @@ -123,7 +125,8 @@ final class MkPull implements Pull {
final MkStorage stg,
final String login,
final Coordinates rep,
final int number) {
final int number
) {
this.storage = stg;
this.self = login;
this.coords = rep;
Expand Down Expand Up @@ -200,7 +203,8 @@ public void merge(
@Override
public MergeState merge(
final String msg,
final String sha) {
final String sha
) {
throw new UnsupportedOperationException("Merge not supported");
}

Expand All @@ -209,6 +213,11 @@ public PullComments comments() throws IOException {
return new MkPullComments(this.storage, this.self, this.coords, this);
}

@Override
public Checks checks() {
return new MkChecks();
}

@Override
public int compareTo(
final Pull pull
Expand Down Expand Up @@ -241,8 +250,8 @@ public JsonObject json() throws IOException {
json.add(
MkPull.USER_PROP,
Json.createObjectBuilder()
.add("login", xml.xpath("user/login/text()").get(0))
.build()
.add("login", xml.xpath("user/login/text()").get(0))
.build()
);
} else if (MkPull.HEAD_PROP.equals(val.getKey())) {
json.add(
Expand Down
Loading

0 comments on commit 8d14d76

Please sign in to comment.