Skip to content

Commit 4f10c0b

Browse files
committed
Merge branch '__rultor'
2 parents 1a12793 + e1c9598 commit 4f10c0b

File tree

8 files changed

+430
-27
lines changed

8 files changed

+430
-27
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ SOFTWARE.
193193
<version>${ghquota.version}</version>
194194
<scope>test</scope>
195195
</dependency>
196+
<dependency>
197+
<groupId>io.github.hakky54</groupId>
198+
<artifactId>logcaptor</artifactId>
199+
<version>${logcaptor.version}</version>
200+
<scope>test</scope>
201+
</dependency>
196202
</dependencies>
197203
<build>
198204
<plugins>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2024 Tracehub.git
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included
14+
* in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package git.tracehub.codereview.action;
25+
26+
import com.jcabi.github.Pull;
27+
import com.jcabi.log.Logger;
28+
import git.tracehub.codereview.action.github.FixedReviews;
29+
import git.tracehub.codereview.action.github.GhRequest;
30+
import git.tracehub.codereview.action.github.JsonReviews;
31+
import git.tracehub.codereview.action.github.WithComments;
32+
import javax.json.JsonArray;
33+
import lombok.RequiredArgsConstructor;
34+
import org.cactoos.Proc;
35+
36+
/**
37+
* Analysis routine.
38+
*
39+
* @since 0.0.0
40+
*/
41+
@RequiredArgsConstructor
42+
@SuppressWarnings("OOP.LongClassNameCheck")
43+
public final class AnalysisRoutine implements Proc<Pull> {
44+
45+
/**
46+
* GitHub token.
47+
*/
48+
private final String token;
49+
50+
@Override
51+
public void exec(final Pull pull) throws Exception {
52+
final JsonArray reviews = new WithComments(
53+
new FixedReviews(new JsonReviews(pull, new GhRequest(this.token))),
54+
new GhRequest(this.token),
55+
pull
56+
).value();
57+
Logger.info(Entry.class, "found reviews: %s", reviews);
58+
}
59+
}

src/main/java/git/tracehub/codereview/action/Entry.java

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,11 @@
2727
import com.jcabi.github.Pull;
2828
import com.jcabi.github.RtGithub;
2929
import com.jcabi.log.Logger;
30-
import git.tracehub.codereview.action.github.ChangesCount;
3130
import git.tracehub.codereview.action.github.EventPull;
32-
import git.tracehub.codereview.action.github.FixedReviews;
33-
import git.tracehub.codereview.action.github.GhRequest;
34-
import git.tracehub.codereview.action.github.JsonReviews;
35-
import git.tracehub.codereview.action.github.WithComments;
3631
import java.io.StringReader;
3732
import java.nio.file.Files;
3833
import java.nio.file.Paths;
3934
import javax.json.Json;
40-
import javax.json.JsonArray;
4135
import javax.json.JsonObject;
4236

4337
/**
@@ -58,6 +52,11 @@ public final class Entry {
5852
* After information is collected (pull request itself, its files,
5953
* and reviews) we can feed it into the model asking what is the quality
6054
* of the following code review.
55+
* @todo #51:45min Box SkipIfTooSmall.java into more major routine.
56+
* SkipIfTooSmall.java is a good routine, but it should be encapsulated
57+
* by something that logically is bigger than that. For now it can
58+
* be not clear why at the end we run SkipIfTooSmall.java, not
59+
* something like Analyze.java or similar.
6160
*/
6261
public static void main(final String... args) throws Exception {
6362
final String name = System.getenv().get("GITHUB_REPOSITORY");
@@ -89,26 +88,9 @@ public static void main(final String... args) throws Exception {
8988
pull.number(),
9089
title
9190
);
92-
final int min = Integer.parseInt(
93-
System.getenv().get("INPUT_MIN_LINES")
94-
);
95-
if (min != 0) {
96-
final int changes = new ChangesCount(pull).value();
97-
if (min > changes) {
98-
Logger.info(
99-
Entry.class,
100-
"Skipping pull request #%s since changes count %d less than %s",
101-
pull.number(),
102-
changes,
103-
min
104-
);
105-
}
106-
}
107-
final JsonArray reviews = new WithComments(
108-
new FixedReviews(new JsonReviews(pull, new GhRequest(token))),
109-
new GhRequest(token),
110-
pull
111-
).value();
112-
Logger.info(Entry.class, "found reviews: %s", reviews);
91+
new SkipIfTooSmall(
92+
new MinLines(),
93+
new AnalysisRoutine(token)
94+
).exec(pull);
11395
}
11496
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2024 Tracehub.git
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included
14+
* in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package git.tracehub.codereview.action;
25+
26+
import org.cactoos.Scalar;
27+
28+
/**
29+
* Min lines.
30+
*
31+
* @since 0.0.0
32+
*/
33+
public final class MinLines implements Scalar<Integer> {
34+
35+
/**
36+
* If lines are not provided.
37+
*/
38+
private static final int NOT_PROVIDED = 0;
39+
40+
@Override
41+
public Integer value() throws Exception {
42+
final int min;
43+
final String input = System.getenv().get("INPUT_MIN_LINES");
44+
if (input == null) {
45+
min = MinLines.NOT_PROVIDED;
46+
} else {
47+
min = Integer.parseInt(input);
48+
}
49+
return min;
50+
}
51+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2024 Tracehub.git
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included
14+
* in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package git.tracehub.codereview.action;
25+
26+
import com.jcabi.github.Pull;
27+
import com.jcabi.log.Logger;
28+
import git.tracehub.codereview.action.github.ChangesCount;
29+
import lombok.RequiredArgsConstructor;
30+
import org.cactoos.Proc;
31+
import org.cactoos.Scalar;
32+
33+
/**
34+
* Skip pull request if it's too small.
35+
*
36+
* @since 0.0.0
37+
*/
38+
@RequiredArgsConstructor
39+
@SuppressWarnings("OOP.LongClassNameCheck")
40+
public final class SkipIfTooSmall implements Proc<Pull> {
41+
42+
/**
43+
* Min lines.
44+
*/
45+
private final Scalar<Integer> lines;
46+
47+
/**
48+
* Routine to run.
49+
*/
50+
private final Proc<Pull> routine;
51+
52+
@Override
53+
public void exec(final Pull pull) throws Exception {
54+
final Integer min = this.lines.value();
55+
if (min != 0) {
56+
final int changes = new ChangesCount(pull).value();
57+
if (min > changes) {
58+
Logger.info(
59+
this,
60+
"Skipping pull request #%d since changes count %d less than min_lines %d",
61+
pull.number(),
62+
changes,
63+
min
64+
);
65+
} else {
66+
Logger.info(
67+
this,
68+
"Pull request #%d has enough number of lines (%d), min: %d",
69+
pull.number(),
70+
changes,
71+
min
72+
);
73+
this.routine.exec(pull);
74+
}
75+
}
76+
this.routine.exec(pull);
77+
}
78+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2024 Tracehub.git
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included
14+
* in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package git.tracehub.codereview.action;
25+
26+
import org.hamcrest.MatcherAssert;
27+
import org.hamcrest.core.IsEqual;
28+
import org.junit.jupiter.api.Disabled;
29+
import org.junit.jupiter.api.Test;
30+
31+
/**
32+
* Test case for {@link MinLines}.
33+
*
34+
* @since 0.0.0
35+
*/
36+
final class MinLinesTest {
37+
38+
/**
39+
* Returns provided min lines from environment.
40+
* @throws Exception if something went wrong
41+
* @todo #51:30min This test fails since there is no injected INPUT_MIN_LINES variable.
42+
* During test execution we should set `INPUT_MIN_LINES` into system environment,
43+
* so `MinLines.java` will fetch it and should return expected number of lines.
44+
* Don't forget to remove this puzzle.
45+
*/
46+
@Test
47+
@Disabled
48+
void returnsProvidedMinLines() throws Exception {
49+
final int lines = new MinLines().value();
50+
final int expected = 15;
51+
MatcherAssert.assertThat(
52+
String.format(
53+
"Provided min lines %d does not match with expected %d",
54+
lines,
55+
expected
56+
),
57+
lines,
58+
new IsEqual<>(expected)
59+
);
60+
}
61+
62+
@Test
63+
void returnsZeroWhenNotProvided() throws Exception {
64+
final int lines = new MinLines().value();
65+
final int expected = 0;
66+
MatcherAssert.assertThat(
67+
String.format(
68+
"Provided min lines %d does not match with expected %d",
69+
lines,
70+
expected
71+
),
72+
lines,
73+
new IsEqual<>(expected)
74+
);
75+
}
76+
}

0 commit comments

Comments
 (0)