add delete repo/org action secrets
This commit is contained in:
parent
8cfbeccb09
commit
2f616bb0da
4 changed files with 60 additions and 0 deletions
|
@ -89,3 +89,28 @@ func (c *Client) CreateOrgActionSecret(org string, opt CreateSecretOption) (*Res
|
|||
return resp, fmt.Errorf("unexpected Status: %d", status)
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteOrgActionSecret deletes a secret for the specified organization in Forgejo Actions.
|
||||
// It takes the organization name, and the secret name as parameters.
|
||||
// The function returns the HTTP response and an error, if any.
|
||||
func (c *Client) DeleteOrgActionSecret(org, secretName string) (*Response, error) {
|
||||
if err := escapeValidatePathSegments(&org, &secretName); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
status, resp, err := c.getStatusCode("DELETE", fmt.Sprintf("/orgs/%s/actions/secrets/%s", org, secretName), nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch status {
|
||||
case http.StatusNoContent:
|
||||
return resp, nil
|
||||
case http.StatusNotFound:
|
||||
return resp, fmt.Errorf("forbidden")
|
||||
case http.StatusBadRequest:
|
||||
return resp, fmt.Errorf("bad request")
|
||||
default:
|
||||
return resp, fmt.Errorf("unexpected Status: %d", status)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,4 +40,9 @@ func TestCreateOrgActionSecret(t *testing.T) {
|
|||
secrets, _, err := c.ListOrgActionSecret(newOrg.UserName, ListOrgActionSecretOption{})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, secrets, 1)
|
||||
|
||||
// delete org secret
|
||||
resp, err = c.DeleteOrgActionSecret(newOrg.UserName, "test")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
|
||||
}
|
||||
|
|
|
@ -65,3 +65,28 @@ func (c *Client) CreateRepoActionSecret(user, repo string, opt CreateSecretOptio
|
|||
return resp, fmt.Errorf("unexpected Status: %d", status)
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteRepoActionSecret deletes a secret for the specified repository in Forgejo Actions.
|
||||
// It takes the repository name, owner, and the secret name as parameters.
|
||||
// The function returns the HTTP response and an error, if any.
|
||||
func (c *Client) DeleteRepoActionSecret(user, repo, secretName string) (*Response, error) {
|
||||
if err := escapeValidatePathSegments(&user, &repo, &secretName); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
status, resp, err := c.getStatusCode("DELETE", fmt.Sprintf("/repos/%s/%s/actions/secrets/%s", user, repo, secretName), nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch status {
|
||||
case http.StatusNoContent:
|
||||
return resp, nil
|
||||
case http.StatusNotFound:
|
||||
return resp, fmt.Errorf("forbidden")
|
||||
case http.StatusBadRequest:
|
||||
return resp, fmt.Errorf("bad request")
|
||||
default:
|
||||
return resp, fmt.Errorf("unexpected Status: %d", status)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,4 +32,9 @@ func TestCreateRepoActionSecret(t *testing.T) {
|
|||
secrets, _, err := c.ListRepoActionSecret(user.UserName, repo.Name, ListRepoActionSecretOption{})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, secrets, 1)
|
||||
|
||||
// delete repo secret
|
||||
resp, err = c.DeleteRepoActionSecret(user.UserName, repo.Name, "test")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue