Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JornVernee committed Sep 6, 2019
1 parent 3e72aab commit 18f2768
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Expand Up @@ -54,7 +54,7 @@ private Command helpCommand() {
}

public Executable parse(String[] args) {
if (args.length != 0) {
if (args.length > 0) {
var p = subCommands.get(args[0]);
if (p != null) {
var forwardedArgs = Arrays.copyOfRange(args, 1, args.length);
Expand Down
4 changes: 3 additions & 1 deletion cli/src/main/java/org/openjdk/skara/cli/GitWebrev.java
Expand Up @@ -23,6 +23,7 @@
package org.openjdk.skara.cli;

import org.openjdk.skara.args.*;
import org.openjdk.skara.proxy.HttpProxy;
import org.openjdk.skara.vcs.*;
import org.openjdk.skara.webrev.*;

Expand Down Expand Up @@ -271,7 +272,7 @@ private static void apply(String[] args) throws Exception {
});

var inputString = arguments.at(0).asString();
var webrevMetaData = WebrevMetaData.fromWebrevURL(inputString);
var webrevMetaData = WebrevMetaData.from(URI.create(inputString));
var patchFileURI = webrevMetaData.patchURI()
.orElseThrow(() -> new IllegalStateException("Could not find patch file in webrev"));
var patchFile = downloadPatchFile(patchFileURI);
Expand All @@ -298,6 +299,7 @@ public static void main(String[] args) throws Exception {
.helptext("apply a webrev from a webrev url")
.main(GitWebrev::apply)
);
HttpProxy.setup();

var parser = new MultiCommandParser("git webrev", commands);
var command = parser.parse(args);
Expand Down
Expand Up @@ -42,7 +42,7 @@ public WebrevMetaData(Optional<URI> patchURI) {
this.patchURI = patchURI;
}

public static WebrevMetaData fromWebrevURL(String uri) throws IOException, URISyntaxException, InterruptedException {
public static WebrevMetaData from(URI uri) throws IOException, URISyntaxException, InterruptedException {
var sanatizedUri = sanitizeURI(uri);
var patchFile = getPatchFile(sanatizedUri);

Expand All @@ -56,9 +56,10 @@ private static String dropSuffix(String s, String suffix) {
return s;
}

private static URI sanitizeURI(String uri) throws URISyntaxException {
uri = dropSuffix(uri, "index.html");
return new URI(uri);
private static URI sanitizeURI(URI uri) throws URISyntaxException {
var path = dropSuffix(uri.getPath(), "index.html");
return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(),
path, uri.getQuery(), uri.getFragment());
}

private static Optional<URI> getPatchFile(URI uri) throws IOException, InterruptedException {
Expand Down

0 comments on commit 18f2768

Please sign in to comment.