Skip to content

Commit

Permalink
Ignore ci branches if PR has no pending builds
Browse files Browse the repository at this point in the history
  • Loading branch information
zentol committed Oct 10, 2021
1 parent 1d3d3c2 commit 81595c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/main/java/com/ververica/CiBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -70,6 +72,8 @@ public class CiBot implements Runnable, AutoCloseable {
private final int pollingIntervalInSeconds;
private final int backlogHours;

private final Set<Integer> pullRequestWithPendingBuilds = new HashSet<>();

public static void main(String[] args) throws Exception {
final Arguments arguments = new Arguments();
final JCommander jCommander = JCommander.newBuilder()
Expand Down Expand Up @@ -189,12 +193,19 @@ public void close() {

private void tick(Date lastUpdateTime) throws Exception {
final Map<Integer, Collection<String>> branchesByPrID = core.getBranches();
core.getPullRequests(lastUpdateTime)
core.getPullRequests(lastUpdateTime, pullRequestWithPendingBuilds)
.map(FunctionWithException.wrap(
core::processPullRequest,
(r, e) -> LOG.error("Error while processing pull request {}.", formatPullRequestID(r.getID()), e)))
.filter(Optional::isPresent)
.map(Optional::get)
.peek(ciReport -> {
if (Stream.concat(ciReport.getRequiredBuilds(), Stream.concat(ciReport.getUnknownBuilds(), ciReport.getPendingBuilds())).findAny().isPresent()) {
pullRequestWithPendingBuilds.add(ciReport.getPullRequestID());
} else {
pullRequestWithPendingBuilds.remove(ciReport.getPullRequestID());
}
})
.forEach(ConsumerWithException.wrap(
ciReport -> processCiReport(
ciReport,
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/ververica/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public Map<Integer, Collection<String>> getBranches() throws IOException {
return branchesByPrID;
}

public Stream<GithubPullRequest> getPullRequests(Date lastUpdatedAtCutoff) throws IOException {
public Stream<GithubPullRequest> getPullRequests(Date lastUpdatedAtCutoff, Set<Integer> pullRequestWithPendingBuilds) throws IOException {
LOG.info("Retrieving observed repository state ({}).", observedRepository);

Iterable<GithubPullRequest> recentlyUpdatedOpenPullRequests = gitHubActions.getRecentlyUpdatedOpenPullRequests(observedRepository, lastUpdatedAtCutoff);
Expand All @@ -229,8 +229,8 @@ public Stream<GithubPullRequest> getPullRequests(Date lastUpdatedAtCutoff) throw
Integer.parseInt(matcher.group(REGEX_GROUP_PULL_REQUEST_ID)),
Date.from(Instant.now()),
matcher.group(REGEX_GROUP_COMMIT_HASH)))
.filter(pr -> !pullRequestsToProcessByID.containsKey(pr.getID()))
.forEach(pr -> pullRequestsToProcessByID.put(pr.getID(), pr));
.filter(pr -> pullRequestWithPendingBuilds.contains(pr.getID()))
.forEach(pr -> pullRequestsToProcessByID.putIfAbsent(pr.getID(), pr));

return pullRequestsToProcessByID.values().stream();
}
Expand Down

0 comments on commit 81595c7

Please sign in to comment.