Skip to content

Commit

Permalink
Allow user assignment override
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Nola <[email protected]>
  • Loading branch information
dereknola committed Jul 5, 2023
1 parent 77c9043 commit bd268fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
16 changes: 5 additions & 11 deletions cmd/backport/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ Options:
-v show version and exit
-r repo repository that should be used
-i issue id original issue id
-c commit commit id that is being backported
-b branch(es) branches issue is being backported to
-u user user to use assign new issues to
Examples:
# generate 2 backport issues for k3s issue 1234
%[2]s -r k3s -b "release-1.21,release-1.22" -i 1234 -c 1
%[2]s -r k3s -b "release-1.24,release-1.25" -i 1234
`

const (
Expand All @@ -39,11 +39,10 @@ const (

var (
vers bool
debug bool
repo string
commitID string
issueID uint
branches string
user string
)

func main() {
Expand All @@ -60,9 +59,9 @@ func main() {

flag.BoolVar(&vers, "v", false, "")
flag.StringVar(&repo, "r", "", "")
flag.StringVar(&commitID, "c", "", "")
flag.UintVar(&issueID, "i", 0, "")
flag.StringVar(&branches, "b", "", "")
flag.StringVar(&user, "u", "", "")
flag.Parse()

if vers {
Expand All @@ -76,11 +75,6 @@ func main() {
os.Exit(1)
}

if commitID == "" {
fmt.Println("error: please provide a commit id")
os.Exit(1)
}

if issueID == 0 {
fmt.Println("error: please provide a valid issue id")
os.Exit(1)
Expand All @@ -92,9 +86,9 @@ func main() {

pbo := repository.PerformBackportOpts{
Repo: repo,
CommitID: commitID,
IssueID: issueID,
Branches: branches,
User: user,
}
issues, err := repository.PerformBackport(ctx, client, &pbo)
if err != nil {
Expand Down
11 changes: 6 additions & 5 deletions repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ func RetrieveOriginalIssue(ctx context.Context, client *github.Client, repo stri
if err != nil {
return nil, err
}

return issue, nil
}

Expand All @@ -198,7 +197,7 @@ type ChangeLog struct {
}

// CreateBackportIssues
func CreateBackportIssues(ctx context.Context, client *github.Client, origIssue *github.Issue, repo, branch string, i *Issue) (*github.Issue, error) {
func CreateBackportIssues(ctx context.Context, client *github.Client, origIssue *github.Issue, repo, branch, user string, i *Issue) (*github.Issue, error) {
org, err := OrgFromRepo(repo)
if err != nil {
return nil, err
Expand All @@ -208,7 +207,9 @@ func CreateBackportIssues(ctx context.Context, client *github.Client, origIssue
body := fmt.Sprintf(i.Body, origIssue.GetTitle(), *origIssue.Number)

var assignee *string
if origIssue.GetAssignee() != nil {
if user != "" {
assignee = types.StringPtr(user)
} else if origIssue.GetAssignee() != nil {
assignee = origIssue.GetAssignee().Login
} else {
assignee = types.StringPtr("")
Expand All @@ -228,9 +229,9 @@ func CreateBackportIssues(ctx context.Context, client *github.Client, origIssue
// PerformBackportOpts
type PerformBackportOpts struct {
Repo string `json:"repo"`
CommitID string `json:"commit_id"`
IssueID uint `json:"issue_id"`
Branches string `json:"branches"`
User string `json:"user"`
}

// PerformBackport
Expand Down Expand Up @@ -261,7 +262,7 @@ func PerformBackport(ctx context.Context, client *github.Client, pbo *PerformBac

issues := make([]*github.Issue, len(backportBranches))
for _, branch := range backportBranches {
newIssue, err := CreateBackportIssues(ctx, client, origIssue, pbo.Repo, branch, &issue)
newIssue, err := CreateBackportIssues(ctx, client, origIssue, pbo.Repo, branch, pbo.User, &issue)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit bd268fe

Please sign in to comment.