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

445: The issue notifier should not process commits for downstream projects #688

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
@@ -46,11 +46,12 @@ class IssueNotifier implements Notifier, PullRequestListener, RepositoryListener
private final boolean setFixVersion;
private final Map<String, String> fixVersions;
private final JbsBackport jbsBackport;
private final boolean prOnly;

private final Logger log = Logger.getLogger("org.openjdk.skara.bots.notify");

IssueNotifier(IssueProject issueProject, boolean reviewLink, URI reviewIcon, boolean commitLink, URI commitIcon,
boolean setFixVersion, Map<String, String> fixVersions, JbsBackport jbsBackport) {
boolean setFixVersion, Map<String, String> fixVersions, JbsBackport jbsBackport, boolean prOnly) {
this.issueProject = issueProject;
this.reviewLink = reviewLink;
this.reviewIcon = reviewIcon;
@@ -59,6 +60,7 @@ class IssueNotifier implements Notifier, PullRequestListener, RepositoryListener
this.setFixVersion = setFixVersion;
this.fixVersions = fixVersions;
this.jbsBackport = jbsBackport;
this.prOnly = prOnly;
}

static IssueNotifierBuilder newBuilder() {
@@ -88,7 +90,9 @@ private Optional<String> findIssueUsername(CommitMetadata commit) {
@Override
public void attachTo(Emitter e) {
e.registerPullRequestListener(this);
e.registerRepositoryListener(this);
if (!prOnly) {
e.registerRepositoryListener(this);
}
}

@Override
@@ -117,6 +121,20 @@ public void onIntegratedPullRequest(PullRequest pr, Hash hash) {
}
issue.addLink(linkBuilder.build());
}

// If prOnly is false, this is instead done when processing commits
if (prOnly) {
if (issue.state() == Issue.State.OPEN) {
issue.setState(Issue.State.RESOLVED);
if (issue.assignees().isEmpty()) {
var username = findIssueUsername(commit);
if (username.isPresent()) {
var assignee = issueProject.issueTracker().user(username.get());
assignee.ifPresent(hostUser -> issue.setAssignees(List.of(hostUser)));
}
}
}
}
}
}

@@ -37,6 +37,7 @@ class IssueNotifierBuilder {
private Map<String, String> fixVersions = null;
private JbsVault vault = null;
private String securityLevel = null;
private boolean prOnly = true;

IssueNotifierBuilder issueProject(IssueProject issueProject) {
this.issueProject = issueProject;
@@ -64,6 +65,7 @@ IssueNotifierBuilder commitIcon(URI commitIcon) {
}

public IssueNotifierBuilder setFixVersion(boolean setFixVersion) {
prOnly = false;
this.setFixVersion = setFixVersion;
return this;
}
@@ -83,9 +85,14 @@ public IssueNotifierBuilder securityLevel(String securityLevel) {
return this;
}

public IssueNotifierBuilder prOnly(boolean prOnly) {
this.prOnly = prOnly;
return this;
}

IssueNotifier build() {
var jbsBackport = new JbsBackport(issueProject.webUrl(), vault, securityLevel);
return new IssueNotifier(issueProject, reviewLink, reviewIcon, commitLink, commitIcon,
setFixVersion, fixVersions, jbsBackport);
setFixVersion, fixVersions, jbsBackport, prOnly);
}
}
@@ -63,6 +63,10 @@ public Notifier create(BotConfiguration botConfiguration, JSONObject notifierCon
builder.securityLevel(notifierConfiguration.get("security").asString());
}

if (notifierConfiguration.contains("pronly")) {
builder.prOnly(notifierConfiguration.get("pronly").asBoolean());
}

return builder.build();
}
}
@@ -314,29 +314,11 @@ void testPullRequestPROnly(TestInfo testInfo) throws IOException {
credentials.commitLock(localRepo);
localRepo.pushAll(repo.url());

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

var issueProject = credentials.getIssueProject();
var storageFolder = tempFolder.path().resolve("storage");
var reviewIcon = URI.create("http://www.example.com/review.png");
var notifyBot = NotifyBot.newBuilder()
.repository(repo)
.storagePath(storageFolder)
.branches(Pattern.compile(".*"))
.tagStorageBuilder(tagStorage)
.branchStorageBuilder(branchStorage)
.prStateStorageBuilder(prStateStorage)
.integratorId(repo.forge().currentUser().id())
.build();
var updater = IssueNotifier.newBuilder()
.issueProject(issueProject)
.reviewIcon(reviewIcon)
.commitLink(true)
.commitIcon(reviewIcon)
.build();
updater.attachTo(notifyBot);
var jbsNotifierConfig = JSON.object().put("reviews", JSON.object().put("icon", reviewIcon.toString()));
var notifyBot = testBotBuilder(repo, issueProject, storageFolder, jbsNotifierConfig).create("notify", JSON.object());

// Initialize history
localRepo.push(localRepo.resolve("master").orElseThrow(), repo.url(), "other");
@@ -377,6 +359,9 @@ void testPullRequestPROnly(TestInfo testInfo) throws IOException {
updatedIssue = issueProject.issue(issue.id()).orElseThrow();
links = updatedIssue.links();
assertEquals(2, links.size());

// And no comments should have been made
assertEquals(0, issue.comments().size());
}
}