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

feat(API): update and delete secret for managing organization secrets #26660

Merged
merged 18 commits into from
Aug 24, 2023

Conversation

appleboy
Copy link
Member

@appleboy appleboy commented Aug 22, 2023

  • Add UpdateSecret function to modify org or user repo secret
  • Add DeleteSecret function to delete secret from an organization
  • Add UpdateSecretOption struct for updating secret options
  • Add UpdateOrgSecret function to update a secret in an organization
  • Add DeleteOrgSecret function to delete a secret in an organization

GitHub API

  1. Update Org Secret: https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#create-or-update-an-organization-secret
  2. Delete Org Secret: https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#delete-an-organization-secret

- Add `ChangeSecret` function to modify org or user repo secret
- Add `DeleteSecret` function to delete secret from an organization
- Add `UpdateSecretOption` struct for updating secret options
- Add `UpdateOrgSecret` function to update a secret in an organization
- Add `DeleteOrgSecret` function to delete a secret in an organization

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Aug 22, 2023
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 22, 2023
- Update the comment for the `UpdateOrgSecret` function
- Update the comment for the `DeleteOrgSecret` function

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
…late file

- Update the `UpdateSecretOption` struct in `modules/structs/secret.go`
- Update the summary comment for the `UpdateOrgSecret` function in `routers/api/v1/org/action.go`
- Update the summary comment for the `v1_json.tmpl` template file in `templates/swagger`
- Update the description for a field in the `v1_json.tmpl` template file in `templates/swagger`
- Update the description for another field in the `v1_json.tmpl` template file in `templates/swagger`
- Update the description for a third field in the `v1_json.tmpl` template file in `templates/swagger`
- Update the description for a fourth field in the `v1_json.tmpl` template file in `templates/swagger`
- Update the description for a fifth field in the `v1_json.tmpl` template file in `templates/swagger`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
@appleboy appleboy added this to the 1.21.0 milestone Aug 23, 2023
@techknowlogick
Copy link
Member

You use ChangeSecret and UpdateSecretOption, could you align the naming to use either change or update?
Also, how do these APIs compare to GitHub's for the same function?

- Change the function name from `ChangeSecret` to `UpdateSecret` in `models/secret/secret.go`
- Update the function call from `ChangeSecret` to `UpdateSecret` in `routers/api/v1/org/action.go`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
@appleboy
Copy link
Member Author

@techknowlogick 14b25cd for ChangeSecret and UpdateSecretOption, could you align the naming to use either change or update?

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Aug 23, 2023
@lunny lunny added type/enhancement An improvement of existing functionality modifies/api This PR adds API routes or modifies them labels Aug 23, 2023
models/secret/secret.go Outdated Show resolved Hide resolved
…use the changes made in the code do not fix a bug or introduce a new feature, but rather improve the structure or organization of the code.: refactor error handling and update secret functions

- Add `ErrSecretNotFound` type to represent a "secret not found" error
- Add `IsErrSecretNotFound` function to check if an error is a `ErrSecretNotFound`
- Implement `Error` method for `ErrSecretNotFound` type
- Implement `Unwrap` method for `ErrSecretNotFound` type
- Update `UpdateSecret` function to use `strings.ToUpper` for `name`
- Update query in `UpdateSecret` function to use `name` instead of `strings.ToUpper(name)`
- Return `ErrSecretNotFound` instead of `errors.New("secret not found")` in `UpdateSecret` function
- Return `ErrSecretNotFound` instead of `errors.New("secret not found")` in `DeleteSecret` function
- Update `UpdateOrgSecret` function to handle `ErrSecretNotFound` error and return 404 if secret is not found
- Update error message in `UpdateOrgSecret` function to "UpdateSecret" instead of "ChangeSecret"
- Update `DeleteOrgSecret` function to handle `ErrSecretNotFound` error and return 404 if secret is not found

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
- Add validation for the `Name` field in the `CreateOrgSecret` function

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
@appleboy
Copy link
Member Author

@wxiaoguang Fixed all that you mention.

@GiteaBot GiteaBot removed the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Aug 23, 2023
@GiteaBot GiteaBot added the lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. label Aug 23, 2023
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Aug 23, 2023
@lunny lunny enabled auto-merge (squash) August 24, 2023 01:09
@lunny lunny merged commit b62c8e7 into go-gitea:main Aug 24, 2023
23 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Aug 24, 2023
zjjhot added a commit to zjjhot/gitea that referenced this pull request Aug 24, 2023
* upstream/main:
  feat(API): update and delete secret for managing organization secrets (go-gitea#26660)
  Remove ref name in PR commits page (go-gitea#25876)
  Modify the content format of the Feishu webhook (go-gitea#25106)
  Handle "comment form combo editor init" more gracefully (go-gitea#26688)
  Prefer variables over subprocesses (go-gitea#26690)
  Fix archived unix time when archiving the label (go-gitea#26681)
  Make "link-action" backend code respond correct JSON content (go-gitea#26680)
  Fix doubled box-shadow in branch dropdown menu (go-gitea#26678)
  Refactor toast module (go-gitea#26677)
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Nov 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants