Skip to content

Commit

Permalink
Add func to get org secrets for repo
Browse files Browse the repository at this point in the history
Wrap the 'organization-secrets' endpoint for a repository to fetch
action secrets.
  • Loading branch information
tomfeigin committed Jan 25, 2024
1 parent 0f73585 commit ce9c9d4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
11 changes: 11 additions & 0 deletions github/actions_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ func (s *ActionsService) ListRepoSecrets(ctx context.Context, owner, repo string
return s.listSecrets(ctx, url, opts)
}

// ListRepoOrgSecrets lists all organization secrets available in a repository
// without revealing their encrypted values.
//
// GitHub API docs: https://docs.github.com/rest/actions/secrets#list-repository-organization-secrets
//
//meta:operation GET /repos/{owner}/{repo}/actions/organization-secrets
func (s *ActionsService) ListRepoOrgSecrets(ctx context.Context, owner, repo string, opts *ListOptions) (*Secrets, *Response, error) {
url := fmt.Sprintf("repos/%v/%v/actions/organization-secrets", owner, repo)
return s.listSecrets(ctx, url, opts)
}

// ListOrgSecrets lists all secrets available in an organization
// without revealing their encrypted values.
//
Expand Down
43 changes: 43 additions & 0 deletions github/actions_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,49 @@ func TestActionsService_ListRepoSecrets(t *testing.T) {
})
}

func TestActionsService_ListRepoOrgSecrets(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/repos/o/r/actions/organization-secrets", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"per_page": "2", "page": "2"})
fmt.Fprint(w, `{"total_count":4,"secrets":[{"name":"A","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"},{"name":"B","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}]}`)
})

opts := &ListOptions{Page: 2, PerPage: 2}
ctx := context.Background()
secrets, _, err := client.Actions.ListRepoOrgSecrets(ctx, "o", "r", opts)
if err != nil {
t.Errorf("Actions.ListRepoOrgSecrets returned error: %v", err)
}

want := &Secrets{
TotalCount: 4,
Secrets: []*Secret{
{Name: "A", CreatedAt: Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)}},
{Name: "B", CreatedAt: Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)}},
},
}
if !cmp.Equal(secrets, want) {
t.Errorf("Actions.ListRepoOrgSecrets returned %+v, want %+v", secrets, want)
}

const methodName = "ListRepoOrgSecrets"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Actions.ListRepoOrgSecrets(ctx, "\n", "\n", opts)
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Actions.ListRepoOrgSecrets(ctx, "o", "r", opts)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}

func TestActionsService_GetRepoSecret(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
Expand Down

0 comments on commit ce9c9d4

Please sign in to comment.