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: prefix event handlers with "on*" #653

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -27,12 +27,12 @@
import org.openjdk.skara.vcs.openjdk.Issue;

public interface PullRequestListener {
default void handleNewIssue(PullRequest pr, Issue issue) {
default void onNewIssue(PullRequest pr, Issue issue) {
}
default void handleRemovedIssue(PullRequest pr, Issue issue) {
default void onRemovedIssue(PullRequest pr, Issue issue) {
}
default void handleNewPullRequest(PullRequest pr) {
default void onNewPullRequest(PullRequest pr) {
}
default void handleIntegratedPullRequest(PullRequest pr, Hash hash) {
default void onIntegratedPullRequest(PullRequest pr, Hash hash) {
}
}
Original file line number Diff line number Diff line change
@@ -157,19 +157,19 @@ public boolean concurrentWith(WorkItem other) {
}

private void notifyNewIssue(String issueId) {
listeners.forEach(c -> c.handleNewIssue(pr, new Issue(issueId, "")));
listeners.forEach(c -> c.onNewIssue(pr, new Issue(issueId, "")));
}

private void notifyRemovedIssue(String issueId) {
listeners.forEach(c -> c.handleRemovedIssue(pr, new Issue(issueId, "")));
listeners.forEach(c -> c.onRemovedIssue(pr, new Issue(issueId, "")));
}

private void notifyNewPr(PullRequest pr) {
listeners.forEach(c -> c.handleNewPullRequest(pr));
listeners.forEach(c -> c.onNewPullRequest(pr));
}

private void notifyIntegratedPr(PullRequest pr, Hash hash) {
listeners.forEach(c -> c.handleIntegratedPullRequest(pr, hash));
listeners.forEach(c -> c.onIntegratedPullRequest(pr, hash));
}

@Override
Original file line number Diff line number Diff line change
@@ -29,13 +29,13 @@
import java.util.List;

public interface RepositoryListener {
default void handleCommits(HostedRepository repository, Repository localRepository, List<Commit> commits, Branch branch) throws NonRetriableException {
default void onNewCommits(HostedRepository repository, Repository localRepository, List<Commit> commits, Branch branch) throws NonRetriableException {
}
default void handleOpenJDKTagCommits(HostedRepository repository, Repository localRepository, List<Commit> commits, OpenJDKTag tag, Tag.Annotated annotated) throws NonRetriableException {
default void onNewOpenJDKTagCommits(HostedRepository repository, Repository localRepository, List<Commit> commits, OpenJDKTag tag, Tag.Annotated annotated) throws NonRetriableException {
}
default void handleTagCommit(HostedRepository repository, Repository localRepository, Commit commit, Tag tag, Tag.Annotated annotation) throws NonRetriableException {
default void onNewTagCommit(HostedRepository repository, Repository localRepository, Commit commit, Tag tag, Tag.Annotated annotation) throws NonRetriableException {
}
default void handleNewBranch(HostedRepository repository, Repository localRepository, List<Commit> commits, Branch parent, Branch branch) throws NonRetriableException {
default void onNewBranch(HostedRepository repository, Repository localRepository, List<Commit> commits, Branch parent, Branch branch) throws NonRetriableException {
}
String name();
}
Original file line number Diff line number Diff line change
@@ -84,12 +84,12 @@ private void handleNewRef(Repository localRepo, Reference ref, Collection<Refere
}
var branch = new Branch(ref.name());
var parent = new Branch(bestParent.getKey().name());
listener.handleNewBranch(repository, localRepo, bestParentCommits, parent, branch);
listener.onNewBranch(repository, localRepo, bestParentCommits, parent, branch);
}

private void handleUpdatedRef(Repository localRepo, Reference ref, List<Commit> commits, RepositoryListener listener) throws NonRetriableException {
var branch = new Branch(ref.name());
listener.handleCommits(repository, localRepo, commits, branch);
listener.onNewCommits(repository, localRepo, commits, branch);
}

private List<Throwable> handleRef(Repository localRepo, UpdateHistory history, Reference ref, Collection<Reference> allRefs) throws IOException {
@@ -208,7 +208,7 @@ private List<Throwable> handleTags(Repository localRepo, UpdateHistory history,

history.addTags(List.of(tag.tag()), listener.name());
try {
listener.handleOpenJDKTagCommits(repository, localRepo, commits, tag, annotation.orElse(null));
listener.onNewOpenJDKTagCommits(repository, localRepo, commits, tag, annotation.orElse(null));
} catch (NonRetriableException e) {
errors.add(e.cause());
} catch (RuntimeException e) {
@@ -230,7 +230,7 @@ private List<Throwable> handleTags(Repository localRepo, UpdateHistory history,

history.addTags(List.of(tag), listener.name());
try {
listener.handleTagCommit(repository, localRepo, commit.get(), tag, annotation.orElse(null));
listener.onNewTagCommit(repository, localRepo, commit.get(), tag, annotation.orElse(null));
} catch (NonRetriableException e) {
errors.add(e.cause());
} catch (RuntimeException e) {
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ public void attachTo(Emitter e) {
}

@Override
public void handleIntegratedPullRequest(PullRequest pr, Hash hash) {
public void onIntegratedPullRequest(PullRequest pr, Hash hash) {
var repository = pr.repository();
var commit = repository.commitMetadata(hash).orElseThrow(() ->
new IllegalStateException("Integrated commit " + hash +
@@ -115,7 +115,7 @@ public void handleIntegratedPullRequest(PullRequest pr, Hash hash) {
}

@Override
public void handleNewIssue(PullRequest pr, org.openjdk.skara.vcs.openjdk.Issue issue) {
public void onNewIssue(PullRequest pr, org.openjdk.skara.vcs.openjdk.Issue issue) {
var realIssue = issueProject.issue(issue.shortId());
if (realIssue.isEmpty()) {
log.warning("Pull request " + pr + " added unknown issue: " + issue.id());
@@ -135,7 +135,7 @@ public void handleNewIssue(PullRequest pr, org.openjdk.skara.vcs.openjdk.Issue i
}

@Override
public void handleRemovedIssue(PullRequest pr, org.openjdk.skara.vcs.openjdk.Issue issue) {
public void onRemovedIssue(PullRequest pr, org.openjdk.skara.vcs.openjdk.Issue issue) {
var realIssue = issueProject.issue(issue.shortId());
if (realIssue.isEmpty()) {
log.warning("Pull request " + pr + " removed unknown issue: " + issue.id());
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ public void attachTo(Emitter e) {
}

@Override
public void handleCommits(HostedRepository repository, Repository localRepository, List<Commit> commits, Branch branch) throws NonRetriableException {
public void onNewCommits(HostedRepository repository, Repository localRepository, List<Commit> commits, Branch branch) throws NonRetriableException {
try (var writer = new JsonWriter(path, repository.name())) {
for (var commit : commits) {
var json = commitToChanges(repository, localRepository, commit, defaultBuild);
@@ -94,7 +94,7 @@ public void handleCommits(HostedRepository repository, Repository localRepositor
}

@Override
public void handleOpenJDKTagCommits(HostedRepository repository, Repository localRepository, List<Commit> commits, OpenJDKTag tag, Tag.Annotated annotation) throws NonRetriableException {
public void onNewOpenJDKTagCommits(HostedRepository repository, Repository localRepository, List<Commit> commits, OpenJDKTag tag, Tag.Annotated annotation) throws NonRetriableException {
var build = String.format("b%02d", tag.buildNum());
try (var writer = new JsonWriter(path, repository.name())) {
var issues = new ArrayList<Issue>();
Original file line number Diff line number Diff line change
@@ -219,20 +219,20 @@ public void attachTo(Emitter e) {
}

@Override
public void handleCommits(HostedRepository repository, Repository localRepository, List<Commit> commits, Branch branch) throws NonRetriableException {
public void onNewCommits(HostedRepository repository, Repository localRepository, List<Commit> commits, Branch branch) throws NonRetriableException {
if (mode == Mode.PR) {
commits = filterPrCommits(repository, localRepository, commits, branch);
}
sendCombinedCommits(repository, commits, branch);
}

@Override
public void handleOpenJDKTagCommits(HostedRepository repository, Repository localRepository, List<Commit> commits, OpenJDKTag tag, Tag.Annotated annotation) throws NonRetriableException {
public void onNewOpenJDKTagCommits(HostedRepository repository, Repository localRepository, List<Commit> commits, OpenJDKTag tag, Tag.Annotated annotation) throws NonRetriableException {
if (!reportNewTags) {
return;
}
if (!reportNewBuilds) {
handleTagCommit(repository, localRepository, commits.get(commits.size() - 1), tag.tag(), annotation);
onNewTagCommit(repository, localRepository, commits.get(commits.size() - 1), tag.tag(), annotation);
return;
}
var writer = new StringWriter();
@@ -275,7 +275,7 @@ public void handleOpenJDKTagCommits(HostedRepository repository, Repository loca
}

@Override
public void handleTagCommit(HostedRepository repository, Repository localRepository, Commit commit, Tag tag, Tag.Annotated annotation) throws NonRetriableException {
public void onNewTagCommit(HostedRepository repository, Repository localRepository, Commit commit, Tag tag, Tag.Annotated annotation) throws NonRetriableException {
if (!reportNewTags) {
return;
}
@@ -327,7 +327,7 @@ private String newBranchSubject(HostedRepository repository, Repository localRep
}

@Override
public void handleNewBranch(HostedRepository repository, Repository localRepository, List<Commit> commits, Branch parent, Branch branch) throws NonRetriableException {
public void onNewBranch(HostedRepository repository, Repository localRepository, List<Commit> commits, Branch parent, Branch branch) throws NonRetriableException {
if (!reportNewBranches) {
return;
}
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ public void attachTo(Emitter e) {
}

@Override
public void handleNewPullRequest(PullRequest pr) {
public void onNewPullRequest(PullRequest pr) {
if (prWebhook == null) {
return;
}
@@ -71,10 +71,10 @@ public void handleNewPullRequest(PullRequest pr) {
}

@Override
public void handleCommits(HostedRepository repository,
Repository localRepository,
List<Commit> commits,
Branch branch) throws NonRetriableException {
public void onNewCommits(HostedRepository repository,
Repository localRepository,
List<Commit> commits,
Branch branch) throws NonRetriableException {
if (commitWebhook == null) {
return;
}
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ private static class TestRepositoryListener implements Notifier, RepositoryListe
}

@Override
public void handleCommits(HostedRepository repository, Repository localRepository, List<Commit> commits,
public void onNewCommits(HostedRepository repository, Repository localRepository, List<Commit> commits,
Branch branch) throws NonRetriableException {
updateCount++;
if (shouldFail) {
@@ -63,19 +63,19 @@ public void handleCommits(HostedRepository repository, Repository localRepositor
}

@Override
public void handleOpenJDKTagCommits(HostedRepository repository, Repository localRepository,
public void onNewOpenJDKTagCommits(HostedRepository repository, Repository localRepository,
List<Commit> commits, OpenJDKTag tag, Tag.Annotated annotated) {
throw new RuntimeException("unexpected");
}

@Override
public void handleTagCommit(HostedRepository repository, Repository localRepository, Commit commit, Tag tag,
public void onNewTagCommit(HostedRepository repository, Repository localRepository, Commit commit, Tag tag,
Tag.Annotated annotation) {
throw new RuntimeException("unexpected");
}

@Override
public void handleNewBranch(HostedRepository repository, Repository localRepository, List<Commit> commits,
public void onNewBranch(HostedRepository repository, Repository localRepository, List<Commit> commits,
Branch parent, Branch branch) {
throw new RuntimeException("unexpected");
}