From 9113092f5c4444d803fba0cdc03133c036efb414 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Fri, 22 May 2020 15:19:39 -0700 Subject: [PATCH] Delete via api --- api/queries_pr.go | 8 ++++++++ command/pr.go | 2 +- git/git.go | 6 ------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/api/queries_pr.go b/api/queries_pr.go index 64925fae5..dd5b509d1 100644 --- a/api/queries_pr.go +++ b/api/queries_pr.go @@ -1014,6 +1014,14 @@ func PullRequestReady(client *Client, repo ghrepo.Interface, pr *PullRequest) er return err } +func BranchDeleteRemote(client *Client, repo ghrepo.Interface, branch string) error { + var response struct { + NodeID string `json:"node_id"` + } + path := fmt.Sprintf("/repos/%s/%s/git/refs/heads/%s", repo.RepoOwner, repo.RepoName, branch) + return client.REST("GET", path, nil, &response) +} + func min(a, b int) int { if a < b { return a diff --git a/command/pr.go b/command/pr.go index 6a080b7f4..e757152b6 100644 --- a/command/pr.go +++ b/command/pr.go @@ -586,7 +586,7 @@ func prMerge(cmd *cobra.Command, args []string) error { } } - err = git.DeleteRemoteBranch(pr.HeadRefName) + err = api.BranchDeleteRemote(apiClient, baseRepo, pr.HeadRefName) if err != nil { err = fmt.Errorf("failed to delete remote branch %s: %w", utils.Cyan(pr.HeadRefName), err) return err diff --git a/git/git.go b/git/git.go index 529dc792d..355f905f0 100644 --- a/git/git.go +++ b/git/git.go @@ -209,12 +209,6 @@ func DeleteLocalBranch(branch string) error { return err } -func DeleteRemoteBranch(branch string) error { - configCmd := GitCommand("push", "origin", "--delete", branch) - _, err := run.PrepareCmd(configCmd).Output() - return err -} - func HasLocalBranch(branch string) bool { configCmd := GitCommand("rev-parse", "--verify", "refs/heads/"+branch) _, err := run.PrepareCmd(configCmd).Output()