Skip to content
Permalink
Browse files
Ensure that the notifier looks at both open and closed PRs
Reviewed-by: ehelin
  • Loading branch information
rwestberg committed Jun 12, 2020
1 parent 96088f4 commit b6390d829ac011d372b88d89f48f13ddb71642a0
@@ -27,6 +27,7 @@
import org.openjdk.skara.storage.StorageBuilder;

import java.nio.file.Path;
import java.time.*;
import java.util.*;
import java.util.logging.Logger;
import java.util.regex.Pattern;
@@ -46,6 +47,8 @@ public class NotifyBot implements Bot, Emitter {
private final Map<String, Pattern> readyComments;
private final String integratorId;

private ZonedDateTime lastFullUpdate;

NotifyBot(HostedRepository repository, Path storagePath, Pattern branches, StorageBuilder<UpdatedTag> tagStorageBuilder,
StorageBuilder<UpdatedBranch> branchStorageBuilder, StorageBuilder<PullRequestState> prStateStorageBuilder,
Set<String> readyLabels, Map<String, Pattern> readyComments, String integratorId) {
@@ -113,9 +116,19 @@ public String toString() {
@Override
public List<WorkItem> getPeriodicItems() {
var ret = new LinkedList<WorkItem>();
List<PullRequest> prs;

// Fetch all open pull requests periodically, and just the recently updated ones in between
if (lastFullUpdate == null || lastFullUpdate.isBefore(ZonedDateTime.now().minus(Duration.ofMinutes(10)))) {
lastFullUpdate = ZonedDateTime.now();
log.info("Fetching all open pull requests");
prs = repository.pullRequests();
} else {
log.info("Fetching recently updated pull requests (open and closed)");
prs = repository.pullRequests(ZonedDateTime.now().minus(Duration.ofDays(14)));
}

// Pull request events
var prs = repository.pullRequests();
for (var pr : prs) {
if (updateCache.needsUpdate(pr)) {
if (!isReady(pr)) {
@@ -23,7 +23,8 @@
package org.openjdk.skara.bots.notify.issue;

import org.junit.jupiter.api.*;
import org.openjdk.skara.bots.notify.*;
import org.openjdk.skara.bots.notify.NotifyBot;
import org.openjdk.skara.issuetracker.Issue;
import org.openjdk.skara.json.JSON;
import org.openjdk.skara.test.*;

@@ -323,6 +324,7 @@ void testPullRequestPROnly(TestInfo testInfo) throws IOException {
// Simulate integration
pr.addComment("Pushed as commit " + editHash.hex() + ".");
pr.addLabel("integrated");
pr.setState(Issue.State.CLOSED);
localRepo.push(editHash, repo.url(), "other");
TestBotRunner.runPeriodicItems(notifyBot);

0 comments on commit b6390d8

Please sign in to comment.