-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Added listing outside collaborators for an organization #538
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Copyright 2017 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 "fmt" | ||
|
|
||
| // ListOutsideCollaboratorsOptions specifies optional parameters to the | ||
| // OrganizationsService.ListOutsideCollaborators method. | ||
| type ListOutsideCollaboratorsOptions struct { | ||
| // Filter outside collaborators returned in the list. Possible values are: | ||
| // 2fa_disabled, all. Default is "all". | ||
| Filter string `url:"filter,omitempty"` | ||
|
|
||
| ListOptions | ||
| } | ||
|
|
||
| // ListOutsideCollaborators lists outside collaborators of organization's repositories. | ||
| // This will only work if the authenticated | ||
| // user is an owner of the organization. | ||
| // | ||
| // Warning: The API may change without advance notice during the preview period. | ||
| // Preview features are not supported for production use. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't usually include this warning in all other similar situations. Should we start doing it here? It'll create more work and might get out of date. We have the I'm not against it, just a thought, because this is the first comment of its kind.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not the first one, I copied it from another file using the same Accept header. (and thought that's the convention). I'll find the file when I'll get back home.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh okay, keeping it is perfectly fine then. Thanks! |
||
| // | ||
| // GitHub API docs: https://developer.github.com/v3/orgs/outside_collaborators/#list-outside-collaborators | ||
| func (s *OrganizationsService) ListOutsideCollaborators(org string, opt *ListOutsideCollaboratorsOptions) ([]*User, *Response, error) { | ||
| u := fmt.Sprintf("orgs/%v/outside_collaborators", org) | ||
| u, err := addOptions(u, opt) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| req, err := s.client.NewRequest("GET", u, nil) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| // TODO: remove custom Accept header when this API fully launches. | ||
| req.Header.Set("Accept", mediaTypeOrgMembershipPreview) | ||
|
|
||
| var members []*User | ||
| resp, err := s.client.Do(req, &members) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return members, resp, nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // Copyright 2017 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 ( | ||
| "fmt" | ||
| "net/http" | ||
| "reflect" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestOrganizationsService_ListOutsideCollaborators(t *testing.T) { | ||
| setup() | ||
| defer teardown() | ||
|
|
||
| mux.HandleFunc("/orgs/o/outside_collaborators", func(w http.ResponseWriter, r *http.Request) { | ||
| testMethod(t, r, "GET") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add test for preview header... see other examples in repo |
||
| testFormValues(t, r, values{ | ||
| "filter": "2fa_disabled", | ||
| "page": "2", | ||
| }) | ||
| testHeader(t, r, "Accept", mediaTypeOrgMembershipPreview) | ||
| fmt.Fprint(w, `[{"id":1}]`) | ||
| }) | ||
|
|
||
| opt := &ListOutsideCollaboratorsOptions{ | ||
| Filter: "2fa_disabled", | ||
| ListOptions: ListOptions{Page: 2}, | ||
| } | ||
| members, _, err := client.Organizations.ListOutsideCollaborators("o", opt) | ||
| if err != nil { | ||
| t.Errorf("Organizations.ListOutsideCollaborators returned error: %v", err) | ||
| } | ||
|
|
||
| want := []*User{{ID: Int(1)}} | ||
| if !reflect.DeepEqual(members, want) { | ||
| t.Errorf("Organizations.ListOutsideCollaborators returned %+v, want %+v", members, want) | ||
| } | ||
| } | ||
|
|
||
| func TestOrganizationsService_ListOutsideCollaborators_invalidOrg(t *testing.T) { | ||
| _, _, err := client.Organizations.ListOutsideCollaborators("%", nil) | ||
| testURLParseError(t, err) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, the sentence "This will only work if the authenticated user is an owner of the organization." can probably fit on a single line, instead of being split into two lines of lengths 40 and 37 characaters.
Also, question, what's the source of this statement? I don't see it mentioned in https://developer.github.com/v3/orgs/outside_collaborators/#list-outside-collaborators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While trying to use the API by hand I was informed (with an error) that only the owner can do this.