-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #871 from octokit/tarebyte/integrations
Add support to prerelease Integrations API
- Loading branch information
Showing
14 changed files
with
250 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...ntegrations/_find_integration_installations/returns_installations_for_an_integration.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\nTj4iLCJpZCI6MTc1Mjk4MTQsImF2YXRhcl91cmwiOiJodHRwczovL2F2YXRh\ncnMwLmdpdGh1YnVzZXJjb250ZW50LmNvbS91LzE3NTI5ODE0P3Y9MyIs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FwaS5naXRodWIuY29tL3VzZXJzLzxHSVRIVUJfVEVTVF9PUkdB\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"} |
1 change: 1 addition & 0 deletions
1
...e_integration_installation_access_token/creates_an_access_token_for_the_installation.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
1 change: 1 addition & 0 deletions
1
...ken/_list_integration_installation_repositories/lists_the_installations_repositories.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
.../_add_repository_to_integration_installation/adds_the_repository_to_the_installation.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...epository_from_integration_installation/removes_the_repository_from_the_installation.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIIEpQIBAAKCAQEArCtJrQ+P59A1Pjaf12EfJqltszDpqO0ufsk7N0WRXUeoYZKF | ||
AihwLMIaHbTc1Jn/QEX8WmZGPKIcRlJ9pk2MxQbXRqxM35n61Cb8mYMne+6VXNyl | ||
ZILvRTMXLGIVy/OTmszafTP8Lws9w8vKKLKCax4kEzbfjiRoCgspO7YudFUCxQ6Q | ||
UUxlLPd4/yUaw5A8nUdWZrvPa3CYXG2355yhigRpnOyawoOsvAHUvQruh+z3k6NZ | ||
g6f3eMjsrpeID84TPw1kRs+T+XNsSP21ZUFKYs54bdxlLPphT4iPKNkRwoP0SqJm | ||
97W98B8k7+mtFPZllYGgiHrA4Egnasg9ULiXCwIDAQABAoIBACMoZ9AuWF2nN+gv | ||
cW6jB6B2gs9P0rdLT+5WG4CK9UdOJcVfDUhGh7msHXcpgtrrY6N1ZzXyoq8pD4sQ | ||
t1XpijCF2Bo3fy8+G2mNWJHkpYB6VQf0itW+oyvHZhkLIpZWdDLtWESvA/V7Xy6H | ||
hA3Rfi5vpkBCOV6mcpRyeQYXit74UzDvojXSf8idsjuVDoIXuaoIJMPwyxTWJY+A | ||
8sQ92ecHJ3rQLspxSmXlZYpRtHTNaZlAv1qx605DP/JlV/6bAA3IIWQtrd9Z0Cw/ | ||
rwNtwcP0vB/w6Yq9o8EmJHn7rQuC4NN6lMi/VkwaNCqcPfnRWW7OCtgOhfGAP+kr | ||
vKU5kEECgYEA4hOWtUC4624E4r9NYNOeYcCj9meR5p3FY8vtPLMvpU9r4m3vPldz | ||
ofq/I/Tpo418gWuy02/c4VpHo/8QUBW33yik0YVfL/XWczZwvhabufSTRL3HtIxb | ||
NY5qbgV7yJea1mUuTkiM2obl4x+bR6haHPnHVu+QI480zOzkroF9P2ECgYEAwvUX | ||
dpKebLxzod/UeQLvZFhFXG/qvvAJ7FwxtDRu22znQJR5YVdqd3XDZkfd+64PjDLf | ||
46WMktqu2DclO9eFbKyuLfD0F1OO5z5IHd5dim39/QYo0sJ+y6y6edEM7Of2IxLH | ||
5PkSJLVKAju5t2PJMXDBZBa4HVhNdW+lDHKlCesCgYEAzDvQCVw38g/JACK8P33N | ||
dhe2x9IWv1TGTnqajhx+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----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |