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

add SignKey gpg entity param to allow easier pgp signing of commits #1198

Merged
merged 12 commits into from
Jun 22, 2019

Conversation

anandkumarpatel
Copy link
Contributor

Reopening of #1142

This PR creates a new param for the Commit struct called SignKey.
SignKey is an openpgp.Entity type which is the standard way of reading and validating pgp keys.

When specified the key will be used to sign the commit. This makes it so the user does not have to sign the key externally and duplicate some of the logic the CreateCommit function does.

To maintain backward compatibility, if the Verification.Signature is defined SignKey will have no effect.

This provides similar functionality that go-git has: src-d/go-git@7b6c126

Note from the git docs: https://github.com/octokit/routes/blob/152c0b5d156844e17a1805d0509c9a0b7cfc848f/routes/api.github.com/git.json#L282

To pass a `signature` parameter, you need to first manually create a valid PGP signature, which can be complicated. You may find it easier to [use the command line]

So I wanted to make it less complicated 😄

@googlebot googlebot added the cla: yes Indication that the PR author has signed a Google Contributor License Agreement. label Jun 14, 2019
Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @anandkumarpatel.
I've requested some changes, please, when you have time.

github/git_commits.go Outdated Show resolved Hide resolved
github/git_commits.go Outdated Show resolved Hide resolved
message := ""

if commit.Tree != nil {
message = fmt.Sprintf("tree %s\n", *commit.Tree)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the getters... commit.GetTree().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no getters defined for createCommit object

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, whups, my bad. Thanks, @anandkumarpatel.

github/git_commits.go Outdated Show resolved Hide resolved
github/git_commits.go Outdated Show resolved Hide resolved
github/git_commits_test.go Outdated Show resolved Hide resolved
github/git_commits_test.go Outdated Show resolved Hide resolved
github/git_commits_test.go Outdated Show resolved Hide resolved
github/git_commits_test.go Outdated Show resolved Hide resolved
github/git_commits_test.go Outdated Show resolved Hide resolved
@anandkumarpatel
Copy link
Contributor Author

@gmlewis fixed most of the comments you left. The only issue was with using getters on the createCommit object. they do not exist so I left those as is but used getters on the sub-objects that had them.

I also updated all the short names in the test file and defined them more verbosely.

github/git_commits.go Outdated Show resolved Hide resolved
@gmlewis
Copy link
Collaborator

gmlewis commented Jun 14, 2019

I also updated all the short names in the test file and defined them more verbosely.

Just FYI... the other names were fine. As you'll see in a lot of other tests, we use o for org and r for repo all over the place, and it would be nice to be consistent for these...

But it was just a bit challenging at a quick glance to figure out in the tests that:

...

m

was the commit message. Thanks.

github/git_commits.go Outdated Show resolved Hide resolved
@anandkumarpatel
Copy link
Contributor Author

anandkumarpatel commented Jun 14, 2019

@gmlewis ready for round 2 👊 review.

  • added nil checks to both functions
  • added respective tests for those nil checks
  • renamed variable to start lower case
  • reverted renaming of test variables to be consistent to the rest of the project (r, o, ...etc)

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @anandkumarpatel!
Just a couple minor tweaks, please, and then I think we are good to go.

github/git_commits.go Outdated Show resolved Hide resolved
github/git_commits.go Outdated Show resolved Hide resolved
@gmlewis gmlewis requested a review from gauntface June 14, 2019 20:50
@anandkumarpatel
Copy link
Contributor Author

@gmlewis Just pushed, lmk if there is something else.

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for bearing with me, @anandkumarpatel!
I think this is going to turn out nicely. Just a couple more minor tweaks, please.

github/git_commits.go Show resolved Hide resolved
github/git_commits.go Outdated Show resolved Hide resolved
github/git_commits.go Outdated Show resolved Hide resolved
@anandkumarpatel
Copy link
Contributor Author

@gmlewis Fixed the issues.

  • checked for empty message
  • added respective test
  • simplified adding message (removed sprintf)

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @anandkumarpatel!
LGTM.

Awaiting second LGTM before merging.

@gmlewis
Copy link
Collaborator

gmlewis commented Jun 19, 2019

friendly ping @gauntface

Copy link
Contributor

@gauntface gauntface left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM, only question I had is regarding the expected behavior if you set commit.SigningKey AND commit.Verification.

At the moment the signature will be commit.Verification, is that expected? Would it be better if we returned an error if both are set?

@anandkumarpatel
Copy link
Contributor Author

@gauntface I would assume if commit.Verification is set then the user wants to use that to sign instead of the commit.SigningKey.
My assumption is that a default SigningKey is always passed and that Verification would only be passed in special cases which should override SigningKey.

Are my assumptions invalid?

Copy link
Contributor

@gauntface gauntface left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll LGTM as is. Thinking on it more, I'm just projecting my general like of enforced input -> behavior regarding the inputs. It may never be an issue.

@gmlewis
Copy link
Collaborator

gmlewis commented Jun 22, 2019

Good discussion. Thanks, @gauntface and @anandkumarpatel !
I like the fact that the comment for SigningKey says Ignored if Verification.Signature is defined. so there shouldn't be much confusion in this regard.
Merging.

go.mod Outdated Show resolved Hide resolved
@gmlewis
Copy link
Collaborator

gmlewis commented Jun 22, 2019

Thank you, @anandkumarpatel!
Merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Indication that the PR author has signed a Google Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants