Skip to content

Commit

Permalink
Merge pull request #928 from LizzHale/nested-teams-preview
Browse files Browse the repository at this point in the history
Add support for the new Nested Teams API preview
  • Loading branch information
tarebyte authored Sep 14, 2017
2 parents e914c26 + 9c5ac37 commit 3076c0f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/octokit/client/organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ def organization_teams(org, options = {})
# @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.
# @option options [Integer] :parent_team_id ID of a team to set as the parent team.
# @return [Sawyer::Resource] Hash representing new team.
# @see https://developer.github.com/v3/orgs/teams/#create-team
# @example
Expand All @@ -303,6 +304,9 @@ def create_team(org, options = {})
if options.key?(:permission)
octokit_warn "Deprecated: Passing :permission option to #create_team. Assign team repository permission by passing :permission to #add_team_repository instead."
end
if options.key?(:parent_team_id)
options = ensure_api_media_type(:nested_teams, options)
end
post "#{Organization.path org}/teams", options
end

Expand All @@ -319,6 +323,20 @@ def team(team_id, options = {})
get "teams/#{team_id}", options
end

# List child teams
#
# Requires authenticated organization member.
#
# @param team_id [Integer] Team id.
# @return [Sawyer::Resource] Hash representing team.
# @see https://developer.github.com/v3/orgs/teams/#list-child-teams
# @example
# @client.child_teams(100000, :accept => "application/vnd.github.hellcat-preview+json")
def child_teams(team_id, options = {})
options = ensure_api_media_type(:nested_teams, options)
paginate "teams/#{team_id}/teams", options
end

# Update team
#
# Requires authenticated organization owner.
Expand All @@ -330,6 +348,7 @@ def team(team_id, options = {})
# `pull` - team members can pull, but not push to or administer these repositories.
# `push` - team members can pull and push, but not administer these repositories.
# `admin` - team members can pull, push and administer these repositories.
# @option options [Integer] :parent_team_id ID of a team to set as the parent team.
# @return [Sawyer::Resource] Hash representing updated team.
# @see https://developer.github.com/v3/orgs/teams/#edit-team
# @example
Expand All @@ -338,6 +357,9 @@ def team(team_id, options = {})
# :permission => 'push'
# })
def update_team(team_id, options = {})
if options.key?(:parent_team_id)
options = ensure_api_media_type(:nested_teams, options)
end
patch "teams/#{team_id}", options
end

Expand Down
1 change: 1 addition & 0 deletions lib/octokit/preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Preview
:reactions => 'application/vnd.github.squirrel-girl-preview'.freeze,
:repository_invitations => 'application/vnd.github.swamp-thing-preview+json'.freeze,
:issue_timelines => 'application/vnd.github.mockingbird-preview+json'.freeze,
:nested_teams => 'application/vnd.github.hellcat-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,
Expand Down
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":"eyJuYW1lIjoiVGVzdCBUZWFtIDE1MDQ2NjE5MDEifQ==\n"},"headers":{"Accept":["application/vnd.github.v3+json"],"User-Agent":["Octokit Ruby Gem 4.7.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":{"Date":["Wed, 06 Sep 2017 01:38:22 GMT"],"Content-Type":["application/json; charset=utf-8"],"Content-Length":["1238"],"Server":["GitHub.com"],"Status":["201 Created"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4999"],"X-Ratelimit-Reset":["1504665502"],"Cache-Control":["private, max-age=60, s-maxage=60"],"Vary":["Accept, Authorization, Cookie, X-GitHub-OTP","Accept-Encoding"],"Etag":["\"869148bc393dc680ec1e53<GITHUB_TEST_INTEGRATION>333f14e9\""],"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-Runtime-Rack":["0.1<GITHUB_TEST_INTEGRATION_INSTALLATION>392"],"X-Github-Request-Id":["DCF2:2F8E3:F4AA47:13E6FE0:59AF518D"]},"body":{"encoding":"UTF-8","base64_string":"eyJuYW1lIjoiVGVzdCBUZWFtIDE1MDQ2NjE5MDEiLCJpZCI6PEdJVEhVQl9U\nRVNUX09SR19URUFNX0lEPiwic2x1ZyI6InRlc3QtdGVhbS0xNTA0NjYxOTAx\nIiwiZGVzY3JpcHRpb24iOm51bGwsInByaXZhY3kiOiJzZWNyZXQiLCJ1cmwi\nOiJodHRwczovL2FwaS5naXRodWIuY29tL3RlYW1zLzxHSVRIVUJfVEVTVF9P\nUkdfVEVBTV9JRD4iLCJtZW1iZXJzX3VybCI6Imh0dHBzOi8vYXBpLmdpdGh1\nYi5jb20vdGVhbXMvPEdJVEhVQl9URVNUX09SR19URUFNX0lEPi9tZW1iZXJz\ney9tZW1iZXJ9IiwicmVwb3NpdG9yaWVzX3VybCI6Imh0dHBzOi8vYXBpLmdp\ndGh1Yi5jb20vdGVhbXMvPEdJVEhVQl9URVNUX09SR19URUFNX0lEPi9yZXBv\ncyIsInBlcm1pc3Npb24iOiJwdWxsIiwiY3JlYXRlZF9hdCI6IjIwMTctMDkt\nMDZUMDE6Mzg6MjJaIiwidXBkY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byb2plY3RzIjp0cnVlLCJoYXNfcmVwb3NpdG9yeV9wcm9qZWN0cyI6\ndHJ1ZSwicHVibGljX3JlcG9zIjoxLCJwdWJsaWNfZ2lzdHMiOjAsImZvbGxv\nd2VycyI6MCwiZm9sbG93aW5nIjowLCJodG1sX3VybCI6Imh0dHBzOi8vZ2l0\naHViLmNvbS88R0lUSFVCX1RFU1RfT1JHQU5JWkFUSU9OPiIsImNyZWF0ZWRf\nYXQiOiIyMDE2LTExLTE4VDAzOjU0OjU4WiIsInVwZGF0ZWRfYXQiOiIyMDE2\nLTExLTE4VDAzOjU0OjU4WiIsInR5cGUiOiJPcmdhbml6YXRpb24ifX0=\n"},"http_version":null},"recorded_at":"Wed, 06 Sep 2017 01:38:22 GMT"},{"request":{"method":"get","uri":"https://api.github.com/teams/<GITHUB_TEST_ORG_TEAM_ID>/teams","body":{"encoding":"US-ASCII","base64_string":""},"headers":{"Accept":["application/vnd.github.hellcat-preview+json"],"User-Agent":["Octokit Ruby Gem 4.7.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":{"Date":["Wed, 06 Sep 2017 01:38:22 GMT"],"Content-Type":["application/json; charset=utf-8"],"Content-Length":["2"],"Server":["GitHub.com"],"Status":["200 OK"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4998"],"X-Ratelimit-Reset":["1504665502"],"Cache-Control":["private, max-age=60, s-maxage=60"],"Vary":["Accept, Authorization, Cookie, X-GitHub-OTP","Accept-Encoding"],"Etag":["\"9073a18f0ca7a<GITHUB_TEST_INTEGRATION>d56b80994ae3f808b\""],"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, user, write:org"],"X-Github-Media-Type":["github.hellcat-preview; format=json"],"Link":["<https://api.github.com/teams/<GITHUB_TEST_ORG_TEAM_ID>/teams?page=0>; rel=\"last\""],"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-Runtime-Rack":["0.054016"],"X-Github-Request-Id":["DCF3:2F8DF:7BC479:A10D70:59AF518E"]},"body":{"encoding":"UTF-8","base64_string":"W10=\n"},"http_version":null},"recorded_at":"Wed, 06 Sep 2017 01:38:22 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.7.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":{"Date":["Wed, 06 Sep 2017 01:38:23 GMT"],"Content-Type":["application/octet-stream"],"Server":["GitHub.com"],"Status":["204 No Content"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4997"],"X-Ratelimit-Reset":["1504665502"],"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"],"X-Runtime-Rack":["0.043638"],"Vary":["Accept-Encoding"],"X-Github-Request-Id":["DCF5:2F8E3:F4AA6A:13E700F:59AF518E"]},"body":{"encoding":"UTF-8","base64_string":""},"http_version":null},"recorded_at":"Wed, 06 Sep 2017 01:38:22 GMT"}],"recorded_with":"VCR 2.9.3"}
11 changes: 11 additions & 0 deletions spec/octokit/client/organizations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@
end
end # .team

describe ".child_teams", :vcr do
it "returns all child teams for the team" do
child_teams = @client.child_teams(
@team.id,
:accept => "application/vnd.github.hellcat-preview+json"
)
expect(child_teams).to be_kind_of Array
assert_requested :get, github_url("/teams/#{@team.id}/teams")
end
end # .child_teams

describe ".update_team", :vcr do
it "updates a team" do
@client.update_team(@team.id, :name => "API Jedi")
Expand Down

0 comments on commit 3076c0f

Please sign in to comment.