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 support for setting environments secrets #3769

Merged
merged 3 commits into from
Jun 2, 2021

Conversation

browniebroke
Copy link
Contributor

Support to list environemnt secrets was added in #3270 but it would be nice to also be able to set them.

Fixes #3265

@@ -75,7 +75,7 @@ and talk through which code gets run in order.
This task might be tricky. Typically, gh commands do things like look up information from the git repository
in the current directory, query the GitHub API, scan the user's `~/.ssh/config` file, clone or fetch git
repositories, etc. Naturally, none of these things should ever happen for real when running tests, unless
you are sure that any filesystem operations are stricly scoped to a location made for and maintained by the
you are sure that any filesystem operations are strictly scoped to a location made for and maintained by the
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unrelated, a small typo I noticed.

@@ -115,7 +123,8 @@ func NewCmdSet(f *cmdutil.Factory, runF func(*SetOptions) error) *cobra.Command
return setRun(opts)
},
}
cmd.Flags().StringVarP(&opts.OrgName, "org", "o", "", "List secrets for an organization")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this description was wrong, fixed it while I was touching the code around.

Comment on lines 187 to 188
} else {
err = putRepoSecret(client, pk, baseRepo, opts.SecretName, encoded)
if envName != "" {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if it's the most idiomatic way of writing this, let me know if you prefer it as:

	if orgName != "" {
		err = putOrgSecret(client, host, pk, *opts, encoded)
	} else if envName != "" {
		err = putEnvSecret(client, pk, baseRepo, envName, opts.SecretName, encoded)
	} else {
		err = putRepoSecret(client, pk, baseRepo, opts.SecretName, encoded)
	}

Copy link
Contributor

Choose a reason for hiding this comment

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

Collapsing that nested conditional nto the else as you suggested would be a welcome change; it's so minor I'll just push a commit before I merge.

@@ -204,6 +216,46 @@ func Test_setRun_repo(t *testing.T) {
assert.Equal(t, payload.EncryptedValue, "UKYUCbHd0DJemxa3AOcZ6XcsBwALG9d4bpB8ZT0gSV39vl3BHiGSgj8zJapDxgB2BwqNqRhpjC4=")
}

func Test_setRun_env(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is almost like Test_setRun_repo above, except the 2nd mock and the EnvName option... Might be better to parametrize the existing test?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is fine for now!

@browniebroke browniebroke marked this pull request as ready for review June 2, 2021 15:18
@cliAutomation cliAutomation added this to Needs review 🤔 in The GitHub CLI Jun 2, 2021
@vilmibm vilmibm self-requested a review June 2, 2021 16:50
The GitHub CLI automation moved this from Needs review 🤔 to Needs to be merged 🎉 Jun 2, 2021
Copy link
Contributor

@vilmibm vilmibm left a comment

Choose a reason for hiding this comment

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

Thanks for this!! It's super helpful and I appreciate how neatly you fit it into our existing code/UX.

@@ -204,6 +216,46 @@ func Test_setRun_repo(t *testing.T) {
assert.Equal(t, payload.EncryptedValue, "UKYUCbHd0DJemxa3AOcZ6XcsBwALG9d4bpB8ZT0gSV39vl3BHiGSgj8zJapDxgB2BwqNqRhpjC4=")
}

func Test_setRun_env(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is fine for now!

Comment on lines 187 to 188
} else {
err = putRepoSecret(client, pk, baseRepo, opts.SecretName, encoded)
if envName != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Collapsing that nested conditional nto the else as you suggested would be a welcome change; it's so minor I'll just push a commit before I merge.

@vilmibm vilmibm enabled auto-merge June 2, 2021 18:29
@vilmibm vilmibm merged commit 71547f4 into cli:trunk Jun 2, 2021
The GitHub CLI automation moved this from Needs to be merged 🎉 to Pending Release 🥚 Jun 2, 2021
@browniebroke browniebroke deleted the feat/set-env-secrets branch June 2, 2021 18:39
@github-actions github-actions bot moved this from Pending Release 🥚 to Done 💤 in The GitHub CLI Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
The GitHub CLI
  
Done 💤
Development

Successfully merging this pull request may close these issues.

Add support for environment secrets
2 participants