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

notify: rename PullRequestIssues to PullRequestState #640

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
@@ -38,23 +38,23 @@ public class NotifyBot implements Bot {
private final Pattern branches;
private final StorageBuilder<UpdatedTag> tagStorageBuilder;
private final StorageBuilder<UpdatedBranch> branchStorageBuilder;
private final StorageBuilder<PullRequestIssues> prIssuesStorageBuilder;
private final StorageBuilder<PullRequestState> prStateStorageBuilder;
private final List<RepositoryUpdateConsumer> updaters;
private final List<PullRequestUpdateConsumer> prUpdaters;
private final PullRequestUpdateCache updateCache;
private final Set<String> readyLabels;
private final Map<String, Pattern> readyComments;

NotifyBot(HostedRepository repository, Path storagePath, Pattern branches, StorageBuilder<UpdatedTag> tagStorageBuilder,
StorageBuilder<UpdatedBranch> branchStorageBuilder, StorageBuilder<PullRequestIssues> prIssuesStorageBuilder,
StorageBuilder<UpdatedBranch> branchStorageBuilder, StorageBuilder<PullRequestState> prStateStorageBuilder,
List<RepositoryUpdateConsumer> updaters, List<PullRequestUpdateConsumer> prUpdaters,
Set<String> readyLabels, Map<String, Pattern> readyComments) {
this.repository = repository;
this.storagePath = storagePath;
this.branches = branches;
this.tagStorageBuilder = tagStorageBuilder;
this.branchStorageBuilder = branchStorageBuilder;
this.prIssuesStorageBuilder = prIssuesStorageBuilder;
this.prStateStorageBuilder = prStateStorageBuilder;
this.updaters = updaters;
this.prUpdaters = prUpdaters;
this.updateCache = new PullRequestUpdateCache();
@@ -112,7 +112,7 @@ public List<WorkItem> getPeriodicItems() {
if (!isReady(pr)) {
continue;
}
ret.add(new PullRequestWorkItem(pr, prIssuesStorageBuilder, prUpdaters, e -> updateCache.invalidate(pr)));
ret.add(new PullRequestWorkItem(pr, prStateStorageBuilder, prUpdaters, e -> updateCache.invalidate(pr)));
}
}

@@ -35,7 +35,7 @@ public class NotifyBotBuilder {
private Pattern branches;
private StorageBuilder<UpdatedTag> tagStorageBuilder;
private StorageBuilder<UpdatedBranch> branchStorageBuilder;
private StorageBuilder<PullRequestIssues> prIssuesStorageBuilder;
private StorageBuilder<PullRequestState> prStateStorageBuilder;
private List<RepositoryUpdateConsumer> updaters = List.of();
private List<PullRequestUpdateConsumer> prUpdaters = List.of();
private Set<String> readyLabels = Set.of();
@@ -66,8 +66,8 @@ public NotifyBotBuilder branchStorageBuilder(StorageBuilder<UpdatedBranch> branc
return this;
}

public NotifyBotBuilder prIssuesStorageBuilder(StorageBuilder<PullRequestIssues> prIssuesStorageBuilder) {
this.prIssuesStorageBuilder = prIssuesStorageBuilder;
public NotifyBotBuilder prStateStorageBuilder(StorageBuilder<PullRequestState> prStateStorageBuilder) {
this.prStateStorageBuilder = prStateStorageBuilder;
return this;
}

@@ -92,6 +92,6 @@ public NotifyBotBuilder readyComments(Map<String, Pattern> readyComments) {
}

public NotifyBot build() {
return new NotifyBot(repository, storagePath, branches, tagStorageBuilder, branchStorageBuilder, prIssuesStorageBuilder, updaters, prUpdaters, readyLabels, readyComments);
return new NotifyBot(repository, storagePath, branches, tagStorageBuilder, branchStorageBuilder, prStateStorageBuilder, updaters, prUpdaters, readyLabels, readyComments);
}
}
}
@@ -122,15 +122,15 @@ public List<Bot> create(BotConfiguration configuration) {
.remoteRepository(databaseRepo, databaseRef, databaseName, databaseEmail, "Added tag for " + repoName);
var branchStorageBuilder = new StorageBuilder<UpdatedBranch>(baseName + ".branches.txt")
.remoteRepository(databaseRepo, databaseRef, databaseName, databaseEmail, "Added branch hash for " + repoName);
var issueStorageBuilder = new StorageBuilder<PullRequestIssues>(baseName + ".prissues.txt")
var prStateStorageBuilder = new StorageBuilder<PullRequestState>(baseName + ".prissues.txt")
.remoteRepository(databaseRepo, databaseRef, databaseName, databaseEmail, "Added pull request issue info for " + repoName);
var bot = NotifyBot.newBuilder()
.repository(configuration.repository(repoName))
.storagePath(configuration.storageFolder())
.branches(branchPattern)
.tagStorageBuilder(tagStorageBuilder)
.branchStorageBuilder(branchStorageBuilder)
.prIssuesStorageBuilder(issueStorageBuilder)
.prStateStorageBuilder(prStateStorageBuilder)
.updaters(updaters)
.prUpdaters(prUpdaters)
.readyLabels(readyLabels)
@@ -26,16 +26,16 @@

import java.util.*;

public class PullRequestIssues {
class PullRequestState {
private final String prId;
private final Set<String> issueIds;

PullRequestIssues(PullRequest pr, Set<String> issueIds) {
PullRequestState(PullRequest pr, Set<String> issueIds) {
this.prId = pr.repository().id() + ":" + pr.id();
this.issueIds = issueIds;
}

PullRequestIssues(String prId, Set<String> issueIds) {
PullRequestState(String prId, Set<String> issueIds) {
this.prId = prId;
this.issueIds = issueIds;
}
@@ -50,7 +50,7 @@ public Set<String> issueIds() {

@Override
public String toString() {
return "PullRequestIssues{" +
return "PullRequestState{" +
"prId='" + prId + '\'' +
", issueIds=" + issueIds +
'}';
@@ -64,7 +64,7 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
PullRequestIssues that = (PullRequestIssues) o;
var that = (PullRequestState) o;
return prId.equals(that.prId) &&
issueIds.equals(that.issueIds);
}
@@ -36,41 +36,41 @@

public class PullRequestWorkItem implements WorkItem {
private final PullRequest pr;
private final StorageBuilder<PullRequestIssues> prIssuesStorageBuilder;
private final StorageBuilder<PullRequestState> prStateStorageBuilder;
private final List<PullRequestUpdateConsumer> pullRequestUpdateConsumers;
private final Consumer<RuntimeException> errorHandler;

PullRequestWorkItem(PullRequest pr, StorageBuilder<PullRequestIssues> prIssuesStorageBuilder, List<PullRequestUpdateConsumer> pullRequestUpdateConsumers, Consumer<RuntimeException> errorHandler) {
PullRequestWorkItem(PullRequest pr, StorageBuilder<PullRequestState> prStateStorageBuilder, List<PullRequestUpdateConsumer> pullRequestUpdateConsumers, Consumer<RuntimeException> errorHandler) {
this.pr = pr;
this.prIssuesStorageBuilder = prIssuesStorageBuilder;
this.prStateStorageBuilder = prStateStorageBuilder;
this.pullRequestUpdateConsumers = pullRequestUpdateConsumers;
this.errorHandler = errorHandler;
}

private Set<PullRequestIssues> loadPrIssues(String current) {
private Set<PullRequestState> deserializePrState(String current) {
if (current.isBlank()) {
return Set.of();
}
var data = JSON.parse(current);
return data.stream()
.map(JSONValue::asObject)
.map(obj -> new PullRequestIssues(obj.get("pr").asString(), obj.get("issues").stream()
.map(JSONValue::asString)
.collect(Collectors.toSet())))
.map(obj -> new PullRequestState(obj.get("pr").asString(), obj.get("issues").stream()
.map(JSONValue::asString)
.collect(Collectors.toSet())))
.collect(Collectors.toSet());
}

private String serializePrIssues(Collection<PullRequestIssues> added, Set<PullRequestIssues> existing) {
private String serializePrState(Collection<PullRequestState> added, Set<PullRequestState> existing) {
var addedPrs = added.stream()
.map(PullRequestIssues::prId)
.map(PullRequestState::prId)
.collect(Collectors.toSet());
var nonReplaced = existing.stream()
.filter(item -> !addedPrs.contains(item.prId()))
.collect(Collectors.toSet());

var entries = Stream.concat(nonReplaced.stream(),
added.stream())
.sorted(Comparator.comparing(PullRequestIssues::prId))
.sorted(Comparator.comparing(PullRequestState::prId))
.map(pr -> JSON.object().put("pr", pr.prId()).put("issues", new JSONArray(
pr.issueIds().stream()
.map(JSON::of)
@@ -124,13 +124,13 @@ private void notifyNewPr(PullRequest pr) {
@Override
public void run(Path scratchPath) {
var historyPath = scratchPath.resolve("notify").resolve("history");
var storage = prIssuesStorageBuilder
.serializer(this::serializePrIssues)
.deserializer(this::loadPrIssues)
var storage = prStateStorageBuilder
.serializer(this::serializePrState)
.deserializer(this::deserializePrState)
.materialize(historyPath);

var issues = parseIssues();
var prIssues = new PullRequestIssues(pr, issues);
var prIssues = new PullRequestState(pr, issues);
var current = storage.current();
if (current.contains(prIssues)) {
// Already up to date
@@ -48,7 +48,7 @@ void testIssueIdempotence(TestInfo testInfo) throws IOException {

var tagStorage = createTagStorage(repo);
var branchStorage = createBranchStorage(repo);
var prIssuesStorage = createPullRequestIssuesStorage(repo);
var prStateStorage = createPullRequestStateStorage(repo);
var storageFolder = tempFolder.path().resolve("storage");

var issueProject = credentials.getIssueProject();
@@ -64,7 +64,7 @@ void testIssueIdempotence(TestInfo testInfo) throws IOException {
.branches(Pattern.compile("master"))
.tagStorageBuilder(tagStorage)
.branchStorageBuilder(branchStorage)
.prIssuesStorageBuilder(prIssuesStorage)
.prStateStorageBuilder(prStateStorage)
.updaters(List.of(updater))
.build();

@@ -116,7 +116,7 @@ void testPullRequest(TestInfo testInfo) throws IOException {

var tagStorage = createTagStorage(repo);
var branchStorage = createBranchStorage(repo);
var prIssuesStorage = createPullRequestIssuesStorage(repo);
var prStateStorage = createPullRequestStateStorage(repo);
var storageFolder = tempFolder.path().resolve("storage");

var issueProject = credentials.getIssueProject();
@@ -132,7 +132,7 @@ void testPullRequest(TestInfo testInfo) throws IOException {
.branches(Pattern.compile("master"))
.tagStorageBuilder(tagStorage)
.branchStorageBuilder(branchStorage)
.prIssuesStorageBuilder(prIssuesStorage)
.prStateStorageBuilder(prStateStorage)
.prUpdaters(List.of(updater))
.readyLabels(Set.of("rfr"))
.readyComments(Map.of(reviewer.forge().currentUser().userName(), Pattern.compile("This is now ready")))
@@ -217,7 +217,7 @@ void testPullRequestNoReview(TestInfo testInfo) throws IOException {

var tagStorage = createTagStorage(repo);
var branchStorage = createBranchStorage(repo);
var prIssuesStorage = createPullRequestIssuesStorage(repo);
var prStateStorage = createPullRequestStateStorage(repo);
var storageFolder = tempFolder.path().resolve("storage");

var issueProject = credentials.getIssueProject();
@@ -234,7 +234,7 @@ void testPullRequestNoReview(TestInfo testInfo) throws IOException {
.branches(Pattern.compile("master"))
.tagStorageBuilder(tagStorage)
.branchStorageBuilder(branchStorage)
.prIssuesStorageBuilder(prIssuesStorage)
.prStateStorageBuilder(prStateStorage)
.prUpdaters(List.of(updater)).readyLabels(Set.of("rfr"))
.readyComments(Map.of(reviewer.forge().currentUser().userName(), Pattern.compile("This is now ready")))
.build();
@@ -276,7 +276,7 @@ void testPullRequestPROnly(TestInfo testInfo) throws IOException {

var tagStorage = createTagStorage(repo);
var branchStorage = createBranchStorage(repo);
var prIssuesStorage = createPullRequestIssuesStorage(repo);
var prStateStorage = createPullRequestStateStorage(repo);
var storageFolder = tempFolder.path().resolve("storage");

var issueProject = credentials.getIssueProject();
@@ -293,7 +293,7 @@ void testPullRequestPROnly(TestInfo testInfo) throws IOException {
.branches(Pattern.compile(".*"))
.tagStorageBuilder(tagStorage)
.branchStorageBuilder(branchStorage)
.prIssuesStorageBuilder(prIssuesStorage)
.prStateStorageBuilder(prStateStorage)
.updaters(List.of(updater))
.prUpdaters(List.of(updater))
.build();
@@ -57,7 +57,7 @@ void testJsonUpdaterBranch(TestInfo testInfo) throws IOException {

var tagStorage = createTagStorage(repo);
var branchStorage = createBranchStorage(repo);
var prIssuesStorage = createPullRequestIssuesStorage(repo);
var prStateStorage = createPullRequestStateStorage(repo);
var jsonFolder = tempFolder.path().resolve("json");
Files.createDirectory(jsonFolder);
var storageFolder = tempFolder.path().resolve("storage");
@@ -69,7 +69,7 @@ void testJsonUpdaterBranch(TestInfo testInfo) throws IOException {
.branches(Pattern.compile("master"))
.tagStorageBuilder(tagStorage)
.branchStorageBuilder(branchStorage)
.prIssuesStorageBuilder(prIssuesStorage)
.prStateStorageBuilder(prStateStorage)
.updaters(List.of(updater))
.build();

@@ -105,7 +105,7 @@ void testJsonUpdaterTag(TestInfo testInfo) throws IOException {

var tagStorage = UpdaterTests.createTagStorage(repo);
var branchStorage = createBranchStorage(repo);
var prIssuesStorage = createPullRequestIssuesStorage(repo);
var prStateStorage = createPullRequestStateStorage(repo);
var jsonFolder = tempFolder.path().resolve("json");
Files.createDirectory(jsonFolder);
var storageFolder =tempFolder.path().resolve("storage");
@@ -117,7 +117,7 @@ void testJsonUpdaterTag(TestInfo testInfo) throws IOException {
.branches(Pattern.compile("master"))
.tagStorageBuilder(tagStorage)
.branchStorageBuilder(branchStorage)
.prIssuesStorageBuilder(prIssuesStorage)
.prStateStorageBuilder(prStateStorage)
.updaters(List.of(updater))
.build();