Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Mar 21, 2023
2 parents cb60178 + f88d79d commit f6871d6
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 18 deletions.
50 changes: 47 additions & 3 deletions src/main/java/com/jcabi/github/Pull.java
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,22 @@ 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>
* @since 1.6.0
*/
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 +149,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 +160,7 @@ public Smart(
this.pull = pll;
this.jsn = new SmartJson(pll);
}

/**
* Is it open?
* @return TRUE if it's open
Expand All @@ -157,6 +169,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 +178,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 +191,7 @@ public void state(
Json.createObjectBuilder().add("state", state).build()
);
}

/**
* Get its title.
* @return Title of pull request
Expand All @@ -185,6 +200,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 +213,7 @@ public void title(
Json.createObjectBuilder().add("title", text).build()
);
}

/**
* Get its body.
* @return Body of pull request
Expand All @@ -205,6 +222,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 +235,7 @@ public void body(
Json.createObjectBuilder().add("body", text).build()
);
}

/**
* Get its URL.
* @return URL of pull request
Expand All @@ -225,6 +244,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 +253,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 +268,7 @@ public Date createdAt() throws IOException {
throw new IllegalStateException(ex);
}
}

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

/**
* When this pull request was closed.
* @return Date of closing
Expand All @@ -275,6 +298,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 +334,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 +344,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 +375,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 +386,29 @@ public PullComments comments() throws IOException {
return this.pull.comments();
}

/**
* Retrieve a PR check runs.
* @return Checks
* @throws IOException If there is any I/O problem.
* @since 1.6.0
*/
@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
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
@@ -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();
}
}
24 changes: 19 additions & 5 deletions src/main/java/com/jcabi/github/mock/MkPull.java
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,16 @@ public PullComments comments() throws IOException {
return new MkPullComments(this.storage, this.self, this.coords, this);
}

/**
* Retrieve PR check runs.
* @return Checks
* @since 1.6.0
*/
@Override
public Checks checks() {
return new MkChecks();
}

@Override
public int compareTo(
final Pull pull
Expand Down Expand Up @@ -241,8 +255,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

0 comments on commit f6871d6

Please sign in to comment.