refactor: add nil checks on all converts
This commit is contained in:
parent
0093a15645
commit
4afb7eb108
|
@ -40,7 +40,7 @@ func timePtrIfNotNil(t *time.Time) *github.Timestamp {
|
|||
|
||||
func convertUser(user *structs.User) *github.User {
|
||||
if user == nil {
|
||||
return nil
|
||||
return &github.User{}
|
||||
}
|
||||
return &github.User{
|
||||
Login: stringPtr(user.UserName),
|
||||
|
@ -58,7 +58,7 @@ func convertUsers(users []*structs.User) []*github.User {
|
|||
|
||||
func convertMilestone(milestone *structs.Milestone) *github.Milestone {
|
||||
if milestone == nil {
|
||||
return nil
|
||||
return &github.Milestone{}
|
||||
}
|
||||
return &github.Milestone{
|
||||
Title: stringPtr(milestone.Title),
|
||||
|
@ -66,6 +66,9 @@ func convertMilestone(milestone *structs.Milestone) *github.Milestone {
|
|||
}
|
||||
|
||||
func convertLabels(labels []*structs.Label) []*github.Label {
|
||||
if labels == nil {
|
||||
return make([]*github.Label, 0)
|
||||
}
|
||||
var ghLabels []*github.Label
|
||||
for _, label := range labels {
|
||||
ghLabels = append(ghLabels, &github.Label{
|
||||
|
@ -76,6 +79,9 @@ func convertLabels(labels []*structs.Label) []*github.Label {
|
|||
}
|
||||
|
||||
func convertPRBranch(branch *structs.PRBranchInfo) *github.PullRequestBranch {
|
||||
if branch == nil {
|
||||
return &github.PullRequestBranch{}
|
||||
}
|
||||
return &github.PullRequestBranch{
|
||||
Label: stringPtr(branch.Name),
|
||||
Ref: stringPtr(branch.Ref),
|
||||
|
@ -85,6 +91,9 @@ func convertPRBranch(branch *structs.PRBranchInfo) *github.PullRequestBranch {
|
|||
}
|
||||
|
||||
func convertRepo(repo *structs.Repository) *github.Repository {
|
||||
if repo == nil {
|
||||
return &github.Repository{}
|
||||
}
|
||||
return &github.Repository{
|
||||
ID: int64Ptr(repo.ID),
|
||||
Name: stringPtr(repo.Name),
|
||||
|
@ -112,6 +121,9 @@ func convertRepo(repo *structs.Repository) *github.Repository {
|
|||
}
|
||||
|
||||
func convertPullRequest(request *structs.PullRequest) *github.PullRequest {
|
||||
if request == nil {
|
||||
return &github.PullRequest{}
|
||||
}
|
||||
pr := &github.PullRequest{
|
||||
ID: int64Ptr(request.ID),
|
||||
Number: intPtr(int(request.Index)),
|
||||
|
@ -149,7 +161,7 @@ func convertPullRequest(request *structs.PullRequest) *github.PullRequest {
|
|||
|
||||
func convertChanges(changes *structs.ChangesPayload) *github.EditChange {
|
||||
if changes == nil {
|
||||
return nil
|
||||
return &github.EditChange{}
|
||||
}
|
||||
return &github.EditChange{
|
||||
Title: &github.EditTitle{
|
||||
|
|
Loading…
Reference in New Issue