Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.5k
Add support to list custom roles for organizations#2336
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
e63bc70bdcc03475ab6abb01926cFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Copyright 2022 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" | ||
| "fmt" | ||
| ) | ||
| // OrganizationCustomRepoRoles represents custom repository roles available in specified organization. | ||
| type OrganizationCustomRepoRoles struct { | ||
| TotalCount *int `json:"total_count,omitempty"` | ||
| CustomRepoRoles []*CustomRepoRoles `json:"custom_roles,omitempty"` | ||
| } | ||
| // CustomRepoRoles represents custom repository roles for an organization. | ||
| // See https://docs.github.com/en/enterprise-cloud@latest/organizations/managing-peoples-access-to-your-organization-with-roles/managing-custom-repository-roles-for-an-organization | ||
| // for more information. | ||
| type CustomRepoRoles struct { | ||
| ID *int64 `json:"id,omitempty"` | ||
| Name *string `json:"name,omitempty"` | ||
| } | ||
| // ListCustomRepoRoles lists the custom repository roles available in this organization. | ||
| // In order to see custom repository roles in an organization, the authenticated user must be an organization owner. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/en/rest/orgs/custom-roles | ||
| func (s *OrganizationsService) ListCustomRepoRoles(ctx context.Context, org string) (*OrganizationCustomRepoRoles, *Response, error) { | ||
| u := fmt.Sprintf("organizations/%v/custom_roles", org) | ||
| req, err := s.client.NewRequest("GET", u, nil) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
| customRepoRoles := new(OrganizationCustomRepoRoles) | ||
| resp, err := s.client.Do(ctx, req, customRepoRoles) | ||
gmlewis marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
| return customRepoRoles, resp, nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Copyright 2022 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 | ||
gmlewis marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/http" | ||
| "testing" | ||
| "github.com/google/go-cmp/cmp" | ||
| ) | ||
| func TestOrganizationsService_ListCustomRepoRoles(t *testing.T) { | ||
| client, mux, _, teardown := setup() | ||
| defer teardown() | ||
| mux.HandleFunc("/organizations/o/custom_roles", func(w http.ResponseWriter, r *http.Request) { | ||
| testMethod(t, r, "GET") | ||
| fmt.Fprint(w, `{"total_count": 1, "custom_roles": [{ "id": 1, "name": "Developer"}]}`) | ||
| }) | ||
| ctx := context.Background() | ||
| apps, _, err := client.Organizations.ListCustomRepoRoles(ctx, "o") | ||
| if err != nil { | ||
| t.Errorf("Organizations.ListCustomRepoRoles returned error: %v", err) | ||
| } | ||
| want := &OrganizationCustomRepoRoles{TotalCount: Int(1), CustomRepoRoles: []*CustomRepoRoles{{ID: Int64(1), Name: String("Developer")}}} | ||
| if !cmp.Equal(apps, want) { | ||
| t.Errorf("Organizations.ListCustomRepoRoles returned %+v, want %+v", apps, want) | ||
| } | ||
| const methodName = "ListCustomRepoRoles" | ||
| testBadOptions(t, methodName, func() (err error) { | ||
| _, _, err = client.Organizations.ListCustomRepoRoles(ctx, "\no") | ||
| return err | ||
| }) | ||
| testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { | ||
| got, resp, err := client.Organizations.ListCustomRepoRoles(ctx, "o") | ||
| if got != nil { | ||
| t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) | ||
| } | ||
| return resp, err | ||
| }) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.