Skip to content

Commit

Permalink
prevent panic when no assignee on issue (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
briandowns authored Feb 10, 2022
1 parent 3a63ab1 commit 4694b37
Show file tree
Hide file tree
Showing 3 changed files with 616 additions and 1 deletion.
9 changes: 8 additions & 1 deletion repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/google/go-github/v39/github"
"github.com/rancher/ecm-distro-tools/types"
"golang.org/x/oauth2"
)

Expand Down Expand Up @@ -111,10 +112,16 @@ func CreateBackportIssues(ctx context.Context, client *github.Client, origIssue
title := fmt.Sprintf(i.Title, strings.Title(branch), origIssue.GetTitle())
body := fmt.Sprintf(i.Body, origIssue.GetTitle(), *origIssue.Number)

var assignee *string
if origIssue.GetAssignee() != nil {
assignee = origIssue.GetAssignee().Login
} else {
assignee = types.StringPtr("")
}
issue, _, err := client.Issues.Create(ctx, org, repo, &github.IssueRequest{
Title: github.String(title),
Body: github.String(body),
Assignee: origIssue.GetAssignee().Login,
Assignee: assignee,
})
if err != nil {
return nil, err
Expand Down
106 changes: 106 additions & 0 deletions types/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package types

// IntPtr creates an int pointer value and
// returns it to the caller.
func IntPtr(i int) *int {
v := int(i)
return &v
}

// Int8Ptr creates an int8 pointer value and
// returns it to the caller.
func Int8Ptr(i int8) *int8 {
v := int8(i)
return &v
}

// Int16Ptr creates an int16 pointer value and
// returns it to the caller.
func Int16Ptr(i int16) *int16 {
v := int16(i)
return &v
}

// Int32Ptr creates an int32 pointer value and
// returns it to the caller.
func Int32Ptr(i int32) *int32 {
v := int32(i)
return &v
}

// Int64Ptr creates an int64 pointer value and
// returns it to the caller.
func Int64Ptr(i int64) *int64 {
v := int64(i)
return &v
}

// UintPtr creates a uint pointer value and
// returns it to the caller.
func UintPtr(i uint) *uint {
v := uint(i)
return &v
}

// Uint8Ptr creates a uint8 pointer value and
// returns it to the caller.
func Uint8Ptr(i uint8) *uint8 {
v := uint8(i)
return &v
}

// Uint16Ptr creates a uint16 pointer value and
// returns it to the caller.
func Uint16Ptr(i uint16) *uint16 {
v := uint16(i)
return &v
}

// Uint32Ptr creates a uint32 pointer value and
// returns it to the caller.
func Uint32Ptr(i uint32) *uint32 {
v := uint32(i)
return &v
}

// Uint64Ptr creates a uint64 pointer value and
// returns it to the caller.
func Uint64Ptr(i uint64) *uint64 {
v := uint64(i)
return &v
}

// StringPtr creates a string pointer value and
// returns it to the caller.
func StringPtr(s string) *string {
v := string(s)
return &v
}

// BytePtr creates a byte pointer value and
// returns it to the caller.
func BytePtr(b byte) *byte {
v := byte(b)
return &v
}

// Float32Ptr creates a float32 pointer value and
// returns it to the caller.
func Float32Ptr(f float32) *float32 {
v := float32(f)
return &v
}

// Float64Ptr creates a float64 pointer value and
// returns it to the caller.
func Float64Ptr(f float64) *float64 {
v := float64(f)
return &v
}

// BoolPtr creates a bool pointer value and
// returns it to the caller.
func BoolPtr(b bool) *bool {
v := bool(b)
return &v
}
Loading

0 comments on commit 4694b37

Please sign in to comment.