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

218: Enforce check on approval of CSRs #385

Closed
wants to merge 3 commits 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
@@ -37,6 +37,7 @@ module {

dependencies {
implementation project(':bots:pr')
implementation project(':bots:csr')
implementation project(':bots:hgbridge')
implementation project(':bots:forward')
implementation project(':bots:notify')
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

module {
name = 'org.openjdk.skara.bots.csr'
test {
requires 'org.junit.jupiter.api'
requires 'org.openjdk.skara.test'
opens 'org.openjdk.skara.bots.csr' to 'org.junit.platform.commons'
}
}

dependencies {
implementation project(':host')
implementation project(':bot')
implementation project(':forge')
implementation project(':issuetracker')
implementation project(':census')
implementation project(':ci')
implementation project(':json')
implementation project(':vcs')

testImplementation project(':test')
}
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
module org.openjdk.skara.bots.csr {
requires org.openjdk.skara.bot;
requires org.openjdk.skara.vcs;
requires org.openjdk.skara.forge;
requires org.openjdk.skara.issuetracker;
requires java.logging;

provides org.openjdk.skara.bot.BotFactory with org.openjdk.skara.bots.csr.CSRBotFactory;
}
@@ -0,0 +1,102 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package org.openjdk.skara.bots.csr;

import org.openjdk.skara.bot.*;
import org.openjdk.skara.forge.HostedRepository;
import org.openjdk.skara.forge.PullRequest;
import org.openjdk.skara.issuetracker.IssueProject;
import org.openjdk.skara.issuetracker.Issue;

import java.nio.file.Path;
import java.util.List;
import java.util.logging.Logger;

class CSRBot implements Bot, WorkItem {
private final static String CSR_LABEL = "csr";
private final Logger log = Logger.getLogger("org.openjdk.skara.bots");;
private final HostedRepository repo;
private final IssueProject project;

CSRBot(HostedRepository repo, IssueProject project) {
this.repo = repo;
this.project = project;
}

@Override
public boolean concurrentWith(WorkItem other) {
if (!(other instanceof CSRBot)) {
return false;
}

return !repo.webUrl().equals(((CSRBot) other).repo.webUrl());
}

private String describe(PullRequest pr) {
return repo.name() + "#" + pr.id();
}

@Override
public void run(Path scratchPath) {
for (var pr : repo.pullRequests()) {
log.info("Checking CSR label for " + describe(pr) + "...");
if (pr.labels().contains(CSR_LABEL)) {
var issue = org.openjdk.skara.vcs.openjdk.Issue.fromString(pr.title());
if (issue.isEmpty()) {
log.info("No issue found in title for " + describe(pr));
continue;
}
var jbsIssue = project.issue(issue.get().id());
if (jbsIssue.isEmpty()) {
log.info("No issue found in JBS for " + describe(pr));
continue;
}

for (var link : jbsIssue.get().links()) {
var relationship = link.relationship();
if (relationship.isPresent() && relationship.get().equals("csr for")) {
var csr = link.issue().orElseThrow(
() -> new IllegalStateException("Link with title 'csr for' does not contain issue")
);
var resolution = csr.properties().get("resolution").get("name").asString();
log.info("Found CSR for " + describe(pr));
if (csr.state() == Issue.State.CLOSED && resolution.equals("Approved")) {
log.info("CSR closed and approved for " + repo.name() + "#" + pr.id() + ", removing csr label");
pr.removeLabel(CSR_LABEL);
}
}
}
}
}
}

@Override
public String toString() {
return "CSRBot@(" + repo.name() + ")";
}

@Override
public List<WorkItem> getPeriodicItems() {
return List.of(this);
}
}
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package org.openjdk.skara.bots.csr;

import org.openjdk.skara.bot.*;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

public class CSRBotFactory implements BotFactory {
private final Logger log = Logger.getLogger("org.openjdk.skara.bots");;

@Override
public String name() {
return "csr";
}

@Override
public List<Bot> create(BotConfiguration configuration) {
var ret = new ArrayList<Bot>();
var specific = configuration.specific();

for (var project : specific.get("projects").asArray()) {
var repo = configuration.repository(project.get("repository").asString());
var issues = configuration.issueProject(project.get("issues").asString());
log.info("Setting up csr bot for " + repo.name());
ret.add(new CSRBot(repo, issues));
}

return ret;
}
}