diff options
author | Denis Palashevskii <palash.denis@outlook.com> | 2021-04-21 15:23:36 +0400 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-07-27 21:30:08 +1000 |
commit | 0e6598adbd7c5321c3e9ec46d303a707d0e5ecbb (patch) | |
tree | aefc546c8367137cc5d23039530171899ab251a8 /pkg/commands | |
parent | f2645da16a4bd4335c4c77e43517b5fd8d8ca259 (diff) |
Implement pull request options menu
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/pull_request.go | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/pkg/commands/pull_request.go b/pkg/commands/pull_request.go index ac60af536..9a29ae17a 100644 --- a/pkg/commands/pull_request.go +++ b/pkg/commands/pull_request.go @@ -37,24 +37,39 @@ func NewService(typeName string, repositoryDomain string, siteDomain string) *Se service = &Service{ Name: repositoryDomain, PullRequestURL: func(owner string, repository string, from string, to string) string { - urlFormat := fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/compare/%s?expand=1") - return fmt.Sprintf(urlFormat, owner, repository, from) + if to == "" { + urlFormat := fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/compare/%s?expand=1") + return fmt.Sprintf(urlFormat, owner, repository, from) + } else { + urlFormat := fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/compare/%s...%s?expand=1") + return fmt.Sprintf(urlFormat, owner, repository, to, from) + } }, } case "bitbucket": service = &Service{ - Name: repositoryDomain, + Name: repositoryDomain, PullRequestURL: func(owner string, repository string, from string, to string) string { - urlFormat := fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/pull-requests/new?source=%s&t=1") - return fmt.Sprintf(urlFormat, owner, repository, from) + if to == "" { + urlFormat := fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/pull-requests/new?source=%s&t=1") + return fmt.Sprintf(urlFormat, owner, repository, from) + } else { + urlFormat := fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/pull-requests/new?source=%s&dest=%s&t=1") + return fmt.Sprintf(urlFormat, owner, repository, from, to) + } }, } case "gitlab": service = &Service{ - Name: repositoryDomain, + Name: repositoryDomain, PullRequestURL: func(owner string, repository string, from string, to string) string { - urlFormat := fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/merge_requests/new?merge_request[source_branch]=%s") - return fmt.Sprintf(urlFormat, owner, repository, from) + if to == "" { + urlFormat := fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/merge_requests/new?merge_request[source_branch]=%s") + return fmt.Sprintf(urlFormat, owner, repository, from) + } else { + urlFormat := fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/merge_requests/new?merge_request[source_branch]=%s&merge_request[target_branch]=%s") + return fmt.Sprintf(urlFormat, owner, repository, from, to) + } }, } } @@ -99,8 +114,8 @@ func NewPullRequest(gitCommand *GitCommand) *PullRequest { } // Create opens link to new pull request in browser -func (pr *PullRequest) Create(branch *models.Branch) (string, error) { - pullRequestURL, err := pr.getPullRequestURL(branch) +func (pr *PullRequest) Create(from *models.Branch, to *models.Branch) (string, error) { + pullRequestURL, err := pr.getPullRequestURL(from, to) if err != nil { return "", err } @@ -109,8 +124,8 @@ func (pr *PullRequest) Create(branch *models.Branch) (string, error) { } // CopyURL copies the pull request URL to the clipboard -func (pr *PullRequest) CopyURL(branch *models.Branch) (string, error) { - pullRequestURL, err := pr.getPullRequestURL(branch) +func (pr *PullRequest) CopyURL(from *models.Branch, to *models.Branch) (string, error) { + pullRequestURL, err := pr.getPullRequestURL(from, to) if err != nil { return "", err } @@ -118,8 +133,8 @@ func (pr *PullRequest) CopyURL(branch *models.Branch) (string, error) { return pullRequestURL, pr.GitCommand.OSCommand.CopyToClipboard(pullRequestURL) } -func (pr *PullRequest) getPullRequestURL(branch *models.Branch) (string, error) { - branchExistsOnRemote := pr.GitCommand.CheckRemoteBranchExists(branch) +func (pr *PullRequest) getPullRequestURL(from *models.Branch, to *models.Branch) (string, error) { + branchExistsOnRemote := pr.GitCommand.CheckRemoteBranchExists(from) if !branchExistsOnRemote { return "", errors.New(pr.GitCommand.Tr.NoBranchOnRemote) @@ -140,7 +155,13 @@ func (pr *PullRequest) getPullRequestURL(branch *models.Branch) (string, error) } repoInfo := getRepoInfoFromURL(repoURL) - pullRequestURL := gitService.PullRequestURL(repoInfo.Owner, repoInfo.Repository, branch.Name, "") + var toBranchName string + if to == nil { + toBranchName = "" + } else { + toBranchName = to.Name + } + pullRequestURL := gitService.PullRequestURL(repoInfo.Owner, repoInfo.Repository, from.Name, toBranchName) return pullRequestURL, nil } |