Skip to content
Open
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
9 changes: 6 additions & 3 deletions cmd/prcreator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@ func main() {
logrus.WithError(err).Fatal("failed to gather options")
}

var prOpts []prcreation.PrOption
prOpts = append(prOpts, prcreation.PrBody(opts.prMessage))
prOpts = append(prOpts, prcreation.PrAssignee(opts.prAssignee))
prOpts = append(prOpts, prcreation.GitCommitMessage(opts.gitCommitMessage))

if err := opts.PRCreationOptions.UpsertPR(".",
opts.organization,
opts.repo,
opts.branch,
opts.prTitle,
prcreation.PrBody(opts.prMessage),
prcreation.PrAssignee(opts.prAssignee),
prcreation.GitCommitMessage(opts.gitCommitMessage),
prOpts...,
); err != nil {
logrus.WithError(err).Fatal("failed to upsert PR")
}
Expand Down
46 changes: 46 additions & 0 deletions pkg/github/prcreation/orgaware.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package prcreation

import (
"strings"

"sigs.k8s.io/prow/pkg/github"
)

// OrgAwareClient wraps a github.Client so that FindIssues routes through
// FindIssuesWithOrg. Prow's App auth round-tripper requires the org in
// the request context to resolve the installation token, but
// bumper.UpdatePullRequestWithLabels internally calls FindIssues which
// passes an empty org.
//
// When IsAppAuth is true, BotUser() appends "[bot]" to the login so that
// GitHub's search API author: qualifier matches the App's acting identity.
type OrgAwareClient struct {
github.Client
Org string
IsAppAuth bool
}

func (c *OrgAwareClient) FindIssues(query, sort string, asc bool) ([]github.Issue, error) {
return c.Client.FindIssuesWithOrg(c.Org, query, sort, asc)
}

// BotUser returns the bot user data. When the client is using GitHub App auth,
// it appends the "[bot]" suffix to the login. GitHub Apps act as "slug[bot]"
// users, but prow's getUserData only stores the bare slug. The search API's
// author: qualifier requires the full "slug[bot]" form to match PRs created
// by the App; using the bare slug results in a 422 because that user does not
// exist on GitHub.
func (c *OrgAwareClient) BotUser() (*github.UserData, error) {
user, err := c.Client.BotUser()
if err != nil {
return nil, err
}
if !c.IsAppAuth || strings.HasSuffix(user.Login, "[bot]") {
return user, nil
}
return &github.UserData{
Name: user.Name,
Login: user.Login + "[bot]",
Email: user.Email,
}, nil
}
Loading