Add workaround to get head branch sha of pulls with deleted head branch #498

Merged
zeripath merged 6 commits from 6543/go-sdk:fix-empty-pull-head-sha into master 2021-03-08 21:15:43 +00:00
Showing only changes of commit ad0c06d612 - Show all commits

View File

@ -269,9 +269,9 @@ func (c *Client) GetPullRequestDiff(owner, repo string, index int64) ([]byte, *R
// pr.Head.Ref points in this case not to the head repo branch name, but the base repo ref,
// which stays available to resolve the commit sha.
func fixPullHeadSha(client *Client, pr *PullRequest) error {
owner := pr.Base.Repository.Owner.UserName
repo := pr.Base.Repository.Name
if pr.Head != nil && pr.Head.Ref != "" && pr.Head.Sha == "" {
if pr.Base != nil && pr.Base.Repository != nil && pr.Base.Repository.Owner != nil && pr.Head != nil && pr.Head.Ref != "" && pr.Head.Sha == "" {
owner := pr.Base.Repository.Owner.UserName
repo := pr.Base.Repository.Name
refs, _, err := client.GetRepoRefs(owner, repo, pr.Head.Ref)
if err != nil {
return err