From a9be28a2768fe515a28e33f666bfca1852d69c3e Mon Sep 17 00:00:00 2001 From: tomfeigin <10672011+tomfeigin@users.noreply.github.com> Date: Thu, 25 Jan 2024 12:11:58 +0200 Subject: [PATCH 1/2] Add func to get org vars for repo Wrap the 'organization-variables' endpoint for a repository to fetch action variables. --- github/actions_variables.go | 10 ++++++++ github/actions_variables_test.go | 43 ++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/github/actions_variables.go b/github/actions_variables.go index 244d159079e..aa0f23ca48d 100644 --- a/github/actions_variables.go +++ b/github/actions_variables.go @@ -59,6 +59,16 @@ func (s *ActionsService) ListRepoVariables(ctx context.Context, owner, repo stri return s.listVariables(ctx, url, opts) } +// ListRepoOrgVariables lists all organization variables available in a repository. +// +// GitHub API docs: https://docs.github.com/rest/actions/variables#list-repository-organization-variables +// +//meta:operation GET /repos/{owner}/{repo}/actions/organization-variables +func (s *ActionsService) ListRepoOrgVariables(ctx context.Context, owner, repo string, opts *ListOptions) (*ActionsVariables, *Response, error) { + url := fmt.Sprintf("repos/%v/%v/actions/organization-variables", owner, repo) + return s.listVariables(ctx, url, opts) +} + // ListOrgVariables lists all variables available in an organization. // // GitHub API docs: https://docs.github.com/rest/actions/variables#list-organization-variables diff --git a/github/actions_variables_test.go b/github/actions_variables_test.go index a9f773c261e..dcd648c25c3 100644 --- a/github/actions_variables_test.go +++ b/github/actions_variables_test.go @@ -58,6 +58,49 @@ func TestActionsService_ListRepoVariables(t *testing.T) { }) } +func TestActionsService_ListRepoOrgVariables(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/actions/organization-variables", 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,"variables":[{"name":"A","value":"AA","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"},{"name":"B","value":"BB","created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}]}`) + }) + + opts := &ListOptions{Page: 2, PerPage: 2} + ctx := context.Background() + variables, _, err := client.Actions.ListRepoOrgVariables(ctx, "o", "r", opts) + if err != nil { + t.Errorf("Actions.ListRepoOrgVariables returned error: %v", err) + } + + want := &ActionsVariables{ + TotalCount: 4, + Variables: []*ActionsVariable{ + {Name: "A", Value: "AA", 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", Value: "BB", 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(variables, want) { + t.Errorf("Actions.ListRepoOrgVariables returned %+v, want %+v", variables, want) + } + + const methodName = "ListRepoOrgVariables" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Actions.ListRepoOrgVariables(ctx, "\n", "\n", opts) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Actions.ListRepoOrgVariables(ctx, "o", "r", opts) + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + func TestActionsService_GetRepoVariable(t *testing.T) { client, mux, _, teardown := setup() defer teardown() From 22cf5a98012a7158f62622ef291f77fd3df34ab0 Mon Sep 17 00:00:00 2001 From: tomfeigin <10672011+tomfeigin@users.noreply.github.com> Date: Thu, 25 Jan 2024 12:12:03 +0200 Subject: [PATCH 2/2] Add func to get org secrets for repo Wrap the 'organization-secrets' endpoint for a repository to fetch action secrets. --- github/actions_secrets.go | 11 +++++++++ github/actions_secrets_test.go | 43 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/github/actions_secrets.go b/github/actions_secrets.go index 2d4ba98db30..d8d405c06d7 100644 --- a/github/actions_secrets.go +++ b/github/actions_secrets.go @@ -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. // diff --git a/github/actions_secrets_test.go b/github/actions_secrets_test.go index a1266d6bae6..a2ac169cd24 100644 --- a/github/actions_secrets_test.go +++ b/github/actions_secrets_test.go @@ -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()