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 support for Community Profile API #975

Merged
merged 2 commits into from
Sep 6, 2018
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
2 changes: 2 additions & 0 deletions lib/octokit/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require 'octokit/client/authorizations'
require 'octokit/client/commits'
require 'octokit/client/commit_comments'
require 'octokit/client/community_profile'
require 'octokit/client/contents'
require 'octokit/client/downloads'
require 'octokit/client/deployments'
Expand Down Expand Up @@ -70,6 +71,7 @@ class Client
include Octokit::Client::Authorizations
include Octokit::Client::Commits
include Octokit::Client::CommitComments
include Octokit::Client::CommunityProfile
include Octokit::Client::Contents
include Octokit::Client::Deployments
include Octokit::Client::Downloads
Expand Down
22 changes: 22 additions & 0 deletions lib/octokit/client/community_profile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Octokit
class Client

# Methods for the Community Profile API
#
# @see https://developer.github.com/v3/repos/community/
module CommunityProfile

# Get community profile metrics for a repository
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
# @return [Sawyer::Resource] Community profile metrics
# @see https://developer.github.com/v3/repos/community/#retrieve-community-profile-metrics
# @example Get community profile metrics for octokit/octokit.rb
# @client.community_profile('octokit/octokit.rb')
def community_profile(repo, options = {})
options = ensure_api_media_type(:community_profile, options)
get "#{Repository.path repo}/community/profile", options
end
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 @@ -16,7 +16,8 @@ module Preview
:projects => 'application/vnd.github.inertia-preview+json'.freeze,
:traffic => 'application/vnd.github.spiderman-preview'.freeze,
:integrations => 'application/vnd.github.machine-man-preview+json'.freeze,
:topics => 'application/vnd.github.mercy-preview+json'.freeze
:topics => 'application/vnd.github.mercy-preview+json'.freeze,
:community_profile => 'application/vnd.github.black-panther-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/repos/octokit/octokit.rb/community/profile","body":{"encoding":"US-ASCII","base64_string":""},"headers":{"Accept":["application/vnd.github.black-panther-preview+json"],"User-Agent":["Octokit Ruby Gem 4.8.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":["Sat, 13 Jan 2018 07:47:32 GMT"],"Content-Type":["application/json; charset=utf-8"],"Transfer-Encoding":["chunked"],"Server":["GitHub.com"],"Status":["200 OK"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4995"],"X-Ratelimit-Reset":["1515831286"],"Cache-Control":["private, max-age=60, s-maxage=60"],"Vary":["Accept, Authorization, Cookie, X-GitHub-OTP","Accept-Encoding"],"Etag":["W/\"5b72d5fd700b48d71c21be2291b<GITHUB_TEST_INTEGRATION>a75\""],"X-Oauth-Scopes":["repo"],"X-Accepted-Oauth-Scopes":[""],"X-Github-Media-Type":["github.black-panther-preview; format=json"],"Access-Control-Expose-Headers":["ETag, Link, Retry-After, 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.092548"],"X-Github-Request-Id":["E945:20E01:15121:1B63D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zOjQzWiJ9\n"},"http_version":null},"recorded_at":"Sat, 13 Jan 2018 07:47:31 GMT"}],"recorded_with":"VCR 2.9.3"}
22 changes: 22 additions & 0 deletions spec/octokit/client/community_profile_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'helper'

describe Octokit::Client::CommunityProfile do
before do
Octokit.reset!
@client = oauth_client
end

describe '.community_profile', :vcr do
it "returns community profile metrics for a repository" do
community_profile = @client.community_profile('octokit/octokit.rb', accept: preview_header)
expect(community_profile.health_percentage).not_to be_nil
assert_requested :get, github_url('/repos/octokit/octokit.rb/community/profile')
end
end # .community_profile

private

def preview_header
Octokit::Preview::PREVIEW_TYPES[:community_profile]
end
end