Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that the notifier looks at both open and closed PRs #659

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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);