From a5fe025e13e680e7a393bda7a57bf5442ca12d73 Mon Sep 17 00:00:00 2001 From: ono-teruya <27873650+teru01@users.noreply.github.com> Date: Tue, 14 May 2024 12:48:33 +0900 Subject: [PATCH] attach assignee of original release --- flow/process.go | 19 ++++++++++++++++--- gitbot/commitpr.go | 9 +++++++-- gitbot/release.go | 6 +++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/flow/process.go b/flow/process.go index 64abd3d..7874259 100644 --- a/flow/process.go +++ b/flow/process.go @@ -97,17 +97,22 @@ func (f *Flow) process(ctx context.Context, app *Application, version string) Pu for oldVersion := range oldVersionSet { oldVersions = append(oldVersions, oldVersion) } + + actor, err := getGitHubActor(ctx, client, app, version) + if err != nil { + log.Printf("Skip getting actor because it may not be a release: %s", err) + } + body := generateBody(ctx, client, app, manifest, version, oldVersions) release.SetBody(body) - err := release.Commit(ctx, client) - if err != nil { + if err := release.Commit(ctx, client); err != nil { log.Printf("Error Commiting: %s", err) continue } if !manifest.CommitWithoutPR { - url, err := release.CreatePR(ctx, client) + url, err := release.CreatePR(ctx, client, actor) if err != nil { log.Printf("Error Submitting PR: %s", err) continue @@ -121,6 +126,14 @@ func (f *Flow) process(ctx context.Context, app *Application, version string) Pu return prs } +func getGitHubActor(ctx context.Context, client *github.Client, app *Application, version string) (*github.User, error) { + release, _, err := client.Repositories.GetReleaseByTag(ctx, app.SourceOwner, app.SourceName, version) + if err != nil { + return nil, err + } + return release.Author, nil +} + func shouldProcess(m Manifest, version string) bool { if version == "" { return false diff --git a/gitbot/commitpr.go b/gitbot/commitpr.go index 662361a..a0f5bdc 100644 --- a/gitbot/commitpr.go +++ b/gitbot/commitpr.go @@ -72,7 +72,7 @@ func (r *release) pushCommit(ctx context.Context, client *github.Client, ref *gi return err } -func (r *release) createPR(ctx context.Context, client *github.Client) (*string, error) { +func (r *release) createPR(ctx context.Context, client *github.Client, assignee *github.User) (*string, error) { newPR := &github.NewPullRequest{ Title: github.String(r.message), Head: github.String(r.repo.CommitBranch), @@ -90,7 +90,12 @@ func (r *release) createPR(ctx context.Context, client *github.Client) (*string, if err != nil { log.Printf("Error Adding Lables: %s", err) } - + if assignee != nil { + _, _, err := client.Issues.AddAssignees(ctx, r.repo.SourceOwner, r.repo.SourceRepo, *pr.Number, []string{assignee.GetLogin()}) + if err != nil { + log.Printf("Failed to add Assignee(%s), but continue: %s", assignee.GetLogin(), err) + } + } return github.String(pr.GetHTMLURL()), nil } diff --git a/gitbot/release.go b/gitbot/release.go index 01aded7..5980a18 100644 --- a/gitbot/release.go +++ b/gitbot/release.go @@ -21,7 +21,7 @@ type Release interface { MakeChange(ctx context.Context, client *github.Client, filePath, regexText, changedText string) MakeChangeFunc(ctx context.Context, client *github.Client, filePath, regexText string, evaluator regexp2.MatchEvaluator) Commit(ctx context.Context, client *github.Client) error - CreatePR(ctx context.Context, client *github.Client) (*string, error) + CreatePR(ctx context.Context, client *github.Client, assignee *github.User) (*string, error) GetRepo() *Repo SetRepo(repo Repo) @@ -85,8 +85,8 @@ func (r *release) Commit(ctx context.Context, client *github.Client) error { return r.pushCommit(ctx, client, ref, tree) } -func (r *release) CreatePR(ctx context.Context, client *github.Client) (*string, error) { - return r.createPR(ctx, client) +func (r *release) CreatePR(ctx context.Context, client *github.Client, assignee *github.User) (*string, error) { + return r.createPR(ctx, client, assignee) } func (r *release) GetRepo() *Repo { return &r.repo }