Skip to content

Commit

Permalink
notify: prefix event handlers with "on*"
Browse files Browse the repository at this point in the history
  • Loading branch information
edvbld committed Jun 10, 2020
1 parent 66b93ca commit 6d17129
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 35 deletions.
Expand Up @@ -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) {
}
}
Expand Up @@ -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
Expand Down
Expand Up @@ -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();
}
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
Expand Up @@ -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 +
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down
Expand Up @@ -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);
Expand All @@ -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>();
Expand Down
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
Expand Up @@ -53,7 +53,7 @@ public void attachTo(Emitter e) {
}

@Override
public void handleNewPullRequest(PullRequest pr) {
public void onNewPullRequest(PullRequest pr) {
if (prWebhook == null) {
return;
}
Expand All @@ -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;
}
Expand Down
Expand Up @@ -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) {
Expand All @@ -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");
}
Expand Down

0 comments on commit 6d17129

Please sign in to comment.