-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e63bc70
Added support to list custom roles for organizations
tamboliasir1 bdcc034
Updated naming and comments for Organization Custom Repo Roles
tamboliasir1 75ab6ab
Update github/org_custom_roles.go
gmlewis b01926c
Updated typos in github/org_custom_roles.go
tamboliasir1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package github | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| ) | ||
|
|
||
| // OrginizationCustomRoles represents custom repository roles available in specified organization | ||
gmlewis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| type OrginizationCustomRoles struct { | ||
gmlewis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| TotalCount *int `json:"total_count,omitempty"` | ||
| CustomRoles []*CustomRoles `json:"custom_roles,omitempty"` | ||
gmlewis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // CustomRoles represents information of custom roles | ||
gmlewis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| type CustomRoles struct { | ||
gmlewis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ID *int64 `json:"id,omitempty"` | ||
| Name *string `json:"name,omitempty"` | ||
| } | ||
|
|
||
| // List Custome Roles in Org | ||
gmlewis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // | ||
| // GitHub API docs: https://docs.github.com/en/rest/reference/orgs#custom-repository-roles | ||
gmlewis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| func (s *OrganizationsService) ListCustomRoles(ctx context.Context, organization_id string) (*OrginizationCustomRoles, *Response, error) { | ||
gmlewis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| u := fmt.Sprintf("organizations/%v/custom_roles", organization_id) | ||
|
|
||
| req, err := s.client.NewRequest("GET", u, nil) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| custom_roles := new(OrginizationCustomRoles) | ||
| resp, err := s.client.Do(ctx, req, custom_roles) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return custom_roles, resp, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package github | ||
gmlewis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/http" | ||
| "testing" | ||
|
|
||
| "github.com/google/go-cmp/cmp" | ||
| ) | ||
|
|
||
| func TestOrganizationsService_ListCustomRoles(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.ListCustomRoles(ctx, "o") | ||
| if err != nil { | ||
| t.Errorf("Organizations.ListCustomRoles returned error: %v", err) | ||
| } | ||
|
|
||
| want := &OrginizationCustomRoles{TotalCount: Int(1), CustomRoles: []*CustomRoles{{ID: Int64(1), Name: String("Developer")}}} | ||
| if !cmp.Equal(apps, want) { | ||
| t.Errorf("Organizations.ListCustomRoles returned %+v, want %+v", apps, want) | ||
| } | ||
|
|
||
| const methodName = "ListCustomRoles" | ||
| testBadOptions(t, methodName, func() (err error) { | ||
| _, _, err = client.Organizations.ListCustomRoles(ctx, "\no") | ||
| return err | ||
| }) | ||
|
|
||
| testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { | ||
| got, resp, err := client.Organizations.ListCustomRoles(ctx, "o") | ||
| if got != nil { | ||
| t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) | ||
| } | ||
| return resp, err | ||
| }) | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.