Fix migration panic when Head.User is not exist (#7226)

* fix migration panic when Head.User is not exist

* fix test
pull/7245/head
Lunny Xiao 6 years ago committed by techknowlogick
parent 954d24c121
commit 392fe6c943
  1. 29
      modules/migrations/github.go

@ -416,17 +416,36 @@ func (g *GithubDownloaderV3) GetPullRequests(page, perPage int) ([]*base.PullReq
merged = true merged = true
} }
var headRepoName string var (
var cloneURL string headRepoName string
cloneURL string
headRef string
headSHA string
)
if pr.Head.Repo != nil { if pr.Head.Repo != nil {
if pr.Head.Repo.Name != nil {
headRepoName = *pr.Head.Repo.Name headRepoName = *pr.Head.Repo.Name
}
if pr.Head.Repo.CloneURL != nil {
cloneURL = *pr.Head.Repo.CloneURL cloneURL = *pr.Head.Repo.CloneURL
} }
}
if pr.Head.Ref != nil {
headRef = *pr.Head.Ref
}
if pr.Head.SHA != nil {
headSHA = *pr.Head.SHA
}
var mergeCommitSHA string var mergeCommitSHA string
if pr.MergeCommitSHA != nil { if pr.MergeCommitSHA != nil {
mergeCommitSHA = *pr.MergeCommitSHA mergeCommitSHA = *pr.MergeCommitSHA
} }
var headUserName string
if pr.Head.User != nil && pr.Head.User.Login != nil {
headUserName = *pr.Head.User.Login
}
allPRs = append(allPRs, &base.PullRequest{ allPRs = append(allPRs, &base.PullRequest{
Title: *pr.Title, Title: *pr.Title,
Number: int64(*pr.Number), Number: int64(*pr.Number),
@ -443,10 +462,10 @@ func (g *GithubDownloaderV3) GetPullRequests(page, perPage int) ([]*base.PullReq
MergedTime: pr.MergedAt, MergedTime: pr.MergedAt,
IsLocked: pr.ActiveLockReason != nil, IsLocked: pr.ActiveLockReason != nil,
Head: base.PullRequestBranch{ Head: base.PullRequestBranch{
Ref: *pr.Head.Ref, Ref: headRef,
SHA: *pr.Head.SHA, SHA: headSHA,
RepoName: headRepoName, RepoName: headRepoName,
OwnerName: *pr.Head.User.Login, OwnerName: headUserName,
CloneURL: cloneURL, CloneURL: cloneURL,
}, },
Base: base.PullRequestBranch{ Base: base.PullRequestBranch{

Loading…
Cancel
Save