From f12d59796580cda5e920f2b802b20cdef7493696 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Thu, 2 May 2024 06:04:51 +0000 Subject: [PATCH] feat(repo): support list of repo secrets (#660) - Update comment to correctly describe `ListOrgActionSecretOption` as listing organization secrets instead of members - Add new file `repo_action.go` with functionality to list a repository's secrets including the structure and API call Signed-off-by: Bo-Yi Wu Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/660 Reviewed-by: Lunny Xiao Co-authored-by: Bo-Yi Wu Co-committed-by: Bo-Yi Wu --- forgejo/org_action.go | 6 +++--- forgejo/repo_action.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 forgejo/repo_action.go diff --git a/forgejo/org_action.go b/forgejo/org_action.go index 4a78632..a392c45 100644 --- a/forgejo/org_action.go +++ b/forgejo/org_action.go @@ -1,4 +1,4 @@ -// Copyright 2024 The Forgjo Authors. All rights reserved. +// Copyright 2024 The Forgejo Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -13,12 +13,12 @@ import ( "net/url" ) -// ListOrgMembershipOption list OrgMembership options +// ListOrgActionSecretOption list OrgActionSecret options type ListOrgActionSecretOption struct { ListOptions } -// ListOrgMembership list an organization's members +// ListOrgActionSecret list an organization's secrets func (c *Client) ListOrgActionSecret(org string, opt ListOrgActionSecretOption) ([]*Secret, *Response, error) { if err := escapeValidatePathSegments(&org); err != nil { return nil, nil, err diff --git a/forgejo/repo_action.go b/forgejo/repo_action.go new file mode 100644 index 0000000..05b9043 --- /dev/null +++ b/forgejo/repo_action.go @@ -0,0 +1,33 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +// Copyright 2024 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package forgejo + +import ( + "fmt" + "net/url" +) + +// ListRepoActionSecretOption list RepoActionSecret options +type ListRepoActionSecretOption struct { + ListOptions +} + +// ListRepoActionSecret list a repository's secrets +func (c *Client) ListRepoActionSecret(user, repo string, opt ListRepoActionSecretOption) ([]*Secret, *Response, error) { + if err := escapeValidatePathSegments(&user, &repo); err != nil { + return nil, nil, err + } + opt.setDefaults() + secrets := make([]*Secret, 0, opt.PageSize) + + link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/actions/secrets", user, repo)) + link.RawQuery = opt.getURLQuery().Encode() + resp, err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, &secrets) + return secrets, resp, err +}