Skip to content

Commit

Permalink
Merge pull request #871 from octokit/tarebyte/integrations
Browse files Browse the repository at this point in the history
Add support to prerelease Integrations API
  • Loading branch information
tarebyte authored Mar 15, 2017
2 parents 178639c + 7a5940c commit d9b2ed7
Show file tree
Hide file tree
Showing 14 changed files with 250 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rvm:
- 2.0
- 2.1
- 2.2
- 2.3.1
- 2.3.3
- 2.4.0

bundler_args: --without development
Expand All @@ -31,4 +31,4 @@ matrix:
- rvm: jruby

notifications:
emails: false
email: false
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ end
group :test do
gem 'coveralls', :require => false
gem 'json', '~> 1.7', :platforms => [:jruby]
gem 'jwt', '~> 1.5', '>= 1.5.6'
gem 'multi_json', '~> 1.11.0'
gem 'mime-types', '< 2.0.0'
gem 'netrc', '~> 0.7.7'
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -622,11 +622,14 @@ ENV Variable | Description |
`OCTOKIT_TEST_GITHUB_CLIENT_SECRET` | Test OAuth application client secret.
`OCTOKIT_TEST_GITHUB_REPOSITORY` | Test repository to perform destructive actions against, this should not be set to any repository of importance. **Automatically created by the test suite if nonexistent** Default: `api-sandbox`
`OCTOKIT_TEST_GITHUB_ORGANIZATION` | Test organization.
`OCTOKIT_TEST_GITHUB_ENTERPRISE_LOGIN` | GitHub Enterprise login name
`OCTOKIT_TEST_GITHUB_ENTERPRISE_TOKEN` | GitHub Enterprise token
`OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_PASSWORD` | GitHub Enterprise management console password
`OCTOKIT_TEST_GITHUB_ENTERPRISE_ENDPOINT` | GitHub Enterprise hostname
`OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT` | GitHub Enterprise Management Console endpoint
`OCTOKIT_TEST_GITHUB_ENTERPRISE_LOGIN` | GitHub Enterprise login name.
`OCTOKIT_TEST_GITHUB_ENTERPRISE_TOKEN` | GitHub Enterprise token.
`OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_PASSWORD` | GitHub Enterprise management console password.
`OCTOKIT_TEST_GITHUB_ENTERPRISE_ENDPOINT` | GitHub Enterprise hostname.
`OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT` | GitHub Enterprise Management Console endpoint.
`OCTOKIT_TEST_GITHUB_INTEGRATION` | [GitHub Integration](https://developer.github.com/early-access/integrations/) owned by your test organization.
`OCTOKIT_TEST_GITHUB_INTEGRATION_INSTALLATION` | Installation of the GitHub Integration specified above.
`OCTOKIT_TEST_INTEGRATION_PEM_KEY` | File path to the private key generated from your integration.

Since we periodically refresh our cassettes, please keep some points in mind
when writing new specs.
Expand Down
2 changes: 2 additions & 0 deletions lib/octokit/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
require 'octokit/client/gists'
require 'octokit/client/gitignore'
require 'octokit/client/hooks'
require 'octokit/client/integrations'
require 'octokit/client/issues'
require 'octokit/client/labels'
require 'octokit/client/legacy_search'
Expand Down Expand Up @@ -77,6 +78,7 @@ class Client
include Octokit::Client::Gists
include Octokit::Client::Gitignore
include Octokit::Client::Hooks
include Octokit::Client::Integrations
include Octokit::Client::Issues
include Octokit::Client::Labels
include Octokit::Client::LegacySearch
Expand Down
77 changes: 77 additions & 0 deletions lib/octokit/client/integrations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
module Octokit
class Client

# Methods for the Integrations API
module Integrations

# Find all installations that belong to an Integration
#
# @param options [Hash] An customizable set of options
#
# @see https://developer.github.com/v3/integrations/#find-installations
#
# @return [Array<Sawyer::Resource>] A list of installations
def find_integration_installations(options = {})
opts = ensure_api_media_type(:integrations, options)
paginate "/integration/installations", opts
end
alias find_installations find_integration_installations

# Create a new installation token
#
# @param installation [Integer] The id of a a GitHub Integration Installation
# @param options [Hash] An customizable set of options
#
# @see https://developer.github.com/v3/integrations/#find-installations
#
# @return [<Sawyer::Resource>] An installation token
def create_integration_installation_access_token(installation, options = {})
opts = ensure_api_media_type(:integrations, options)
post "/installations/#{installation}/access_tokens", opts
end
alias create_installation_access_token create_integration_installation_access_token

# List repositories that are accessible to the authenticated installation
#
# @param options [Hash] An customizable set of options
# @see https://developer.github.com/v3/integrations/installations/#list-repositories
#
# @return [Array<Sawyer::Resource>] A list of repositories
def list_integration_installation_repositories(options = {})
opts = ensure_api_media_type(:integrations, options)
paginate "/installation/repositories", opts
end
alias list_installation_repos list_integration_installation_repositories

# Add a single repository to an installation
#
# @param installation [Integer] The id of a a GitHub Integration Installation
# @param repo [Integer] The id of the GitHub repository
# @param options [Hash] An customizable set of options
#
# @see https://developer.github.com/v3/integrations/installations/#add-repository-to-installation
#
# @return [Boolean] Success
def add_repository_to_integration_installation(installation, repo, options = {})
opts = ensure_api_media_type(:integrations, options)
boolean_from_response :put, "/installations/#{installation}/repositories/#{repo}", opts
end
alias add_repo_to_installation add_repository_to_integration_installation

# Remove a single repository to an installation
#
# @param installation [Integer] The id of a a GitHub Integration Installation
# @param repo [Integer] The id of the GitHub repository
# @param options [Hash] An customizable set of options
#
# @see https://developer.github.com/v3/integrations/installations/#remove-repository-from-installation
#
# @return [Boolean] Success
def remove_repository_from_integration_installation(installation, repo, options = {})
opts = ensure_api_media_type(:integrations, options)
boolean_from_response :delete, "/installations/#{installation}/repositories/#{repo}", opts
end
alias remove_repo_from_installation remove_repository_from_integration_installation
end
end
end
3 changes: 2 additions & 1 deletion lib/octokit/preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module Preview
:projects => 'application/vnd.github.inertia-preview+json'.freeze,
:traffic => 'application/vnd.github.spiderman-preview'.freeze,
:org_membership => 'application/vnd.github.korra-preview'.freeze,
:reviews => 'application/vnd.github.black-cat-preview'.freeze
:reviews => 'application/vnd.github.black-cat-preview'.freeze,
:integrations => 'Accept: application/vnd.github.machine-man-preview+json'.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/integration/installations","body":{"encoding":"US-ASCII","base64_string":""},"headers":{"Accept":["Accept: application/vnd.github.machine-man-preview+json"],"User-Agent":["Octokit Ruby Gem 4.6.2"],"Content-Type":["application/json"],"Authorization":["Bearer <JWT_BEARER_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":["Mon, 06 Mar 2017 22:17:47 GMT"],"Content-Type":["application/json; charset=utf-8"],"Transfer-Encoding":["chunked"],"Status":["200 OK"],"Cache-Control":["public, max-age=60, s-maxage=60"],"Vary":["Accept","Accept-Encoding"],"Etag":["W/\"47870164deaaf2f565734db32ec45e97\""],"X-Github-Media-Type":["github.machine-man-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":["2811da37fbdda4367181b328b22b2499"],"X-Github-Request-Id":["A9F9:6D38:14B3D9B:1A5EEFB:58BDE00B"]},"body":{"encoding":"ASCII-8BIT","base64_string":"W3siaWQiOjxHSVRIVUJfVEVTVF9JTlRFR1JBVElPTl9JTlNUQUxMQVRJT04+\nLCJhY2NvdW50Ijp7ImxvZ2luIjoiPEdJVEhVQl9URVNUX09SR0FOSVpBVElP\nTj4iLCJp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Ly9hcGkuZ2l0aHViLmNvbS91c2Vycy88R0lU\nSFVCX1RFU1RfT1JHQU5JWkFUSU9OPi9yZXBvcyIsImV2ZW50c191cmwiOiJo\ndHRwczovL2FwaS5naXRodWIuY29tL3VzZXJzLzxHSVRIVUJfVEVTVF9PUkdB\nTklaQVRJT04+L2V2ZW50c3svcHJpdmFjeX0iLCJyZWNlaXZlZF9ldmVudHNf\ndXJsIjoiaHR0cHM6Ly9hcGkuZ2l0aHViLmNvbS91c2Vycy88R0lUSFVCX1RF\nU1RfT1JHQU5JWkFUSU9OPi9yZWNlaXZlZF9ldmVudHMiLCJ0eXBlIjoiT3Jn\nYW5pemF0aW9uIiwic2l0ZV9hZG1pbiI6ZmFsc2V9LCJhY2Nlc3NfdG9rZW5z\nX3VybCI6Imh0dHBzOi8vYXBpLmdpdGh1Yi5jb20vaW5zdGFsbGF0aW9ucy88\nR0lUSFVCX1RFU1RfSU5URUdSQVRJT05fSU5TVEFMTEFUSU9OPi9hY2Nlc3Nf\ndG9rZW5zIiwicmVwb3NpdG9yaWVzX3VybCI6Imh0dHBzOi8vYXBpLmdpdGh1\nYi5jb20vaW5zdGFsbGF0aW9uL3JlcG9zaXRvcmllcyIsImh0bWxfdXJsIjoi\naHR0cHM6Ly9naXRodWIuY29tL29yZ2FuaXphdGlvbnMvPEdJVEhVQl9URVNU\nX09SR0FOSVpBVElPTj4vc2V0dGluZ3MvaW5zdGFsbGF0aW9ucy88R0lUSFVC\nX1RFU1RfSU5URUdSQVRJT05fSU5TVEFMTEFUSU9OPiJ9XQ==\n"},"http_version":null},"recorded_at":"Mon, 06 Mar 2017 22:17:47 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/installations/<GITHUB_TEST_INTEGRATION_INSTALLATION>/access_tokens","body":{"encoding":"UTF-8","base64_string":"e30=\n"},"headers":{"Accept":["Accept: application/vnd.github.machine-man-preview+json"],"User-Agent":["Octokit Ruby Gem 4.6.2"],"Content-Type":["application/json"],"Authorization":["Bearer <JWT_BEARER_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":["Mon, 06 Mar 2017 22:17:47 GMT"],"Content-Type":["application/json; charset=utf-8"],"Content-Length":["91"],"Status":["201 Created"],"Cache-Control":["public, max-age=60, s-maxage=60"],"Vary":["Accept","Accept-Encoding"],"Etag":["\"83917a71bf249be99ee77175bb60d68b\""],"X-Github-Media-Type":["github.machine-man-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":["46808ddc41c302090177e58148908b23"],"X-Github-Request-Id":["BAEE:6D3A:228592D:2BCB64D:58BDE00B"]},"body":{"encoding":"UTF-8","base64_string":"eyJ0b2tlbiI6InYxLjFhNTk3NDc0ZDE5ODExM2FjYWJjMGJjNGU1NDRmMGNl\nYTAyMTM5MDkiLCJleHBpcmVzX2F0IjoiMjAxNy0wMy0wNlQyMzoxNzo0N1oi\nfQ==\n"},"http_version":null},"recorded_at":"Mon, 06 Mar 2017 22:17:47 GMT"}],"recorded_with":"VCR 2.9.3"}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions spec/fixtures/fake_integration.private-key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEArCtJrQ+P59A1Pjaf12EfJ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1TGTnqajhx+LYQLPVn9KL+OKcXBSTVmoCcgVDa8LUDANSD+2UuCLCcC
neo0w0cOj+Ax5JFI1qDL+/jT1eTwdc3aVA6dXVk80yEKcyai53upK310TnNuLxUK
m2SWzZXMDCPCGmLj0DYQtOECgYEAs3oIsKsH19ihpxs1MnZGRp2QtSl+9Wpr6EFz
rI88oxqdxfEp0Tg1lmY+jbGJpYI3Y/0N6jfksulJX1ldGLsvZL2P2FFjlPniq/XF
VGH6wU7DLSV3fZd6PSz1uuF+QbbF/MH0blHxpwOSb33mWfMuLCq+jtLvimxZWsx+
KHh+gSMCgYEA22osS9G3tGpG+x3nZRLXc0lOdKQ51sAo955U1BFscZusP/qQ+b12
KTHhoUd264C6Nb42XXs9qIkiKWaVblglJPhui61/iWw4s0k4Q9Yf/0KxREmlLbL0
mm1m2wenfA97PYoheO1esGsatSXNtxPL+C8ywebu38A6hOClQi1BHd4=
-----END RSA PRIVATE KEY-----
25 changes: 22 additions & 3 deletions spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require 'rspec'
require 'webmock/rspec'
require 'base64'
require 'jwt'

WebMock.disable_net_connect!(:allow => 'coveralls.io')

Expand Down Expand Up @@ -48,10 +49,10 @@
test_github_enterprise_login
end
c.filter_sensitive_data("<<ENTERPRISE_ACCESS_TOKEN>>") do
test_github_enterprise_token
test_github_enterprise_token
end
c.filter_sensitive_data("<<ENTERPRISE_MANAGEMENT_CONSOLE_PASSWORD>>") do
test_github_enterprise_management_console_password
test_github_enterprise_management_console_password
end
c.filter_sensitive_data("<<ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT>>") do
test_github_enterprise_management_console_endpoint
Expand All @@ -68,6 +69,12 @@
c.define_cassette_placeholder("<GITHUB_TEST_ORG_TEAM_ID>") do
"10050505050000"
end
c.define_cassette_placeholder("<GITHUB_TEST_INTEGRATION>") do
test_github_integration
end
c.define_cassette_placeholder("<GITHUB_TEST_INTEGRATION_INSTALLATION>") do
test_github_integration_installation
end

c.before_http_request(:real?) do |request|
next if request.headers['X-Vcr-Test-Repo-Setup']
Expand Down Expand Up @@ -159,13 +166,25 @@ def test_github_repository
end

def test_github_repository_id
ENV.fetch 'OCTOKIT_TEST_GITHUB_REPOSITORY_ID', 20974780
ENV.fetch 'OCTOKIT_TEST_GITHUB_REPOSITORY_ID', 20_974_780
end

def test_github_org
ENV.fetch 'OCTOKIT_TEST_GITHUB_ORGANIZATION', 'api-playground'
end

def test_github_integration
ENV.fetch 'OCTOKIT_TEST_GITHUB_INTEGRATION', 42
end

def test_github_integration_installation
ENV.fetch 'OCTOKIT_TEST_GITHUB_INTEGRATION_INSTALLATION', 37
end

def test_github_integration_pem_key
ENV.fetch 'OCTOKIT_TEST_INTEGRATION_PEM_KEY', "#{fixture_path}/fake_integration.private-key.pem"
end

def stub_delete(url)
stub_request(:delete, github_url(url))
end
Expand Down
104 changes: 104 additions & 0 deletions spec/octokit/client/integrations_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
require 'helper'

describe Octokit::Client::Integrations do
before(:each) do
Octokit.reset!
@client = oauth_client
@jwt_client = Octokit::Client.new(:bearer_token => new_jwt_token)
use_vcr_placeholder_for(@jwt_client.bearer_token, '<JWT_BEARER_TOKEN>')
end

after(:each) do
Octokit.reset!
end

describe ".find_integration_installations", :vcr do
it "returns installations for an integration" do
installations = @jwt_client.find_integration_installations
expect(installations).to be_kind_of Array
assert_requested :get, github_url("/integration/installations")
end
end # .find_integration_installations

context "with integration installation", :vcr do
let(:installation) { test_github_integration_installation }

describe ".create_integration_installation_access_token" do
it "creates an access token for the installation" do
response = @jwt_client.create_integration_installation_access_token(installation)

expect(response).to be_kind_of(Sawyer::Resource)
expect(response.token).not_to be_nil
expect(response.expires_at).not_to be_nil

assert_requested :post, github_url("/installations/#{installation}/access_tokens")
end
end # .create_integration_installation_access_token

context "with integration installation access token" do
let(:installation_client) do
token = @jwt_client.create_integration_installation_access_token(installation).token
use_vcr_placeholder_for(token, '<INTEGRATION_INSTALLATION_TOKEN>')
Octokit::Client.new(:access_token => token)
end

describe ".list_integration_installation_repositories" do
it "lists the installations repositories" do
response = installation_client.list_integration_installation_repositories
expect(response.total_count).not_to be_nil
expect(response.repositories).to be_kind_of(Array)
end
end # .list_integration_installation_repositories
end # with integration installation access token

context "with repository" do
let(:repository) { test_org_repo }

before(:each) do
@repo = @client.create_repository(
"#{test_github_repository}_#{Time.now.to_f}",
:organization => test_github_org
)
end

after(:each) do
@client.delete_repository(@repo.full_name)
end

describe ".add_repository_to_integration_installation" do
it "adds the repository to the installation" do
response = @client.add_repository_to_integration_installation(installation, @repo.id)
expect(response).to be_truthy
end
end # .add_repository_to_integration_installation

context 'with installed repository on installation' do
before(:each) do
@client.add_repository_to_integration_installation(installation, @repo.id)
end

describe ".remove_repository_from_integration_installation" do
it "removes the repository from the installation" do
response = @client.remove_repository_from_integration_installation(installation, @repo.id)
expect(response).to be_truthy
end
end # .remove_repository_from_integration_installation
end # with installed repository on installation
end # with repository
end # with integration installation

private

def new_jwt_token
private_pem = File.read(test_github_integration_pem_key)
private_key = OpenSSL::PKey::RSA.new(private_pem)

payload = {}.tap do |opts|
opts[:iat] = Time.now.to_i # Issued at time.
opts[:exp] = opts[:iat] + 600 # JWT expiration time is 10 minutes from issued time.
opts[:iss] = test_github_integration # Integration's GitHub identifier.
end

JWT.encode(payload, private_key, 'RS256')
end
end

0 comments on commit d9b2ed7

Please sign in to comment.