make PR workflow helpers more robust (#300)

improve handling of remote deleted branches

split git.TeaDeleteBranch

only delete remote branch if we have permission

add missing err check

Co-authored-by: Norwin Roosen <git@nroo.de>
Reviewed-on: https://gitea.com/gitea/tea/pulls/300
Reviewed-by: 6543 <6543@obermui.de>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-Authored-By: Norwin <noerw@noreply.gitea.io>
Co-Committed-By: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
Norwin
2020-12-17 22:00:16 +08:00
committed by 6543
parent a2e8b47c57
commit 8b588f5313
3 changed files with 47 additions and 30 deletions

View File

@ -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 {