Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed May 24, 2024
2 parents f9137ea + f6f1dab commit 332bceb
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ These are the parameters you can use/override:
* `min_lines`: Minimal amount of lines in the pull request to get analyzed
by this action, pull requests with fewer lines than provided `min_size`
won't be processed.
* `skip_authors`: GitHub logins of authors, whose pull requests you want to
skip from analyzing. By default, `renovatebot` and `dependabot` are ignored.

### Analysis Method

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ inputs:
min_lines:
description: 'Minimal amount of lines in the pull request to get analyzed by this action'
required: false
skip_authors:
description: 'GitHub logins of authors, whose pull requests you want to skip from analyzing'
default: '["renovate", "dependabot"]'
required: false
runs:
using: 'docker'
image: 'Dockerfile'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public final class SkipAuthors implements Scalar<Collection<String>> {
*
* @param skip Authors which will be skipped.
*/
SkipAuthors(final String... skip) {
public SkipAuthors(final String... skip) {
this(new ListOf<>(skip));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public final void exec(final Pull pull, final String param) throws Exception {
if (this.mentions.value().contains(author)) {
Logger.info(
this,
"Skipping pull request, since author '%s' is excluded",
"Skipping pull request #%d, since author @%s is excluded",
pull.number(),
author
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@
import com.jcabi.log.Logger;
import git.tracehub.codereview.action.extentions.PullRequestExtension;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import nl.altindag.log.LogCaptor;
import org.cactoos.list.ListOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.core.IsEqual;
import org.hamcrest.core.IsNot;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -75,4 +79,31 @@ void processesAuthorMentioned(final Pull pull) throws Exception {
)
);
}

@Test
@ExtendWith(PullRequestExtension.class)
void addsLogsWhenSkips(final Pull pull) throws Exception {
final LogCaptor capt = LogCaptor.forClass(SkipIfMentioned.class);
final String skip = "jeff";
new SkipIfMentioned(
new SkipAuthors(skip),
(incoming, param) -> Logger.info(SkipIfMentioned.class, "Boom!")
).exec(pull, "");
final List<String> logs = capt.getInfoLogs();
final List<String> expected = new ListOf<>(
String.format(
"Skipping pull request #%d, since author @%s is excluded",
pull.number(),
skip
)
);
MatcherAssert.assertThat(
String.format(
"Received logs (%s) do not match with expected (%s)",
logs, expected
),
logs,
new IsEqual<>(expected)
);
}
}
95 changes: 95 additions & 0 deletions src/test/java/it/SkipIfMentionedITCase.java
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 it;

import com.jcabi.github.Coordinates;
import com.jcabi.github.Github;
import com.jcabi.github.Pull;
import com.yegor256.WeAreOnline;
import git.tracehub.codereview.action.AnalysisRoutine;
import git.tracehub.codereview.action.MinLines;
import git.tracehub.codereview.action.SkipAuthors;
import git.tracehub.codereview.action.SkipIfMentioned;
import git.tracehub.codereview.action.SkipIfTooSmall;
import git.tracehub.codereview.action.github.GhIdentity;
import io.github.h1alexbel.ghquota.Quota;
import java.util.List;
import nl.altindag.log.LogCaptor;
import org.cactoos.list.ListOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.core.IsEqual;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

/**
* Integration test case for {@link SkipIfMentioned}.
*
* @since 0.2.0
*/
final class SkipIfMentionedITCase {

@Test
@Tag("simulation")
@ExtendWith({WeAreOnline.class, Quota.class})
void skipsAuthorPull() throws Exception {
final LogCaptor capt = LogCaptor.forClass(SkipIfMentioned.class);
final Github github = new GhIdentity().value();
final Pull pull = github.repos()
.get(new Coordinates.Simple("tracehubpm/test"))
.pulls()
.get(5);
final String token = System.getProperty("INPUT_GITHUB_TOKEN");
final String skip = "h1alexbel";
new SkipIfMentioned(
new SkipAuthors(skip),
new SkipIfTooSmall(
new MinLines(),
new AnalysisRoutine(
token,
github.users().self().login(),
System.getenv().get("INPUT_DEEPINFRA_TOKEN")
)
)
).exec(
pull,
System.getenv().get("INPUT_DEEPINFRA_MODEL")
);
final List<String> logs = capt.getInfoLogs();
final List<String> expected = new ListOf<>(
String.format(
"Skipping pull request #%d, since author @%s is excluded",
pull.number(), skip
)
);
MatcherAssert.assertThat(
String.format(
"Received logs (%s) do not match with expected (%s)",
logs, expected
),
logs,
new IsEqual<>(expected)
);
}
}

0 comments on commit 332bceb

Please sign in to comment.