Skip to content

Commit 332bceb

Browse files
committed
Merge branch '__rultor'
2 parents f9137ea + f6f1dab commit 332bceb

File tree

6 files changed

+135
-2
lines changed

6 files changed

+135
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ These are the parameters you can use/override:
8787
* `min_lines`: Minimal amount of lines in the pull request to get analyzed
8888
by this action, pull requests with fewer lines than provided `min_size`
8989
won't be processed.
90+
* `skip_authors`: GitHub logins of authors, whose pull requests you want to
91+
skip from analyzing. By default, `renovatebot` and `dependabot` are ignored.
9092

9193
### Analysis Method
9294

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ inputs:
2424
min_lines:
2525
description: 'Minimal amount of lines in the pull request to get analyzed by this action'
2626
required: false
27+
skip_authors:
28+
description: 'GitHub logins of authors, whose pull requests you want to skip from analyzing'
29+
default: '["renovate", "dependabot"]'
30+
required: false
2731
runs:
2832
using: 'docker'
2933
image: 'Dockerfile'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public final class SkipAuthors implements Scalar<Collection<String>> {
6161
*
6262
* @param skip Authors which will be skipped.
6363
*/
64-
SkipAuthors(final String... skip) {
64+
public SkipAuthors(final String... skip) {
6565
this(new ListOf<>(skip));
6666
}
6767

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public final void exec(final Pull pull, final String param) throws Exception {
5959
if (this.mentions.value().contains(author)) {
6060
Logger.info(
6161
this,
62-
"Skipping pull request, since author '%s' is excluded",
62+
"Skipping pull request #%d, since author @%s is excluded",
63+
pull.number(),
6364
author
6465
);
6566
} else {

src/test/java/git/tracehub/codereview/action/SkipIfMentionedTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@
2727
import com.jcabi.log.Logger;
2828
import git.tracehub.codereview.action.extentions.PullRequestExtension;
2929
import java.util.Collections;
30+
import java.util.List;
3031
import java.util.concurrent.atomic.AtomicBoolean;
32+
import nl.altindag.log.LogCaptor;
33+
import org.cactoos.list.ListOf;
3134
import org.hamcrest.MatcherAssert;
35+
import org.hamcrest.core.IsEqual;
3236
import org.hamcrest.core.IsNot;
3337
import org.junit.jupiter.api.Test;
3438
import org.junit.jupiter.api.extension.ExtendWith;
@@ -75,4 +79,31 @@ void processesAuthorMentioned(final Pull pull) throws Exception {
7579
)
7680
);
7781
}
82+
83+
@Test
84+
@ExtendWith(PullRequestExtension.class)
85+
void addsLogsWhenSkips(final Pull pull) throws Exception {
86+
final LogCaptor capt = LogCaptor.forClass(SkipIfMentioned.class);
87+
final String skip = "jeff";
88+
new SkipIfMentioned(
89+
new SkipAuthors(skip),
90+
(incoming, param) -> Logger.info(SkipIfMentioned.class, "Boom!")
91+
).exec(pull, "");
92+
final List<String> logs = capt.getInfoLogs();
93+
final List<String> expected = new ListOf<>(
94+
String.format(
95+
"Skipping pull request #%d, since author @%s is excluded",
96+
pull.number(),
97+
skip
98+
)
99+
);
100+
MatcherAssert.assertThat(
101+
String.format(
102+
"Received logs (%s) do not match with expected (%s)",
103+
logs, expected
104+
),
105+
logs,
106+
new IsEqual<>(expected)
107+
);
108+
}
78109
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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 it;
25+
26+
import com.jcabi.github.Coordinates;
27+
import com.jcabi.github.Github;
28+
import com.jcabi.github.Pull;
29+
import com.yegor256.WeAreOnline;
30+
import git.tracehub.codereview.action.AnalysisRoutine;
31+
import git.tracehub.codereview.action.MinLines;
32+
import git.tracehub.codereview.action.SkipAuthors;
33+
import git.tracehub.codereview.action.SkipIfMentioned;
34+
import git.tracehub.codereview.action.SkipIfTooSmall;
35+
import git.tracehub.codereview.action.github.GhIdentity;
36+
import io.github.h1alexbel.ghquota.Quota;
37+
import java.util.List;
38+
import nl.altindag.log.LogCaptor;
39+
import org.cactoos.list.ListOf;
40+
import org.hamcrest.MatcherAssert;
41+
import org.hamcrest.core.IsEqual;
42+
import org.junit.jupiter.api.Tag;
43+
import org.junit.jupiter.api.Test;
44+
import org.junit.jupiter.api.extension.ExtendWith;
45+
46+
/**
47+
* Integration test case for {@link SkipIfMentioned}.
48+
*
49+
* @since 0.2.0
50+
*/
51+
final class SkipIfMentionedITCase {
52+
53+
@Test
54+
@Tag("simulation")
55+
@ExtendWith({WeAreOnline.class, Quota.class})
56+
void skipsAuthorPull() throws Exception {
57+
final LogCaptor capt = LogCaptor.forClass(SkipIfMentioned.class);
58+
final Github github = new GhIdentity().value();
59+
final Pull pull = github.repos()
60+
.get(new Coordinates.Simple("tracehubpm/test"))
61+
.pulls()
62+
.get(5);
63+
final String token = System.getProperty("INPUT_GITHUB_TOKEN");
64+
final String skip = "h1alexbel";
65+
new SkipIfMentioned(
66+
new SkipAuthors(skip),
67+
new SkipIfTooSmall(
68+
new MinLines(),
69+
new AnalysisRoutine(
70+
token,
71+
github.users().self().login(),
72+
System.getenv().get("INPUT_DEEPINFRA_TOKEN")
73+
)
74+
)
75+
).exec(
76+
pull,
77+
System.getenv().get("INPUT_DEEPINFRA_MODEL")
78+
);
79+
final List<String> logs = capt.getInfoLogs();
80+
final List<String> expected = new ListOf<>(
81+
String.format(
82+
"Skipping pull request #%d, since author @%s is excluded",
83+
pull.number(), skip
84+
)
85+
);
86+
MatcherAssert.assertThat(
87+
String.format(
88+
"Received logs (%s) do not match with expected (%s)",
89+
logs, expected
90+
),
91+
logs,
92+
new IsEqual<>(expected)
93+
);
94+
}
95+
}

0 commit comments

Comments
 (0)