-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
h1alexbel
committed
Mar 29, 2024
1 parent
1bded1e
commit 77d38c1
Showing
9 changed files
with
1,733 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/main/java/git/tracehub/codereview/action/github/Authored.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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 java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.cactoos.Scalar; | ||
import org.cactoos.list.ListOf; | ||
|
||
/** | ||
* All review comment bodies together with its author. | ||
* | ||
* @since 0.0.0 | ||
*/ | ||
@RequiredArgsConstructor | ||
public final class Authored implements Scalar<List<String>> { | ||
|
||
/** | ||
* Comments. | ||
*/ | ||
private final Comments origin; | ||
|
||
@Override | ||
public List<String> value() throws Exception { | ||
final List<String> bodies = new ListOf<>(); | ||
this.origin.value().forEach( | ||
value -> bodies.add( | ||
String.format( | ||
"%s: %s", | ||
value.asJsonObject() | ||
.getJsonObject("user") | ||
.getString("login"), | ||
value.asJsonObject().getString("body") | ||
) | ||
) | ||
); | ||
return bodies; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/git/tracehub/codereview/action/github/Comments.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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 javax.json.JsonArray; | ||
import org.cactoos.Scalar; | ||
|
||
/** | ||
* Comments in pull request review. | ||
* | ||
* @since 0.0.0 | ||
*/ | ||
public interface Comments extends Scalar<JsonArray> { | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/git/tracehub/codereview/action/github/ReviewIds.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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 java.util.List; | ||
import javax.json.JsonArray; | ||
import lombok.RequiredArgsConstructor; | ||
import org.cactoos.Scalar; | ||
import org.cactoos.list.ListOf; | ||
|
||
/** | ||
* Identifiers collected from all reviews. | ||
* | ||
* @since 0.0.0 | ||
*/ | ||
@RequiredArgsConstructor | ||
public final class ReviewIds implements Scalar<List<Integer>> { | ||
|
||
/** | ||
* All reviews. | ||
*/ | ||
private final Scalar<JsonArray> reviews; | ||
|
||
@Override | ||
public List<Integer> value() throws Exception { | ||
final List<Integer> identifiers = new ListOf<>(); | ||
this.reviews.value().forEach( | ||
value -> identifiers.add( | ||
value.asJsonObject().getInt("id") | ||
) | ||
); | ||
return identifiers; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/git/tracehub/codereview/action/github/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* Operations on GitHub. | ||
* | ||
* @since 0.0.0 | ||
*/ | ||
package git.tracehub.codereview.action.github; |
70 changes: 70 additions & 0 deletions
70
src/test/java/git/tracehub/codereview/action/github/AuthoredTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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 java.io.InputStreamReader; | ||
import java.util.List; | ||
import javax.json.Json; | ||
import org.cactoos.io.ResourceOf; | ||
import org.cactoos.list.ListOf; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.core.IsEqual; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Test case for {@link Authored}. | ||
* | ||
* @since 0.0.0 | ||
* @checkstyle StringLiteralsConcatenationCheck (30 lines) | ||
*/ | ||
final class AuthoredTest { | ||
|
||
@Test | ||
void collectsAllComments() throws Exception { | ||
final List<String> comments = new Authored( | ||
() -> Json.createReader( | ||
new InputStreamReader( | ||
new ResourceOf( | ||
"git/tracehub/codereview/action/github/comments.json" | ||
).stream() | ||
) | ||
).readArray() | ||
).value(); | ||
final List<String> expected = new ListOf<>( | ||
"h1alexbel: @hizmailovich first comment", | ||
"h1alexbel: @hizmailovich second comment", | ||
"h1alexbel: @hizmailovich This sentence might be connected with the" | ||
+ " previous one: \"The subject of this article is caching.\"" | ||
); | ||
MatcherAssert.assertThat( | ||
String.format( | ||
"Received comments (%s) do not match with expected (%s)", | ||
comments, | ||
expected | ||
), | ||
comments, | ||
new IsEqual<>(expected) | ||
); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
src/test/java/git/tracehub/codereview/action/github/ReviewIdsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* 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 java.io.InputStreamReader; | ||
import java.util.List; | ||
import javax.json.Json; | ||
import org.cactoos.io.ResourceOf; | ||
import org.cactoos.list.ListOf; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.core.IsEqual; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Test case for {@link ReviewIds}. | ||
* | ||
* @since 0.0.0 | ||
*/ | ||
final class ReviewIdsTest { | ||
|
||
@Test | ||
void collectsAllIds() throws Exception { | ||
final List<Integer> identifiers = new ReviewIds( | ||
() -> Json.createReader( | ||
new InputStreamReader( | ||
new ResourceOf( | ||
"git/tracehub/codereview/action/github/fake-reviews.json" | ||
).stream() | ||
) | ||
).readArray() | ||
).value(); | ||
final List<Integer> expected = new ListOf<>( | ||
1_928_092_753, | ||
1_933_376_078, | ||
1_933_400_866, | ||
1_933_423_242, | ||
1_934_365_729, | ||
1_936_499_773, | ||
1_937_766_798, | ||
1_937_769_165, | ||
1_938_765_378, | ||
1_941_381_055, | ||
1_942_346_249, | ||
1_942_473_609, | ||
1_942_543_997, | ||
1_942_546_920, | ||
1_943_201_197, | ||
1_944_125_139, | ||
1_944_149_138, | ||
1_944_162_704, | ||
1_945_559_698, | ||
1_945_588_726, | ||
1_945_825_481, | ||
1_957_939_991, | ||
1_958_081_438, | ||
1_958_089_833, | ||
1_958_101_405, | ||
1_958_244_013, | ||
1_958_387_750, | ||
1_958_419_033, | ||
1_958_445_820, | ||
1_958_450_376 | ||
); | ||
MatcherAssert.assertThat( | ||
String.format( | ||
"Collected identifiers (%s) do not match with expected (%s)", | ||
identifiers, | ||
expected | ||
), | ||
identifiers, | ||
new IsEqual<>(expected) | ||
); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/test/java/git/tracehub/codereview/action/github/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* Tests for GitHub operations. | ||
* | ||
* @since 0.0.0 | ||
*/ | ||
package git.tracehub.codereview.action.github; |
Oops, something went wrong.