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

attach assignee of original release #92

Closed
wants to merge 1 commit into from
Closed
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
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