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

Add enterprise actions permissions endpoints and reorg files #2920

Merged
merged 22 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f1c331c
Add enterprise allowed actions
algorythmic Oct 25, 2022
5319263
Add enterprise actions permissions
algorythmic Oct 25, 2022
437c925
Add enterprise action permissions for orgs
algorythmic Oct 25, 2022
3eb4312
Move actions permissions out of action_runners.go
algorythmic Oct 25, 2022
7f8e2af
Update copyright
algorythmic Oct 25, 2022
c55315a
Update copyright
algorythmic Oct 25, 2022
e9b5264
Update copyright
algorythmic Oct 25, 2022
c2cd862
Update copyright
algorythmic Oct 25, 2022
33e666c
fixed tests with enterprise action permission endpoints
RickleAndMortimer Sep 14, 2023
1da39d7
formatting
RickleAndMortimer Sep 14, 2023
54e213a
reorganized urls for enterprise and orgs endpoints for action permiss…
RickleAndMortimer Sep 25, 2023
db1d21b
readded allowed permissions tests and copyright
RickleAndMortimer Sep 26, 2023
b64b8b8
linting
RickleAndMortimer Sep 26, 2023
dde3ba2
renaming to match original names prior to the PR
RickleAndMortimer Sep 26, 2023
18b5850
readded old orgs_actions_permissions as deprecated code
RickleAndMortimer Sep 26, 2023
055da67
file typo
RickleAndMortimer Sep 26, 2023
c9ce020
remove incorrectly named file
RickleAndMortimer Sep 26, 2023
324285e
readded org_actions tests
RickleAndMortimer Sep 26, 2023
b2f9d6c
Update github/orgs_actions_allowed.go
gmlewis Sep 29, 2023
11a21aa
Update github/orgs_actions_allowed.go
gmlewis Sep 29, 2023
ea8a460
Update github/orgs_actions_permissions.go
gmlewis Sep 29, 2023
0d02f81
Update github/orgs_actions_permissions.go
gmlewis Sep 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions github/actions_permissions_orgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (s *ActionsService) EditActionsPermissions(ctx context.Context, org string,
return p, resp, nil
}

// ListEnabledRepos lists the selected repositories that are enabled for GitHub Actions in an organization.
// ListEnabledReposInOrg lists the selected repositories that are enabled for GitHub Actions in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/actions/permissions#list-selected-repositories-enabled-for-github-actions-in-an-organization
func (s *ActionsService) ListEnabledReposInOrg(ctx context.Context, owner string, opts *ListOptions) (*ActionsEnabledOnOrgRepos, *Response, error) {
Expand All @@ -105,7 +105,7 @@ func (s *ActionsService) ListEnabledReposInOrg(ctx context.Context, owner string
return repos, resp, nil
}

// SetEnabledRepos replaces the list of selected repositories that are enabled for GitHub Actions in an organization..
// SetEnabledReposInOrg replaces the list of selected repositories that are enabled for GitHub Actions in an organization..
//
// GitHub API docs: https://docs.github.com/en/rest/actions/permissions#set-selected-repositories-enabled-for-github-actions-in-an-organization
func (s *ActionsService) SetEnabledReposInOrg(ctx context.Context, owner string, repositoryIDs []int64) (*Response, error) {
Expand All @@ -126,7 +126,7 @@ func (s *ActionsService) SetEnabledReposInOrg(ctx context.Context, owner string,
return resp, nil
}

// AddEnabledRepos adds a repository to the list of selected repositories that are enabled for GitHub Actions in an organization.
// AddEnabledReposInOrg adds a repository to the list of selected repositories that are enabled for GitHub Actions in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/actions/permissions#enable-a-selected-repository-for-github-actions-in-an-organization
func (s *ActionsService) AddEnabledReposInOrg(ctx context.Context, owner string, repositoryID int64) (*Response, error) {
Expand All @@ -145,7 +145,7 @@ func (s *ActionsService) AddEnabledReposInOrg(ctx context.Context, owner string,
return resp, nil
}

// RemoveEnabledRepo removes a single repository from the list of enabled repos for GitHub Actions in an organization.
// RemoveEnabledRepoInOrg removes a single repository from the list of enabled repos for GitHub Actions in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/actions/permissions#disable-a-selected-repository-for-github-actions-in-an-organization
func (s *ActionsService) RemoveEnabledReposInOrg(ctx context.Context, owner string, repositoryID int64) (*Response, error) {
Expand Down
8 changes: 4 additions & 4 deletions github/actions_permissions_orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ func TestActionsService_AddEnabledReposInOrg(t *testing.T) {
ctx := context.Background()
_, err := client.Actions.AddEnabledReposInOrg(ctx, "o", 123)
if err != nil {
t.Errorf("Actions.AddEnabledRepos returned error: %v", err)
t.Errorf("Actions.AddEnabledReposInOrg returned error: %v", err)
}

const methodName = "AddEnabledRepos"
const methodName = "AddEnabledReposInOrg"

testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.AddEnabledReposInOrg(ctx, "\n", 123)
Expand All @@ -205,10 +205,10 @@ func TestActionsService_RemoveEnabledReposInOrg(t *testing.T) {
ctx := context.Background()
_, err := client.Actions.RemoveEnabledReposInOrg(ctx, "o", 123)
if err != nil {
t.Errorf("Actions.RemoveEnabledRepo returned error: %v", err)
t.Errorf("Actions.RemoveEnabledReposInOrg returned error: %v", err)
}

const methodName = "RemoveEnabledRepo"
const methodName = "RemoveEnabledReposInOrg"

testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.RemoveEnabledReposInOrg(ctx, "\n", 123)
Expand Down
28 changes: 28 additions & 0 deletions github/orgs_actions_allowed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2021 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package github

import (
"context"
)

// GetActionsAllowed gets the actions that are allowed in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/actions/permissions#get-allowed-actions-and-reusable-workflows-for-an-organization
// Deprecated: please use `client.Actions.GetActionsAllowed` instead
gmlewis marked this conversation as resolved.
Show resolved Hide resolved
func (s *OrganizationsService) GetActionsAllowed(ctx context.Context, org string) (*ActionsAllowed, *Response, error) {
s2 := (*ActionsService)(s)
return s2.GetActionsAllowed(ctx, org)
}

// EditActionsAllowed sets the actions that are allowed in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/actions/permissions#set-allowed-actions-and-reusable-workflows-for-an-organization
// Deprecated: please use `client.Actions.EditActionsAllowed` instead
gmlewis marked this conversation as resolved.
Show resolved Hide resolved
func (s *OrganizationsService) EditActionsAllowed(ctx context.Context, org string, actionsAllowed ActionsAllowed) (*ActionsAllowed, *Response, error) {
s2 := (*ActionsService)(s)
return s2.EditActionsAllowed(ctx, org, actionsAllowed)
}
93 changes: 93 additions & 0 deletions github/orgs_actions_allowed_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright 2021 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package github

import (
"context"
"encoding/json"
"fmt"
"net/http"
"testing"

"github.com/google/go-cmp/cmp"
)

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

mux.HandleFunc("/orgs/o/actions/permissions/selected-actions", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"github_owned_allowed":true, "verified_allowed":false, "patterns_allowed":["a/b"]}`)
})

ctx := context.Background()
org, _, err := client.Organizations.GetActionsAllowed(ctx, "o")
if err != nil {
t.Errorf("Organizations.GetActionsAllowed returned error: %v", err)
}
want := &ActionsAllowed{GithubOwnedAllowed: Bool(true), VerifiedAllowed: Bool(false), PatternsAllowed: []string{"a/b"}}
if !cmp.Equal(org, want) {
t.Errorf("Organizations.GetActionsAllowed returned %+v, want %+v", org, want)
}

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

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

func TestOrganizationsService_EditActionsAllowed(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
input := &ActionsAllowed{GithubOwnedAllowed: Bool(true), VerifiedAllowed: Bool(false), PatternsAllowed: []string{"a/b"}}

mux.HandleFunc("/orgs/o/actions/permissions/selected-actions", func(w http.ResponseWriter, r *http.Request) {
v := new(ActionsAllowed)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, "PUT")
if !cmp.Equal(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}

fmt.Fprint(w, `{"github_owned_allowed":true, "verified_allowed":false, "patterns_allowed":["a/b"]}`)
})

ctx := context.Background()
org, _, err := client.Organizations.EditActionsAllowed(ctx, "o", *input)
if err != nil {
t.Errorf("Organizations.EditActionsAllowed returned error: %v", err)
}

want := &ActionsAllowed{GithubOwnedAllowed: Bool(true), VerifiedAllowed: Bool(false), PatternsAllowed: []string{"a/b"}}
if !cmp.Equal(org, want) {
t.Errorf("Organizations.EditActionsAllowed returned %+v, want %+v", org, want)
}

const methodName = "EditActionsAllowed"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Organizations.EditActionsAllowed(ctx, "\n", *input)
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Organizations.EditActionsAllowed(ctx, "o", *input)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
28 changes: 28 additions & 0 deletions github/orgs_actions_permissions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2021 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package github

import (
"context"
)

// GetActionsPermissions gets the GitHub Actions permissions policy for repositories and allowed actions in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/actions/permissions#get-github-actions-permissions-for-an-organization
// Deprecated: please use `client.Actions.GetActionsPermissions` instead
gmlewis marked this conversation as resolved.
Show resolved Hide resolved
func (s *OrganizationsService) GetActionsPermissions(ctx context.Context, org string) (*ActionsPermissions, *Response, error) {
s2 := (*ActionsService)(s)
return s2.GetActionsPermissions(ctx, org)
}

// EditActionsPermissions sets the permissions policy for repositories and allowed actions in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/actions/permissions#set-github-actions-permissions-for-an-organization
// Deprecated: please use `client.Actions.EditActionsPermissions` instead
gmlewis marked this conversation as resolved.
Show resolved Hide resolved
func (s *OrganizationsService) EditActionsPermissions(ctx context.Context, org string, actionsPermissions ActionsPermissions) (*ActionsPermissions, *Response, error) {
s2 := (*ActionsService)(s)
return s2.EditActionsPermissions(ctx, org, actionsPermissions)
}
94 changes: 94 additions & 0 deletions github/orgs_actions_permissions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright 2021 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package github

import (
"context"
"encoding/json"
"fmt"
"net/http"
"testing"

"github.com/google/go-cmp/cmp"
)

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

mux.HandleFunc("/orgs/o/actions/permissions", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"enabled_repositories": "all", "allowed_actions": "all"}`)
})

ctx := context.Background()
org, _, err := client.Organizations.GetActionsPermissions(ctx, "o")
if err != nil {
t.Errorf("Organizations.GetActionsPermissions returned error: %v", err)
}
want := &ActionsPermissions{EnabledRepositories: String("all"), AllowedActions: String("all")}
if !cmp.Equal(org, want) {
t.Errorf("Organizations.GetActionsPermissions returned %+v, want %+v", org, want)
}

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

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

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

input := &ActionsPermissions{EnabledRepositories: String("all"), AllowedActions: String("selected")}

mux.HandleFunc("/orgs/o/actions/permissions", func(w http.ResponseWriter, r *http.Request) {
v := new(ActionsPermissions)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, "PUT")
if !cmp.Equal(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}

fmt.Fprint(w, `{"enabled_repositories": "all", "allowed_actions": "selected"}`)
})

ctx := context.Background()
org, _, err := client.Organizations.EditActionsPermissions(ctx, "o", *input)
if err != nil {
t.Errorf("Organizations.EditActionsPermissions returned error: %v", err)
}

want := &ActionsPermissions{EnabledRepositories: String("all"), AllowedActions: String("selected")}
if !cmp.Equal(org, want) {
t.Errorf("Organizations.EditActionsPermissions returned %+v, want %+v", org, want)
}

const methodName = "EditActionsPermissions"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Organizations.EditActionsPermissions(ctx, "\n", *input)
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Organizations.EditActionsPermissions(ctx, "o", *input)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
Loading