diff --git a/bots/pr/src/main/java/org/openjdk/skara/bots/pr/CSRCommand.java b/bots/pr/src/main/java/org/openjdk/skara/bots/pr/CSRCommand.java index 3dfe59d5a..5c33aadf2 100644 --- a/bots/pr/src/main/java/org/openjdk/skara/bots/pr/CSRCommand.java +++ b/bots/pr/src/main/java/org/openjdk/skara/bots/pr/CSRCommand.java @@ -34,7 +34,7 @@ public class CSRCommand implements CommandHandler { private static final String CSR_LABEL = "csr"; private static void showHelp(PrintWriter writer) { - writer.println("usage: `/csr [unneeded]`, requires that the issue the pull request links to an approved [CSR](https://wiki.openjdk.java.net/display/csr/Main) request."); + writer.println("usage: `/csr [needed|unneeded]`, requires that the issue the pull request refers to links to an approved [CSR](https://wiki.openjdk.java.net/display/csr/Main) request."); } private static void csrReply(PrintWriter writer) { @@ -64,14 +64,15 @@ public void handle(PullRequestBot bot, PullRequest pr, CensusInstance censusInst var labels = pr.labels(); - if (command.args().trim().toLowerCase().equals("unneeded")) { + var cmd = command.args().trim().toLowerCase(); + if (cmd.equals("unneeded") || cmd.equals("uneeded")) { if (labels.contains(CSR_LABEL)) { pr.removeLabel(CSR_LABEL); } reply.println("determined that a [CSR](https://wiki.openjdk.java.net/display/csr/Main) request " + "is no longer needed for this pull request."); return; - } else if (!command.args().isEmpty()) { + } else if (!cmd.isEmpty() && !cmd.equals("needed")) { showHelp(reply); return; } diff --git a/bots/pr/src/test/java/org/openjdk/skara/bots/pr/CSRTests.java b/bots/pr/src/test/java/org/openjdk/skara/bots/pr/CSRTests.java index 74ec82e99..2cd306722 100644 --- a/bots/pr/src/test/java/org/openjdk/skara/bots/pr/CSRTests.java +++ b/bots/pr/src/test/java/org/openjdk/skara/bots/pr/CSRTests.java @@ -86,6 +86,16 @@ void simple(TestInfo testInfo) throws IOException { assertLastCommentContains(pr, "determined that a [CSR](https://wiki.openjdk.java.net/display/csr/Main) request " + "is no longer needed for this pull request."); assertFalse(pr.labels().contains("csr")); + + // Require CSR again with long form + prAsReviewer.addComment("/csr needed"); + TestBotRunner.runPeriodicItems(prBot); + + // The bot should reply with a message that a CSR is needed + assertLastCommentContains(pr, "has indicated that a " + + "[compatibility and specification](https://wiki.openjdk.java.net/display/csr/Main) (CSR) request " + + "is needed for this pull request."); + assertTrue(pr.labels().contains("csr")); } } @@ -239,7 +249,7 @@ void showHelpMessageOnUnexpectedArg(TestInfo testInfo) throws IOException { TestBotRunner.runPeriodicItems(prBot); // Show help - assertLastCommentContains(pr, "usage: `/csr [unneeded]`, requires that the issue the pull request links " + + assertLastCommentContains(pr, "usage: `/csr [needed|unneeded]`, requires that the issue the pull request refers to links " + "to an approved [CSR](https://wiki.openjdk.java.net/display/csr/Main) request."); assertFalse(pr.labels().contains("csr")); } diff --git a/cli/src/main/java/org/openjdk/skara/cli/GitPr.java b/cli/src/main/java/org/openjdk/skara/cli/GitPr.java index 79998793d..b6a11235f 100644 --- a/cli/src/main/java/org/openjdk/skara/cli/GitPr.java +++ b/cli/src/main/java/org/openjdk/skara/cli/GitPr.java @@ -85,6 +85,9 @@ public static void main(String[] args) throws Exception { Command.name("cc") .helptext("add one or more labels") .main(GitPrCC::main), + Command.name("csr") + .helptext("require CSR for the pull request") + .main(GitPrCSR::main), Command.name("contributor") .helptext("add or remove contributors") .main(GitPrContributor::main) diff --git a/cli/src/main/java/org/openjdk/skara/cli/pr/GitPrCSR.java b/cli/src/main/java/org/openjdk/skara/cli/pr/GitPrCSR.java new file mode 100644 index 000000000..ec159d079 --- /dev/null +++ b/cli/src/main/java/org/openjdk/skara/cli/pr/GitPrCSR.java @@ -0,0 +1,85 @@ +/* + * 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.cli.pr; + +import org.openjdk.skara.args.*; +import org.openjdk.skara.issuetracker.Comment; +import org.openjdk.skara.forge.PullRequest; + +import static org.openjdk.skara.cli.pr.Utils.*; + +import java.io.IOException; +import java.util.*; + +public class GitPrCSR { + static final List flags = List.of( + Switch.shortcut("") + .fullname("needed") + .helptext("This pull request needs an approved CSR before integration") + .optional(), + Switch.shortcut("") + .fullname("unneeded") + .helptext("This pull request does not need an approved CSR before integration") + .optional(), + Switch.shortcut("") + .fullname("verbose") + .helptext("Turn on verbose output") + .optional(), + Switch.shortcut("") + .fullname("debug") + .helptext("Turn on debugging output") + .optional(), + Switch.shortcut("") + .fullname("version") + .helptext("Print the version of this tool") + .optional() + ); + + static final List inputs = List.of( + Input.position(0) + .describe("ID") + .singular() + .optional() + ); + + public static void main(String[] args) throws IOException, InterruptedException { + var parser = new ArgumentParser("git-pr csr", flags, inputs); + var arguments = parse(parser, args); + var repo = getRepo(); + var uri = getURI(repo, arguments); + var host = getForge(uri, repo, arguments); + var id = pullRequestIdArgument(repo, arguments); + var pr = getPullRequest(uri, repo, host, id); + + if (arguments.contains("needed")) { + var comment = pr.addComment("/csr needed"); + showReply(awaitReplyTo(pr, comment)); + } else if (arguments.contains("unneeded")) { + var comment = pr.addComment("/csr unneeded"); + showReply(awaitReplyTo(pr, comment)); + } else { + System.err.println("error: must use either --needed or --unneeded"); + System.exit(1); + } + } +}