Skip to content

Commit

Permalink
attach assignee of original release
Browse files Browse the repository at this point in the history
  • Loading branch information
teru01 committed May 14, 2024
1 parent c36e618 commit a5fe025
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
19 changes: 16 additions & 3 deletions flow/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions gitbot/commitpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions gitbot/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 }
Expand Down

0 comments on commit a5fe025

Please sign in to comment.