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 29, 2024
2 parents ea98b54 + 9fb9563 commit bad4fdf
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/main/java/git/tracehub/codereview/action/github/JsonPull.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 Tracehub.git
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package git.tracehub.codereview.action.github;

import com.jcabi.github.Repo;
import java.io.IOException;
import javax.json.JsonObject;
import lombok.RequiredArgsConstructor;
import org.cactoos.Scalar;

/**
* Pull request on GitHub in JSON.
*
* @since 0.0.0
*/
@RequiredArgsConstructor
public final class JsonPull implements Scalar<JsonObject> {

/**
* Repo.
*/
private final Repo repo;

/**
* JSON event.
*/
private final JsonObject event;

@Override
public JsonObject value() throws IOException {
return this.repo.pulls().get(
this.event.getJsonObject("pull_request").getInt("number")
).json();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 Tracehub.git
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package git.tracehub.codereview.action.github;

import com.jcabi.github.Pull;
import com.jcabi.github.Repo;
import com.jcabi.github.mock.MkGithub;
import javax.json.Json;
import javax.json.JsonObject;
import org.cactoos.io.ResourceOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.core.IsEqual;
import org.junit.jupiter.api.Test;

/**
* Test case for {@link JsonPull}.
*
* @since 0.0.0
*/
final class JsonPullTest {

@Test
void readsJsonPull() throws Exception {
final Repo repo = new MkGithub().randomRepo();
final Pull created = repo.pulls().create("test", "master", "master");
final JsonObject pull = new JsonPull(
repo,
Json.createObjectBuilder()
.add(
"pull_request",
Json.createObjectBuilder()
.add("number", created.number())
.build()
)
.build()
).value();
final JsonObject expected = Json.createReader(
new ResourceOf(
"git/tracehub/codereview/action/github/pull.json"
).stream()
).readObject();
MatcherAssert.assertThat(
String.format(
"Received JSON (%s) does not match with expected (%s)",
pull,
expected
),
pull,
new IsEqual<>(expected)
);
}
}
15 changes: 15 additions & 0 deletions src/test/resources/git/tracehub/codereview/action/github/pull.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"number": 1,
"head": {
"ref": "master",
"label": "jeff:master"
},
"base": {
"ref": "master",
"label": "jeff:master"
},
"user": {
"login": "jeff"
},
"comments": 0
}

0 comments on commit bad4fdf

Please sign in to comment.