提交 6473f4d6 编写于 作者: J Jingwen Owen Ou

Fix more cucumber test failure due to -F

上级 ccd32318
......@@ -16,7 +16,7 @@ import (
var cmdPullRequest = &Command{
Run: pullRequest,
Usage: "pull-request [-f] [-i ISSUE] [-b BASE] [-d HEAD] [-m MESSAGE] [TITLE]",
Usage: "pull-request [-f] [-i ISSUE] [-b BASE] [-h HEAD] [-m MESSAGE] [TITLE]",
Short: "Open a pull request on GitHub",
Long: `Opens a pull request on GitHub for the project that the "origin" remote
points to. The default head of the pull request is the current branch.
......@@ -35,13 +35,14 @@ of title you can paste a full URL to an issue on GitHub.
`,
}
var flagPullRequestBase, flagPullRequestHead, flagPullRequestIssue, flagPullRequestMessage string
var flagPullRequestBase, flagPullRequestHead, flagPullRequestIssue, flagPullRequestMessage, flagPullRequestFile string
func init() {
cmdPullRequest.Flag.StringVar(&flagPullRequestBase, "b", "master", "BASE")
cmdPullRequest.Flag.StringVar(&flagPullRequestHead, "d", "", "HEAD")
cmdPullRequest.Flag.StringVar(&flagPullRequestBase, "b", "", "BASE")
cmdPullRequest.Flag.StringVar(&flagPullRequestHead, "h", "", "HEAD")
cmdPullRequest.Flag.StringVar(&flagPullRequestIssue, "i", "", "ISSUE")
cmdPullRequest.Flag.StringVar(&flagPullRequestMessage, "m", "", "MESSAGE")
cmdPullRequest.Flag.StringVar(&flagPullRequestFile, "F", "", "FILE")
}
/*
......@@ -77,13 +78,31 @@ func pullRequest(cmd *Command, args *Args) {
gh := github.NewWithoutProject()
gh.Project = baseProject
var base, head string
var (
base, head string
explicitOwner bool
)
if flagPullRequestBase != "" {
base = flagPullRequestBase
if strings.Contains(flagPullRequestBase, ":") {
split := strings.SplitN(flagPullRequestBase, ":", 2)
base = split[1]
baseProject.Owner = split[0]
} else {
base = flagPullRequestBase
}
}
if flagPullRequestHead != "" {
head = flagPullRequestHead
if strings.Contains(flagPullRequestHead, ":") {
split := strings.SplitN(flagPullRequestHead, ":", 2)
head = split[1]
headProject.Owner = split[0]
explicitOwner = true
} else {
head = flagPullRequestHead
}
}
if args.ParamsSize() == 1 {
arg := args.RemoveParam(0)
u, e := github.ParseURL(arg)
......@@ -124,7 +143,7 @@ func pullRequest(cmd *Command, args *Args) {
}
// when no tracking, assume remote branch is published under active user's fork
if tberr != nil && gh.Config.User != headProject.Owner {
if tberr != nil && !explicitOwner && gh.Config.User != headProject.Owner {
headProject = github.NewProjectFromNameAndOwner(headProject.Name, "")
}
......@@ -133,6 +152,20 @@ func pullRequest(cmd *Command, args *Args) {
title, body = readMsg(flagPullRequestMessage)
}
if flagPullRequestFile != "" {
var (
content []byte
err error
)
if flagPullRequestFile == "-" {
content, err = ioutil.ReadAll(os.Stdin)
} else {
content, err = ioutil.ReadFile(flagPullRequestFile)
}
utils.Check(err)
title, body = readMsg(string(content))
}
fullBase := fmt.Sprintf("%s:%s", baseProject.Owner, base)
fullHead := fmt.Sprintf("%s:%s", headProject.Owner, head)
......
......@@ -4,6 +4,7 @@ import (
"errors"
"net/url"
"regexp"
"strings"
)
type Remote struct {
......@@ -24,7 +25,9 @@ func Remotes() (remotes []Remote, err error) {
for _, o := range output {
if re.MatchString(o) {
match := re.FindStringSubmatch(o)
remotesMap[match[1]] = match[2]
k := strings.TrimSpace(match[1])
v := strings.TrimSpace(match[2])
remotesMap[k] = v
}
}
......
......@@ -51,7 +51,8 @@ func (r *GitHubRepo) MasterBranch() (branch Branch, err error) {
name, err := git.SymbolicFullName(origin.Name)
if err != nil {
return
name = "refs/head/master"
err = nil
}
branch = Branch(name)
......@@ -66,7 +67,12 @@ func (r *GitHubRepo) MainProject() (project *Project, err error) {
return
}
return NewProjectFromURL(origin.URL)
project, err = NewProjectFromURL(origin.URL)
if err != nil {
err = fmt.Errorf("Aborted: the origin remote doesn't point to a GitHub repository.")
}
return
}
func (r *GitHubRepo) CurrentProject() (project *Project, err error) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册