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 new methods from the most recent org memberships API enhancements #841

Merged
merged 15 commits into from
Dec 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
81 changes: 81 additions & 0 deletions lib/octokit/client/organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def organization(org, options = {})
# @option values [String] :email Publicly visible email address.
# @option values [String] :location Location of organization.
# @option values [String] :name GitHub username for organization.
# @option values [String] :default_repository_permission The default permission members have on organization repositories.
# @option values [Boolean] :members_can_create_repositories Set true to allow members to create repositories on the organization.
# @return [Sawyer::Resource] Hash representing GitHub organization.
# @see https://developer.github.com/v3/orgs/#edit-an-organization
# @example
Expand Down Expand Up @@ -207,6 +209,69 @@ def organization_public_member?(org, user, options = {})
end
alias :org_public_member? :organization_public_member?

# List pending organization invitations
#
# Requires authenticated organization member.
#
# @param org [String, Integer] Organization GitHub login or id.
# @return [Array<Sawyer::Resource>] Array of hashes representing invitations.
# @see https://developer.github.com/v3/orgs/members/#list-pending-organization-invitations
#
# @example
# @client.organization_invitations('github')
def organization_invitations(org, options = {})
options = ensure_api_media_type(:org_memberships, options)
get "#{Organization.path org}/invitations", options
end
Copy link
Member

Choose a reason for hiding this comment

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

Since we support aliases for the other organization methods, what do you think about supporting:

alias :org_invitations :organization_invitations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed -- added in 4dd9c28

alias :org_invitations :organization_invitations

# List outside collaborators for an organization
#
# Requires authenticated organization members.
#
# @param org [String, Integer] Organization GitHub login or id.
# @return [Array<Sawyer::Resource>] Array of hashes representing users.
# @see https://developer.github.com/v3/orgs/outside-collaborators/#list-outside-collaborators
#
# @example
# @client.outside_collaborators('github')
def outside_collaborators(org, options={})
options = ensure_api_media_type(:org_memberships, options)
get "#{Organization.path org}/outside_collaborators", options
end

# Remove outside collaborator from an organization
#
# Requires authenticated organization members.
#
# @param org [String, Integer] Organization GitHub login or id.
# @param user [String] GitHub username to be removed as outside collaborator
# @return [Boolean] Return true if outside collaborator removed from organization, false otherwise.
# @see https://developer.github.com/v3/orgs/outside-collaborators/#remove-outside-collaborator
#
# @example
# @client.remove_outside_collaborator('github', 'lizzhale')
def remove_outside_collaborator(org, user, options={})
options = ensure_api_media_type(:org_memberships, options)
boolean_from_response :delete, "#{Organization.path org}/outside_collaborators/#{user}", options
end

# Converts an organization member to an outside collaborator
#
# Requires authenticated organization members.
#
# @param org [String, Integer] Organization GitHub login or id.
# @param user [String] GitHub username to be removed as outside collaborator
# @return [Boolean] Return true if outside collaborator removed from organization, false otherwise.
# @see https://developer.github.com/v3/orgs/outside-collaborators/#convert-member-to-outside-collaborator
#
# @example
# @client.convert_to_outside_collaborator('github', 'lizzhale')
def convert_to_outside_collaborator(org, user, options={})
options = ensure_api_media_type(:org_memberships, options)
boolean_from_response :put, "#{Organization.path org}/outside_collaborators/#{user}", options
end

# List teams
#
# Requires authenticated organization member.
Expand All @@ -230,6 +295,7 @@ def organization_teams(org, options = {})
# @param org [String, Integer] Organization GitHub login or id.
# @option options [String] :name Team name.
# @option options [Array<String>] :repo_names Repositories for the team.
# @option options [Array<String>] :maintainers Maintainers for the team.
# @return [Sawyer::Resource] Hash representing new team.
# @see https://developer.github.com/v3/orgs/teams/#create-team
# @example
Expand Down Expand Up @@ -367,6 +433,21 @@ def team_member?(team_id, user, options = {})
boolean_from_response :get, "teams/#{team_id}/members/#{user}", options
end

# List pending team invitations
#
# Requires authenticated organization member.
#
# @param team_id [Integer] Team id.
# @return [Array<Sawyer::Resource>] Array of hashes representing invitations.
# @see https://developer.github.com/v3/orgs/teams/#list-pending-team-invitations
#
# @example
# @client.team_invitations('github')
def team_invitations(team_id, options = {})
options = ensure_api_media_type(:org_memberships, options)
get "teams/#{team_id}/invitations", options
end

# List team repositories
#
# Requires authenticated organization member.
Expand Down
16 changes: 16 additions & 0 deletions lib/octokit/client/repositories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ def remove_deploy_key(repo, id, options = {})
# Requires authenticated client for private repos.
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @option options [String] :affiliation Filters the return array by affiliation.
# Can be one of: <tt>outside</tt> or <tt>all</tt>.
# If not specified, defaults to <tt>all</tt>
# @return [Array<Sawyer::Resource>] Array of hashes representing collaborating users.
# @see https://developer.github.com/v3/repos/collaborators/#list-collaborators
# @example
Expand Down Expand Up @@ -346,6 +349,19 @@ def collaborator?(repo, collaborator, options={})
boolean_from_response :get, "#{Repository.path repo}/collaborators/#{collaborator}", options
end

# Get a user's permission level for a repo.
#
# Requires authenticated client
#
# @return [Sawyer::Resource] Hash representing the user's permission level for the given repository
# @see https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level
# @example
# @client.permission_level('octokit/octokit.rb', 'lizzhale')
def permission_level(repo, collaborator, options={})
options = ensure_api_media_type(:org_memberships, options)
get "#{Repository.path repo}/collaborators/#{collaborator}/permission", options
end

# List teams for a repo
#
# Requires authenticated client that is an owner or collaborator of the repo.
Expand Down
3 changes: 2 additions & 1 deletion lib/octokit/preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ module Preview
:issue_timelines => 'application/vnd.github.mockingbird-preview+json'.freeze,
:pages => 'application/vnd.github.mister-fantastic-preview+json'.freeze,
:projects => 'application/vnd.github.inertia-preview+json'.freeze,
:traffic => 'application/vnd.github.spiderman-preview'.freeze
:traffic => 'application/vnd.github.spiderman-preview'.freeze,
:org_membership => 'application/vnd.github.korra-preview'.freeze
}

def ensure_api_media_type(type, options)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"http_interactions":[{"request":{"method":"get","uri":"https://api.github.com/orgs/<GITHUB_TEST_ORGANIZATION>/invitations","body":{"encoding":"US-ASCII","base64_string":""},"headers":{"Accept":["application/vnd.github.korra-preview+json"],"User-Agent":["Octokit Ruby Gem 4.6.0"],"Content-Type":["application/json"],"Authorization":["token <<ACCESS_TOKEN>>"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Server":["GitHub.com"],"Date":["Fri, 18 Nov 2016 03:57:21 GMT"],"Content-Type":["application/json; charset=utf-8"],"Content-Length":["2"],"Status":["200 OK"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["3785"],"X-Ratelimit-Reset":["1479443057"],"Cache-Control":["private, max-age=60, s-maxage=60"],"Vary":["Accept, Authorization, Cookie, X-GitHub-OTP","Accept-Encoding"],"Etag":["\"74981bad1a2cd19e46517a1fba85716c\""],"X-Oauth-Scopes":["admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user"],"X-Accepted-Oauth-Scopes":["admin:org, repo"],"X-Github-Media-Type":["github.korra-preview; format=json"],"Access-Control-Expose-Headers":["ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"],"Access-Control-Allow-Origin":["*"],"Content-Security-Policy":["default-src 'none'"],"Strict-Transport-Security":["max-age=31536000; includeSubdomains; preload"],"X-Content-Type-Options":["nosniff"],"X-Frame-Options":["deny"],"X-Xss-Protection":["1; mode=block"],"X-Served-By":["2c18a09f3ac5e4dd1e004af7c5a94769"],"X-Github-Request-Id":["32B88C12:14AE7:BB5088B:582E7C20"]},"body":{"encoding":"UTF-8","base64_string":"W10=\n"},"http_version":null},"recorded_at":"Fri, 18 Nov 2016 03:57:21 GMT"}],"recorded_with":"VCR 2.9.3"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"http_interactions":[{"request":{"method":"get","uri":"https://api.github.com/orgs/<GITHUB_TEST_ORGANIZATION>/outside_collaborators","body":{"encoding":"US-ASCII","base64_string":""},"headers":{"Accept":["application/vnd.github.korra-preview+json"],"User-Agent":["Octokit Ruby Gem 4.6.0"],"Content-Type":["application/json"],"Authorization":["token <<ACCESS_TOKEN>>"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Server":["GitHub.com"],"Date":["Fri, 18 Nov 2016 03:57:22 GMT"],"Content-Type":["application/json; charset=utf-8"],"Content-Length":["2"],"Status":["200 OK"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["3784"],"X-Ratelimit-Reset":["1479443057"],"Cache-Control":["private, max-age=60, s-maxage=60"],"Vary":["Accept, Authorization, Cookie, X-GitHub-OTP","Accept-Encoding"],"Etag":["\"74981bad1a2cd19e46517a1fba85716c\""],"X-Oauth-Scopes":["admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user"],"X-Accepted-Oauth-Scopes":["admin:org, read:org, repo, write:org"],"X-Github-Media-Type":["github.korra-preview; format=json"],"Access-Control-Expose-Headers":["ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"],"Access-Control-Allow-Origin":["*"],"Content-Security-Policy":["default-src 'none'"],"Strict-Transport-Security":["max-age=31536000; includeSubdomains; preload"],"X-Content-Type-Options":["nosniff"],"X-Frame-Options":["deny"],"X-Xss-Protection":["1; mode=block"],"X-Served-By":["7f48e2f7761567e923121f17538d7a6d"],"X-Github-Request-Id":["32B88C12:14AE5:B454A61:582E7C22"]},"body":{"encoding":"UTF-8","base64_string":"W10=\n"},"http_version":null},"recorded_at":"Fri, 18 Nov 2016 03:57:22 GMT"}],"recorded_with":"VCR 2.9.3"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"http_interactions":[{"request":{"method":"post","uri":"https://api.github.com/orgs/<GITHUB_TEST_ORGANIZATION>/teams","body":{"encoding":"UTF-8","base64_string":"eyJuYW1lIjoiVGVzdCBUZWFtIDE0Nzk0NDE0MzYifQ==\n"},"headers":{"Accept":["application/vnd.github.v3+json"],"User-Agent":["Octokit Ruby Gem 4.6.0"],"Content-Type":["application/json"],"Authorization":["token <<ACCESS_TOKEN>>"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":201,"message":"Created"},"headers":{"Server":["GitHub.com"],"Date":["Fri, 18 Nov 2016 03:57:17 GMT"],"Content-Type":["application/json; charset=utf-8"],"Content-Length":["1101"],"Status":["201 Created"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["3788"],"X-Ratelimit-Reset":["1479443057"],"Cache-Control":["private, max-age=60, s-maxage=60"],"Vary":["Accept, Authorization, Cookie, X-GitHub-OTP","Accept-Encoding"],"Etag":["\"f97162330b62476fd43359411401426c\""],"X-Oauth-Scopes":["admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user"],"X-Accepted-Oauth-Scopes":["admin:org, repo"],"Location":["https://api.github.com/teams/<GITHUB_TEST_ORG_TEAM_ID>"],"X-Github-Media-Type":["github.v3; format=json"],"Access-Control-Expose-Headers":["ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"],"Access-Control-Allow-Origin":["*"],"Content-Security-Policy":["default-src 'none'"],"Strict-Transport-Security":["max-age=31536000; includeSubdomains; preload"],"X-Content-Type-Options":["nosniff"],"X-Frame-Options":["deny"],"X-Xss-Protection":["1; mode=block"],"X-Served-By":["d256f86292c6dde5d09d15d926ec67a3"],"X-Github-Request-Id":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fT1JHQU5JWkFUSU9O\nPi9ob29rcyIsImlzc3Vlc191cmwiOiJodHRwczovL2FwaS5naXRodWIuY29t\nL29yZ3MvPEdJVEhVQl9URVNUX09SR0FOSVpBVElPTj4vaXNzdWVzIiwibWVt\nYmVyc191cmwiOiJodHRwczovL2FwaS5naXRodWIuY29tL29yZ3MvPEdJVEhV\nQl9URVNUX09SR0FOSVpBVElPTj4vbWVtYmVyc3svbWVtYmVyfSIsInB1Ymxp\nY19tZW1iZXJzX3VybCI6Imh0dHBzOi8vYXBpLmdpdGh1Yi5jb20vb3Jncy88\nR0lUSFVCX1RFU1RfT1JHQU5JWkFUSU9OPi9wdWJsaWNfbWVtYmVyc3svbWVt\nYmVyfSIsImF2YXRhcl91cmwiOiJodHRwczovL2F2YXRhcnMuZ2l0aHVidXNl\ncmNvbnRlbnQuY29tL3UvMjM1NDYyNjA/dj0zIiwiZGVzY3JpcHRpb24iOm51\nbGwsInB1YmxpY19yZXBvcyI6MCwicHVibGljX2dpc3RzIjowLCJmb2xsb3dl\ncnMiOjAsImZvbGxvd2luZyI6MCwiaHRtbF91cmwiOiJodHRwczovL2dpdGh1\nYi5jb20vPEdJVEhVQl9URVNUX09SR0FOSVpBVElPTj4iLCJjcmVhdGVkX2F0\nIjoiMjAxNi0xMS0xOFQwMzo1NDo1OFoiLCJ1cGRhdGVkX2F0IjoiMjAxNi0x\nMS0xOFQwMzo1NDo1OFoiLCJ0eXBlIjoiT3JnYW5pemF0aW9uIn19\n"},"http_version":null},"recorded_at":"Fri, 18 Nov 2016 03:57:17 GMT"},{"request":{"method":"get","uri":"https://api.github.com/teams/<GITHUB_TEST_ORG_TEAM_ID>/invitations","body":{"encoding":"US-ASCII","base64_string":""},"headers":{"Accept":["application/vnd.github.korra-preview+json"],"User-Agent":["Octokit Ruby Gem 4.6.0"],"Content-Type":["application/json"],"Authorization":["token <<ACCESS_TOKEN>>"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Server":["GitHub.com"],"Date":["Fri, 18 Nov 2016 03:57:17 GMT"],"Content-Type":["application/json; charset=utf-8"],"Content-Length":["2"],"Status":["200 OK"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["3787"],"X-Ratelimit-Reset":["1479443057"],"Cache-Control":["private, max-age=60, s-maxage=60"],"Vary":["Accept, Authorization, Cookie, X-GitHub-OTP","Accept-Encoding"],"Etag":["\"74981bad1a2cd19e46517a1fba85716c\""],"X-Oauth-Scopes":["admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user"],"X-Accepted-Oauth-Scopes":["admin:org, repo"],"X-Github-Media-Type":["github.korra-preview; format=json"],"Access-Control-Expose-Headers":["ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"],"Access-Control-Allow-Origin":["*"],"Content-Security-Policy":["default-src 'none'"],"Strict-Transport-Security":["max-age=31536000; includeSubdomains; preload"],"X-Content-Type-Options":["nosniff"],"X-Frame-Options":["deny"],"X-Xss-Protection":["1; mode=block"],"X-Served-By":["a241e1a8264a6ace03db946c85b92db3"],"X-Github-Request-Id":["32B88C12:14AE7:BB5071E:582E7C1D"]},"body":{"encoding":"UTF-8","base64_string":"W10=\n"},"http_version":null},"recorded_at":"Fri, 18 Nov 2016 03:57:18 GMT"},{"request":{"method":"delete","uri":"https://api.github.com/teams/<GITHUB_TEST_ORG_TEAM_ID>","body":{"encoding":"UTF-8","base64_string":"e30=\n"},"headers":{"Accept":["application/vnd.github.v3+json"],"User-Agent":["Octokit Ruby Gem 4.6.0"],"Content-Type":["application/json"],"Authorization":["token <<ACCESS_TOKEN>>"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":204,"message":"No Content"},"headers":{"Server":["GitHub.com"],"Date":["Fri, 18 Nov 2016 03:57:18 GMT"],"Status":["204 No Content"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["3786"],"X-Ratelimit-Reset":["1479443057"],"X-Oauth-Scopes":["admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user"],"X-Accepted-Oauth-Scopes":["admin:org, repo"],"X-Github-Media-Type":["github.v3; format=json"],"Access-Control-Expose-Headers":["ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"],"Access-Control-Allow-Origin":["*"],"Content-Security-Policy":["default-src 'none'"],"Strict-Transport-Security":["max-age=31536000; includeSubdomains; preload"],"X-Content-Type-Options":["nosniff"],"X-Frame-Options":["deny"],"X-Xss-Protection":["1; mode=block"],"Vary":["Accept-Encoding"],"X-Served-By":["76d9828c7e4f1d910f7ba069e90ce976"],"X-Github-Request-Id":["32B88C12:14AE5:B454800:582E7C1E"]},"body":{"encoding":"UTF-8","base64_string":""},"http_version":null},"recorded_at":"Fri, 18 Nov 2016 03:57:18 GMT"}],"recorded_with":"VCR 2.9.3"}
Loading