make PR workflow helpers more robust #300
|
@ -27,6 +27,10 @@ func PullCheckout(login *config.Login, repoOwner, repoName string, index int64,
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
remoteDeleted := pr.Head.Ref == fmt.Sprintf("refs/pull/%d/head", pr.Index)
|
||||
if remoteDeleted {
|
||||
return fmt.Errorf("Can't checkout: remote head branch was already deleted")
|
||||
}
|
||||
|
||||
remoteURL := pr.Head.Repository.CloneURL
|
||||
if len(login.SSHKey) != 0 {
|
||||
|
|
|
@ -35,6 +35,14 @@ func PullClean(login *config.Login, repoOwner, repoName string, index int64, ign
|
|||
|
||||
// IDEA: abort if PR.Head.Repository.CloneURL does not match login.URL?
|
||||
|
||||
// if remote head branch is already deleted, pr.Head.Ref points to "pulls/<idx>/head"
|
||||
remoteBranch := pr.Head.Ref
|
||||
remoteDeleted := remoteBranch == fmt.Sprintf("refs/pull/%d/head", pr.Index)
|
||||
if remoteDeleted {
|
||||
remoteBranch = pr.Head.Name // this still holds the original branch name
|
||||
fmt.Printf("Remote branch '%s' already deleted.\n", remoteBranch)
|
||||
}
|
||||
|
||||
r, err := local_git.RepoForWorkdir()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -43,7 +51,7 @@ func PullClean(login *config.Login, repoOwner, repoName string, index int64, ign
|
|||
// find a branch with matching sha or name, that has a remote matching the repo url
|
||||
var branch *git_config.Branch
|
||||
if ignoreSHA {
|
||||
branch, err = r.TeaFindBranchByName(pr.Head.Ref, pr.Head.Repository.CloneURL)
|
||||
branch, err = r.TeaFindBranchByName(remoteBranch, pr.Head.Repository.CloneURL)
|
||||
} else {
|
||||
branch, err = r.TeaFindBranchBySha(pr.Head.Sha, pr.Head.Repository.CloneURL)
|
||||
}
|
||||
|
@ -52,12 +60,12 @@ func PullClean(login *config.Login, repoOwner, repoName string, index int64, ign
|
|||
}
|
||||
if branch == nil {
|
||||
if ignoreSHA {
|
||||
return fmt.Errorf("Remote branch %s not found in local repo", pr.Head.Ref)
|
||||
return fmt.Errorf("Remote branch %s not found in local repo", remoteBranch)
|
||||
}
|
||||
return fmt.Errorf(`Remote branch %s not found in local repo.
|
||||
Either you don't track this PR, or the local branch has diverged from the remote.
|
||||
If you still want to continue & are sure you don't loose any important commits,
|
||||
call me again with the --ignore-sha flag`, pr.Head.Ref)
|
||||
call me again with the --ignore-sha flag`, remoteBranch)
|
||||
}
|
||||
|
||||
// prepare deletion of local branch:
|
||||
|
@ -73,7 +81,7 @@ call me again with the --ignore-sha flag`, pr.Head.Ref)
|
|||
}
|
||||
|
||||
// remove local & remote branch
|
||||
fmt.Printf("Deleting local branch %s and remote branch %s\n", branch.Name, pr.Head.Ref)
|
||||
fmt.Printf("Deleting local branch %s and remote branch %s\n", branch.Name, remoteBranch)
|
||||
url, err := r.TeaRemoteURL(branch.Remote)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -82,5 +90,5 @@ call me again with the --ignore-sha flag`, pr.Head.Ref)
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return r.TeaDeleteBranch(branch, pr.Head.Ref, auth)
|
||||
return r.TeaDeleteBranch(branch, remoteBranch, auth)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user