Skip to content

Added listing outside collaborators for an organization#538

Closed
glapul wants to merge 4 commits intogoogle:masterfrom
glapul:outside_collaborators
Closed

Added listing outside collaborators for an organization#538
glapul wants to merge 4 commits intogoogle:masterfrom
glapul:outside_collaborators

Conversation

@glapul
Copy link
Copy Markdown
Contributor

@glapul glapul commented Feb 1, 2017

2fa_disabled filter is supported too.

I created a new file [orgs_outside_collaborators.go], but I'm not sure whether it wouldn't be better to rename [orgs_members.go] to something like [orgs_members_and_outside_collaborators.go] as it's not clear to me where would the function that converts a member to an outside collaborator fit best.

[orgs_outside_collaborators_test.go] contains tests that are basically recycled from [orgs_members_test.go].

I thought about adding an integration test, but I think that setting up a test scenario is either very hard or straight impossible right now (as we would have to be able to create an organisation and users, which I think is impossible without an Github Enterprise account).
So I fell back to testing it a bit by hand, and those tests passed.

By the way, it's not clear to me why only the organisation's owner can list the organisation's outside collaborators (that's the response API gave me when I tried listing google's). It seems that this is inferrable by just going through all the organisation's repositories, so being a member should suffice. Or am I missing something?

2fa_disabled filter is supported too.
@gmlewis
Copy link
Copy Markdown
Collaborator

gmlewis commented Feb 1, 2017

Why not extend the already-existing Organizations.ListMembers method (in orgs_members.go) and make OutsideCollaborators bool a new option of ListMembersOptions ?

It currently already handles the PublicOnly option and seems like a good fit to me.

As an added bonus, it already has all the Filter and ListOptions ready-to-go.

@dmitshur
Copy link
Copy Markdown
Member

dmitshur commented Feb 1, 2017

@gmlewis, that's a good idea to consider.

However, I see that GitHub API really lists this as a separate endpoint. Compare:

Additionally, removing an outside collaborator is also different than removing a normal member:

Our current method for removing organization members does not take an options struct:

https://godoc.org/github.com/google/go-github/github#OrganizationsService.RemoveMember

So we would be forced to have a different method for removal (or add an options struct).

You can also "convert member to outside collaborator". It suggests to me these things are different enough that listing them via different endpoints makes sense.

While the idea of merging the listing endpoints makes sense now, I worry that future changes/additions to the API that further diverge outside collaborators and members may cause trouble for our API.

What do you think?

@gmlewis
Copy link
Copy Markdown
Collaborator

gmlewis commented Feb 1, 2017

OK, I'm fine with keeping it separate then, @shurcooL.

Copy link
Copy Markdown
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, @glapul - thank you!
Just a few minor changes requested.

Comment thread github/orgs_outside_collaborators.go Outdated
@@ -0,0 +1,51 @@
// Copyright 2016 The go-github AUTHORS. All rights reserved.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/2016/2017/

Comment thread github/orgs_outside_collaborators.go Outdated
}

req, err := s.client.NewRequest("GET", u, nil)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nix blank line between API call and err check

Comment thread github/orgs_outside_collaborators.go Outdated
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeOrgMembershipPreview)

members := new([]*User)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

	var members []*User
	resp, err := s.client.Do(req, &members)
	if err != nil {
		return nil, resp, err
	}

	return members, resp, nil

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see these changes... do you need to push them?

@@ -0,0 +1,46 @@
// Copyright 2016 The go-github AUTHORS. All rights reserved.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/2016/2017/

defer teardown()

mux.HandleFunc("/orgs/o/outside_collaborators", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add test for preview header... see other examples in repo

Comment thread github/orgs_outside_collaborators.go Outdated
// Warning: The API may change without advance notice during the preview period.
// Preview features are not supported for production use.
//
// GitHub API docs: https://developer.github.com/v3/orgs/outside_collaborators/
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glapul
Copy link
Copy Markdown
Contributor Author

glapul commented Feb 3, 2017

Done.

Comment thread github/orgs_outside_collaborators.go Outdated
}

return *members, resp, err
return members, resp, err
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return members, resp, nil

Copy link
Copy Markdown
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @glapul!

@gmlewis
Copy link
Copy Markdown
Collaborator

gmlewis commented Feb 3, 2017

Awaiting second LGTM.

@dmitshur dmitshur self-assigned this Feb 13, 2017
Copy link
Copy Markdown
Member

@dmitshur dmitshur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. /cc @gmlewis

See a couple minor questions/comments inline.

// 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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 // TODO: remove custom Accept header when this API fully launches. comments in code, and GitHub API itself is a good source for knowing which endpoints are stable or not.

I'm not against it, just a thought, because this is the first comment of its kind.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh okay, keeping it is perfectly fine then. Thanks!


// ListOutsideCollaborators lists outside collaborators of organization's repositories.
// This will only work if the authenticated
// user is an owner of the organization.
Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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.

@dmitshur dmitshur removed their assignment Feb 13, 2017
@gmlewis
Copy link
Copy Markdown
Collaborator

gmlewis commented Feb 22, 2017

It looks like this was ready to merge and I think I dropped the ball by not getting it in before the context changes.

I'm thinking that while I'm rebasing, that I could add a commit before squashing that adds context.

Does that sound reasonable to you, @shurcooL, or do you have an alternative proposal?

@dmitshur
Copy link
Copy Markdown
Member

Yes, this PR is just 1 logical commit + 3 adjustments based on review comments. I think you should rebase them, add context support and squash everything into one commit before merging into master.

Add more commits by pushing to the outside_collaborators branch on glapul/go-github.

You can also do that.

@gmlewis
Copy link
Copy Markdown
Collaborator

gmlewis commented Feb 22, 2017

SGTM. Adjusting and merging.

@gmlewis gmlewis closed this in 93f95bf Feb 22, 2017
@gmlewis
Copy link
Copy Markdown
Collaborator

gmlewis commented Feb 22, 2017

Integrated in 93f95bf

bubg-dev pushed a commit to bubg-dev/go-github that referenced this pull request Jun 16, 2017
2fa_disabled filter is supported too.

Closes google#538.

Change-Id: I7513435eebd2a20d2392cdb375818b3c8e80accd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants