Skip to content

Commit 7c8ed36

Browse files
authored
Define default user and email on PRs (#290)
This commit modifies the PR calls to initialize them with a default user and email based on the auth token. Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
1 parent 4451616 commit 7c8ed36

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

pkg/sourcetool/backends/vcs/github/manage.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ func (b *Backend) CreateWorkflowPR(r *models.Repository, branches []*models.Bran
8282
return nil, errors.New("no branches specified")
8383
}
8484

85+
user, err := b.authenticator.WhoAmI()
86+
if err != nil {
87+
return nil, err
88+
}
89+
8590
// Populate the branches in the workflow template
8691
quotedBranchesList := []string{}
8792
for _, b := range branches {
@@ -112,6 +117,10 @@ func (b *Backend) CreateWorkflowPR(r *models.Repository, branches []*models.Bran
112117
&options.PullRequestFileListOptions{
113118
Title: workflowCommitMessage,
114119
Body: workflowPRBody,
120+
CommitOptions: options.CommitOptions{
121+
Name: user.GetLogin(),
122+
Email: user.GetLogin() + "@users.noreply.github.com",
123+
},
115124
},
116125
[]*repo.PullRequestFileEntry{
117126
{

pkg/sourcetool/implementation.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ func (impl *defaultToolImplementation) CreatePolicyPR(a *auth.Authenticator, opt
9090
if p == nil {
9191
return nil, fmt.Errorf("policy is nil")
9292
}
93+
user, err := a.WhoAmI()
94+
if err != nil {
95+
return nil, err
96+
}
97+
9398
repoOwner, repoName, err := r.PathAsGitHubOwnerName()
9499
if err != nil {
95100
return nil, err
@@ -134,6 +139,10 @@ func (impl *defaultToolImplementation) CreatePolicyPR(a *auth.Authenticator, opt
134139
&roptions.PullRequestFileListOptions{
135140
Title: fmt.Sprintf("Add %s/%s SLSA Source policy file", repoOwner, repoName),
136141
Body: fmt.Sprintf(`This pull request adds the SLSA source policy for github.com/%s/%s`, repoOwner, repoName),
142+
CommitOptions: roptions.CommitOptions{
143+
Name: user.GetLogin(),
144+
Email: user.GetLogin() + "@users.noreply.github.com",
145+
},
137146
},
138147
[]*repo.PullRequestFileEntry{
139148
{

0 commit comments

Comments
 (0)