refactor: add nil checks on all converts

This commit is contained in:
Derrick Hammer 2024-02-11 04:50:01 -05:00
parent 0093a15645
commit 4afb7eb108
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 15 additions and 3 deletions

View File

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