Skip to content

Commit

Permalink
Fix github_repository_file: Disable default compute of author and e…
Browse files Browse the repository at this point in the history
…mail (integrations#1179)

* Disable compute of author and email from previous commit

* Add additional flag to commit as token owner

* Ignore author and email if its web-flow user

* Set compute to false for commit author and email

* Add note on verifying commits using github app

* Update website/docs/r/repository_file.html.markdown

* Update website/docs/r/repository_file.html.markdown

* Update github/resource_github_repository_file.go

* Update github/resource_github_repository_file.go

Co-authored-by: Keegan Campbell <me@kfcampbell.com>
  • Loading branch information
pawnu and kfcampbell authored Oct 10, 2022
1 parent 6773d80 commit 9d58e1d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
18 changes: 12 additions & 6 deletions github/resource_github_repository_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ func resourceGithubRepositoryFile() *schema.Resource {
"commit_author": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The commit author name, defaults to the authenticated user's name",
Computed: false,
Description: "The commit author name, defaults to the authenticated user's name. GitHub app users may omit author and email information so GitHub can verify commits as the GitHub App. ",
},
"commit_email": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The commit author email address, defaults to the authenticated user's email address",
Computed: false,
Description: "The commit author email address, defaults to the authenticated user's email address. GitHub app users may omit author and email information so GitHub can verify commits as the GitHub App.",
},
"sha": {
Type: schema.TypeString,
Expand Down Expand Up @@ -255,8 +255,14 @@ func resourceGithubRepositoryFileRead(d *schema.ResourceData, meta interface{})
}

d.Set("commit_sha", commit.GetSHA())
d.Set("commit_author", commit.Commit.GetCommitter().GetName())
d.Set("commit_email", commit.Commit.GetCommitter().GetEmail())

commit_author := commit.Commit.GetCommitter().GetName()
commit_email := commit.Commit.GetCommitter().GetEmail()

if commit_author != "GitHub" && commit_email != "noreply@github.com" {
d.Set("commit_author", commit_author)
d.Set("commit_email", commit_email)
}
d.Set("commit_message", commit.GetCommit().GetMessage())

return nil
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/repository_file.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ The following arguments are supported:
* `branch` - (Optional) Git branch (defaults to `main`).
The branch must already exist, it will not be created if it does not already exist.

* `commit_author` - (Optional) Committer author name to use.
* `commit_author` - (Optional) Committer author name to use. **NOTE:** GitHub app users may omit author and email information so GitHub can verify commits as the GitHub App. This maybe useful when a branch protection rule requires signed commits.

* `commit_email` - (Optional) Committer email address to use.
* `commit_email` - (Optional) Committer email address to use. **NOTE:** GitHub app users may omit author and email information so GitHub can verify commits as the GitHub App. This may be useful when a branch protection rule requires signed commits.

* `commit_message` - (Optional) Commit message when adding or updating the managed file.

Expand Down

0 comments on commit 9d58e1d

Please sign in to comment.