From 260c235ad59448ad537be5173ff606d4f019a75a Mon Sep 17 00:00:00 2001 From: Katsuhiko YOSHIDA Date: Sat, 7 Apr 2018 16:25:02 +0900 Subject: [PATCH] Run by the most recent commit when no args --- Gopkg.lock | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++++- cli.go | 39 ++++++++++---- 2 files changed, 178 insertions(+), 12 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 5e02240..cbcda80 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -7,6 +7,19 @@ revision = "b26d9c308763d68093482582cea63d69be07a0f0" version = "v0.3.0" +[[projects]] + name = "github.com/emirpasic/gods" + packages = [ + "containers", + "lists", + "lists/arraylist", + "trees", + "trees/binaryheap", + "utils" + ] + revision = "f6c17b524822278a87e3b3bd809fec33b51f5b46" + version = "v1.9.0" + [[projects]] branch = "master" name = "github.com/github/hub" @@ -38,12 +51,24 @@ packages = ["query"] revision = "53e6ce116135b80d037921a7fdd5138cf32d7a8a" +[[projects]] + branch = "master" + name = "github.com/jbenet/go-context" + packages = ["io"] + revision = "d14ea06fba99483203c19d92cfcd13ebe73135f4" + [[projects]] branch = "master" name = "github.com/kballard/go-shellquote" packages = ["."] revision = "cd60e84ee657ff3dc51de0b4f55dd299a3e136f2" +[[projects]] + name = "github.com/kevinburke/ssh_config" + packages = ["."] + revision = "9fc7bb800b555d63157c65a904c86a2cc7b4e795" + version = "0.4" + [[projects]] name = "github.com/mattn/go-colorable" packages = ["."] @@ -68,16 +93,60 @@ packages = ["."] revision = "b8bc1bf767474819792c23f32d8286a45736f1c6" +[[projects]] + name = "github.com/pelletier/go-buffruneio" + packages = ["."] + revision = "c37440a7cf42ac63b919c752ca73a85067e05992" + version = "v0.2.0" + +[[projects]] + name = "github.com/sergi/go-diff" + packages = ["diffmatchpatch"] + revision = "1744e2970ca51c86172c8190fadad617561ed6e7" + version = "v1.0.0" + [[projects]] branch = "master" name = "github.com/skratchdot/open-golang" packages = ["open"] revision = "75fb7ed4208cf72d323d7d02fd1a5964a7a9073c" +[[projects]] + name = "github.com/src-d/gcfg" + packages = [ + ".", + "scanner", + "token", + "types" + ] + revision = "f187355171c936ac84a82793659ebb4936bc1c23" + version = "v1.3.0" + +[[projects]] + branch = "master" + name = "github.com/xanzy/ssh-agent" + packages = ["."] + revision = "ba9c9e33906f58169366275e3450db66139a31a9" + [[projects]] branch = "master" name = "golang.org/x/crypto" - packages = ["ssh/terminal"] + packages = [ + "cast5", + "curve25519", + "ed25519", + "ed25519/internal/edwards25519", + "openpgp", + "openpgp/armor", + "openpgp/elgamal", + "openpgp/errors", + "openpgp/packet", + "openpgp/s2k", + "ssh", + "ssh/agent", + "ssh/knownhosts", + "ssh/terminal" + ] revision = "0fcca4842a8d74bfddc2c96a073bd2a4d2a7a2e8" [[projects]] @@ -107,6 +176,19 @@ ] revision = "83801418e1b59fb1880e363299581ee543af32ca" +[[projects]] + name = "golang.org/x/text" + packages = [ + "internal/gen", + "internal/triegen", + "internal/ucd", + "transform", + "unicode/cldr", + "unicode/norm" + ] + revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" + version = "v0.3.0" + [[projects]] name = "google.golang.org/appengine" packages = [ @@ -121,6 +203,71 @@ revision = "150dc57a1b433e64154302bdc40b6bb8aefa313a" version = "v1.0.0" +[[projects]] + name = "gopkg.in/src-d/go-billy.v4" + packages = [ + ".", + "helper/chroot", + "helper/polyfill", + "osfs", + "util" + ] + revision = "df053870ae7070b0350624ba5a22161ba3796cc0" + version = "v4.1.1" + +[[projects]] + name = "gopkg.in/src-d/go-git.v4" + packages = [ + ".", + "config", + "internal/revision", + "plumbing", + "plumbing/cache", + "plumbing/filemode", + "plumbing/format/config", + "plumbing/format/diff", + "plumbing/format/gitignore", + "plumbing/format/idxfile", + "plumbing/format/index", + "plumbing/format/objfile", + "plumbing/format/packfile", + "plumbing/format/pktline", + "plumbing/object", + "plumbing/protocol/packp", + "plumbing/protocol/packp/capability", + "plumbing/protocol/packp/sideband", + "plumbing/revlist", + "plumbing/storer", + "plumbing/transport", + "plumbing/transport/client", + "plumbing/transport/file", + "plumbing/transport/git", + "plumbing/transport/http", + "plumbing/transport/internal/common", + "plumbing/transport/server", + "plumbing/transport/ssh", + "storage", + "storage/filesystem", + "storage/filesystem/internal/dotgit", + "storage/memory", + "utils/binary", + "utils/diff", + "utils/ioutil", + "utils/merkletrie", + "utils/merkletrie/filesystem", + "utils/merkletrie/index", + "utils/merkletrie/internal/frame", + "utils/merkletrie/noder" + ] + revision = "247cf690745dfd67ccd9f0c07878e6dd85e6c9ed" + version = "v4.2.1" + +[[projects]] + name = "gopkg.in/warnings.v0" + packages = ["."] + revision = "ec4a0fea49c7b46c2aeb0b51aac55779c607e52b" + version = "v0.1.2" + [[projects]] branch = "v1" name = "gopkg.in/yaml.v1" @@ -136,6 +283,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "10c5bcb0aceeeaa8d9e9c8416fbb386f3ee3574e0bfd8a4d54a1d2fae7f3ce5f" + inputs-digest = "da52c3932b95412fd1fd5a16e04b1a2d937727153aae0c30a9449b5e2c0fd296" solver-name = "gps-cdcl" solver-version = 1 diff --git a/cli.go b/cli.go index ba43729..cb004cc 100644 --- a/cli.go +++ b/cli.go @@ -16,6 +16,7 @@ import ( "github.com/mitchellh/colorstring" homedir "github.com/mitchellh/go-homedir" "github.com/skratchdot/open-golang/open" + "gopkg.in/src-d/go-git.v4" ) const ( @@ -98,16 +99,12 @@ func (c *CLI) Run(args []string) int { return ExitCodeOK } - parsedArgs := flags.Args() - if len(parsedArgs) != 1 { - PrintErrorf("Invalid argument: you must set sha.") - return ExitCodeBadArgs + client, err := NewClient() + if err != nil { + return ExitCodeError } - sha := parsedArgs[0] - Debugf("sha: %s", sha) - - client, err := NewClient() + sha, err := getSha(flags.Args()) if err != nil { return ExitCodeError } @@ -142,6 +139,27 @@ func printURL(client *APIClient, sha string, newline bool) int { return ExitCodeOK } +func getSha(args []string) (string, error) { + var sha string + if len(args) == 0 { + wd, _ := os.Getwd() + repo, err := git.PlainOpen(wd) + if err != nil { + return "", err + } + ref, err := repo.Head() + if err != nil { + return "", err + } + sha = ref.Hash().String() + } else { + sha = args[0] + } + + Debugf("sha: %s", sha) + return sha, nil +} + func printAPIUrl(client *APIClient, sha string, newline bool) int { Debugf("Print API URL") @@ -284,11 +302,12 @@ func Repository(client *api.Client) (*api.Repository, error) { return repo, err } -var helpText = `Usage: tosa [options...] sha +var helpText = `Usage: tosa [options...] [sha] tosa is a tool to open the pull request page. -You must specify commit sha what you want to know pull request. +sha is a commit hash you want to know the pull request. +If not specified, get it from HEAD. Options: