Skip to content
Permalink
Browse files
git-pr: add contributor sub-command
Co-authored-by: Jorn Vernee <jvernee@openjdk.org>
Reviewed-by: jvernee
  • Loading branch information
edvbld and JornVernee committed Jul 9, 2020
1 parent 9b2c7e0 commit a39fb993bd38d94f09567e4e2fbcf4f74e9520da
Showing with 93 additions and 1 deletion.
  1. +4 −1 cli/src/main/java/org/openjdk/skara/cli/GitPr.java
  2. +89 −0 cli/src/main/java/org/openjdk/skara/cli/pr/GitPrContributor.java
@@ -84,7 +84,10 @@ public static void main(String[] args) throws Exception {
.main(GitPrSummary::main),
Command.name("cc")
.helptext("add one or more labels")
.main(GitPrCC::main)
.main(GitPrCC::main),
Command.name("contributor")
.helptext("add or remove contributors")
.main(GitPrContributor::main)
);

HttpProxy.setup();
@@ -0,0 +1,89 @@
/*
* 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 GitPrContributor {
static final List<Flag> flags = List.of(
Option.shortcut("")
.fullname("add")
.describe("USERNAME")
.helptext("Consider pull request contributed to by this user")
.optional(),
Option.shortcut("")
.fullname("remove")
.describe("USERNAME")
.helptext("Do not consider pull request contributed to by this user")
.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<Input> 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 contributor", 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("add")) {
var username = arguments.get("add").asString();
var comment = pr.addComment("/contributor add" + " " + username);
showReply(awaitReplyTo(pr, comment));
} else if (arguments.contains("remove")) {
var username = arguments.get("remove").asString();
var comment = pr.addComment("/contributor remove" + " " + username);
showReply(awaitReplyTo(pr, comment));
} else {
System.err.println("error: must use either --add or --remove");
System.exit(1);
}
}
}

1 comment on commit a39fb99

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on a39fb99 Jul 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.