Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport: Allow user assignment override #223

Merged
merged 3 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cmd/backport/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ Options:
-i issue id original issue id
-c commits commits to be backported (comma seperated)
-b branch(es) branches issue is being backported to
-u user user to assign new issues to (default: user assigned to orig. issue)

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.25,release-1.26" -i 1234 -c 1
%[2]s -r k3s -b "release-1.26" -i 1234 -c 1,2,3
`

Expand All @@ -40,6 +41,7 @@ var (
commitIDs string
issueID uint
branches string
user string
)

func main() {
Expand All @@ -59,6 +61,7 @@ func main() {
flag.StringVar(&commitIDs, "c", "", "")
flag.UintVar(&issueID, "i", 0, "")
flag.StringVar(&branches, "b", "", "")
flag.StringVar(&user, "u", "", "")
flag.Parse()

if vers {
Expand Down Expand Up @@ -91,6 +94,7 @@ func main() {
Commits: commits,
IssueID: issueID,
Branches: branches,
User: user,
}
issues, err := repository.PerformBackport(ctx, client, &pbo)
if err != nil {
Expand Down
10 changes: 6 additions & 4 deletions repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,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 @@ -212,7 +212,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 @@ -235,6 +237,7 @@ type PerformBackportOpts struct {
Commits []string `json:"commits"`
IssueID uint `json:"issue_id"`
Branches string `json:"branches"`
User string `json:"user"`
}

// PerformBackport creates backport issues, performs a cherry-pick of the
Expand Down Expand Up @@ -266,12 +269,11 @@ 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
}
issues = append(issues, newIssue)
fmt.Println("Backport issue created: " + newIssue.GetHTMLURL())
}

// stop here if there are no commits given
Expand Down