diff options
author | Kristijan Husak <husakkristijan@gmail.com> | 2018-10-17 14:20:15 +0200 |
---|---|---|
committer | Kristijan Husak <husakkristijan@gmail.com> | 2018-10-20 11:58:08 +0200 |
commit | 990dc8c4ea1133a58d5c863abd543ee5cde1e700 (patch) | |
tree | 80cee673655645b82f7d76d2cc2be409c16c1c8e /pkg/commands/pull_request.go | |
parent | c69fce2e9d28dc847ad5a4528b99682fe61762af (diff) |
Add separate open command for links and check if branch exists on remote before opening pull request link.
Diffstat (limited to 'pkg/commands/pull_request.go')
-rw-r--r-- | pkg/commands/pull_request.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/pkg/commands/pull_request.go b/pkg/commands/pull_request.go index bd076d877..043a3c07d 100644 --- a/pkg/commands/pull_request.go +++ b/pkg/commands/pull_request.go @@ -3,7 +3,6 @@ package commands import ( "errors" "fmt" - "regexp" "strings" ) @@ -53,6 +52,12 @@ func NewPullRequest(gitCommand *GitCommand) *PullRequest { // Create opens link to new pull request in browser func (pr *PullRequest) Create(branch *Branch) error { + branchExistsOnRemote := pr.GitCommand.CheckRemoteBranchExists(branch) + + if !branchExistsOnRemote { + return errors.New(pr.GitCommand.Tr.SLocalize("NoBranchOnRemote")) + } + repoURL := pr.GitCommand.GetRemoteURL() var gitService *Service @@ -69,19 +74,18 @@ func (pr *PullRequest) Create(branch *Branch) error { repoInfo := getRepoInfoFromURL(repoURL) - return pr.GitCommand.OSCommand.OpenFile(fmt.Sprintf( + return pr.GitCommand.OSCommand.OpenLink(fmt.Sprintf( gitService.PullRequestURL, repoInfo.Owner, repoInfo.Repository, branch.Name, )) } func getRepoInfoFromURL(url string) *RepoInformation { isHTTP := strings.HasPrefix(url, "http") - removeGitExtension := regexp.MustCompile(`\.git$`) if isHTTP { splits := strings.Split(url, "/") owner := splits[len(splits)-2] - repo := removeGitExtension.ReplaceAllString(splits[len(splits)-1], "") + repo := strings.TrimSuffix(splits[len(splits)-1], ".git") return &RepoInformation{ Owner: owner, @@ -92,7 +96,7 @@ func getRepoInfoFromURL(url string) *RepoInformation { tmpSplit := strings.Split(url, ":") splits := strings.Split(tmpSplit[1], "/") owner := splits[0] - repo := removeGitExtension.ReplaceAllString(splits[1], "") + repo := strings.TrimSuffix(splits[1], ".git") return &RepoInformation{ Owner: owner, |