octokit-3.8.0/0000755000004100000410000000000012511016543013224 5ustar www-datawww-dataoctokit-3.8.0/Rakefile0000644000004100000410000000067712511016543014703 0ustar www-datawww-datarequire 'bundler' Bundler::GemHelper.install_tasks require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) task :test => :spec task :default => :spec namespace :doc do begin require 'yard' YARD::Rake::YardocTask.new do |task| task.files = ['README.md', 'LICENSE.md', 'lib/**/*.rb'] task.options = [ '--output-dir', 'doc/yard', '--markup', 'markdown', ] end rescue LoadError end end octokit-3.8.0/LICENSE.md0000644000004100000410000000211412511016543014626 0ustar www-datawww-dataCopyright (c) 2009-2014 Wynn Netherland, Adam Stacoviak, Erik Michaels-Ober Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. octokit-3.8.0/lib/0000755000004100000410000000000012511016543013772 5ustar www-datawww-dataoctokit-3.8.0/lib/octokit/0000755000004100000410000000000012511016543015446 5ustar www-datawww-dataoctokit-3.8.0/lib/octokit/default.rb0000644000004100000410000000714412511016543017425 0ustar www-datawww-datarequire 'octokit/response/raise_error' require 'octokit/response/feed_parser' require 'octokit/version' module Octokit # Default configuration options for {Client} module Default # Default API endpoint API_ENDPOINT = "https://api.github.com".freeze # Default User Agent header string USER_AGENT = "Octokit Ruby Gem #{Octokit::VERSION}".freeze # Default media type MEDIA_TYPE = "application/vnd.github.v3+json".freeze # Default WEB endpoint WEB_ENDPOINT = "https://github.com".freeze # In Faraday 0.9, Faraday::Builder was renamed to Faraday::RackBuilder RACK_BUILDER_CLASS = defined?(Faraday::RackBuilder) ? Faraday::RackBuilder : Faraday::Builder # Default Faraday middleware stack MIDDLEWARE = RACK_BUILDER_CLASS.new do |builder| builder.use Octokit::Response::RaiseError builder.use Octokit::Response::FeedParser builder.adapter Faraday.default_adapter end class << self # Configuration options # @return [Hash] def options Hash[Octokit::Configurable.keys.map{|key| [key, send(key)]}] end # Default access token from ENV # @return [String] def access_token ENV['OCTOKIT_ACCESS_TOKEN'] end # Default API endpoint from ENV or {API_ENDPOINT} # @return [String] def api_endpoint ENV['OCTOKIT_API_ENDPOINT'] || API_ENDPOINT end # Default pagination preference from ENV # @return [String] def auto_paginate ENV['OCTOKIT_AUTO_PAGINATE'] end # Default OAuth app key from ENV # @return [String] def client_id ENV['OCTOKIT_CLIENT_ID'] end # Default OAuth app secret from ENV # @return [String] def client_secret ENV['OCTOKIT_SECRET'] end # Default options for Faraday::Connection # @return [Hash] def connection_options { :headers => { :accept => default_media_type, :user_agent => user_agent } } end # Default media type from ENV or {MEDIA_TYPE} # @return [String] def default_media_type ENV['OCTOKIT_DEFAULT_MEDIA_TYPE'] || MEDIA_TYPE end # Default GitHub username for Basic Auth from ENV # @return [String] def login ENV['OCTOKIT_LOGIN'] end # Default middleware stack for Faraday::Connection # from {MIDDLEWARE} # @return [String] def middleware MIDDLEWARE end # Default GitHub password for Basic Auth from ENV # @return [String] def password ENV['OCTOKIT_PASSWORD'] end # Default pagination page size from ENV # @return [Fixnum] Page size def per_page page_size = ENV['OCTOKIT_PER_PAGE'] page_size.to_i if page_size end # Default proxy server URI for Faraday connection from ENV # @return [String] def proxy ENV['OCTOKIT_PROXY'] end # Default User-Agent header string from ENV or {USER_AGENT} # @return [String] def user_agent ENV['OCTOKIT_USER_AGENT'] || USER_AGENT end # Default web endpoint from ENV or {WEB_ENDPOINT} # @return [String] def web_endpoint ENV['OCTOKIT_WEB_ENDPOINT'] || WEB_ENDPOINT end # Default behavior for reading .netrc file # @return [Boolean] def netrc ENV['OCTOKIT_NETRC'] || false end # Default path for .netrc file # @return [String] def netrc_file ENV['OCTOKIT_NETRC_FILE'] || File.join(ENV['HOME'].to_s, '.netrc') end end end end octokit-3.8.0/lib/octokit/authentication.rb0000644000004100000410000000365212511016543021020 0ustar www-datawww-datamodule Octokit # Authentication methods for {Octokit::Client} module Authentication # Indicates if the client was supplied Basic Auth # username and password # # @see https://developer.github.com/v3/#authentication # @return [Boolean] def basic_authenticated? !!(@login && @password) end # Indicates if the client was supplied an OAuth # access token # # @see https://developer.github.com/v3/#authentication # @return [Boolean] def token_authenticated? !!@access_token end # Indicates if the client was supplied an OAuth # access token or Basic Auth username and password # # @see https://developer.github.com/v3/#authentication # @return [Boolean] def user_authenticated? basic_authenticated? || token_authenticated? end # Indicates if the client has OAuth Application # client_id and secret credentials to make anonymous # requests at a higher rate limit # # @see https://developer.github.com/v3/#unauthenticated-rate-limited-requests # @return Boolean def application_authenticated? !!application_authentication end private def application_authentication if @client_id && @client_secret { :client_id => @client_id, :client_secret => @client_secret } end end def login_from_netrc return unless netrc? require 'netrc' info = Netrc.read netrc_file netrc_host = URI.parse(api_endpoint).host creds = info[netrc_host] if creds.nil? # creds will be nil if there is no netrc for this end point octokit_warn "Error loading credentials from netrc file for #{api_endpoint}" else creds = creds.to_a self.login = creds.shift self.password = creds.shift end rescue LoadError octokit_warn "Please install netrc gem for .netrc support" end end end octokit-3.8.0/lib/octokit/organization.rb0000644000004100000410000000063012511016543020476 0ustar www-datawww-datamodule Octokit # GitHub organization class to generate API path urls class Organization # Get the api path for an organization # # @param org [String, Integer] GitHub organization login or id # @return [String] Organization Api path def self.path org case org when String "orgs/#{org}" when Integer "organizations/#{org}" end end end end octokit-3.8.0/lib/octokit/gist.rb0000644000004100000410000000110512511016543016736 0ustar www-datawww-datamodule Octokit # Class to parse and create Gist URLs class Gist # !@attribute id # @return [String] Gist ID attr_accessor :id # Instantiate {Gist} object from Gist URL # @ return [Gist] def self.from_url(url) Gist.new(URI.parse(url).path[1..-1]) end def initialize(gist) case gist when Fixnum, String @id = gist.to_s end end # Gist ID # @return [String] def to_s @id end # Gist URL # @return [String] def url "https://gist.github.com/#{@id}" end end end octokit-3.8.0/lib/octokit/rate_limit.rb0000644000004100000410000000212612511016543020125 0ustar www-datawww-datamodule Octokit # Class for API Rate Limit info # # @!attribute [w] limit # @return [Fixnum] Max tries per rate limit period # @!attribute [w] remaining # @return [Fixnum] Remaining tries per rate limit period # @!attribute [w] resets_at # @return [Time] Indicates when rate limit resets # @!attribute [w] resets_in # @return [Fixnum] Number of seconds when rate limit resets # # @see https://developer.github.com/v3/#rate-limiting class RateLimit < Struct.new(:limit, :remaining, :resets_at, :resets_in) # Get rate limit info from HTTP response # # @param response [#headers] HTTP response # @return [RateLimit] def self.from_response(response) info = new if response && !response.headers.nil? info.limit = (response.headers['X-RateLimit-Limit'] || 1).to_i info.remaining = (response.headers['X-RateLimit-Remaining'] || 1).to_i info.resets_at = Time.at((response.headers['X-RateLimit-Reset'] || Time.now).to_i) info.resets_in = [(info.resets_at - Time.now).to_i, 0].max end info end end end octokit-3.8.0/lib/octokit/response/0000755000004100000410000000000012511016543017304 5ustar www-datawww-dataoctokit-3.8.0/lib/octokit/response/feed_parser.rb0000644000004100000410000000057312511016543022115 0ustar www-datawww-datarequire 'faraday' module Octokit module Response # Parses RSS and Atom feed responses. class FeedParser < Faraday::Response::Middleware private def on_complete(env) if env[:response_headers]["content-type"] =~ /(\batom|\brss)/ require 'rss' env[:body] = RSS::Parser.parse env[:body] end end end end end octokit-3.8.0/lib/octokit/response/raise_error.rb0000644000004100000410000000066212511016543022151 0ustar www-datawww-datarequire 'faraday' require 'octokit/error' module Octokit # Faraday response middleware module Response # This class raises an Octokit-flavored exception based # HTTP status codes returned by the API class RaiseError < Faraday::Response::Middleware private def on_complete(response) if error = Octokit::Error.from_response(response) raise error end end end end end octokit-3.8.0/lib/octokit/arguments.rb0000644000004100000410000000036312511016543020002 0ustar www-datawww-datamodule Octokit # Extracts options from method arguments # @private class Arguments < Array attr_reader :options def initialize(args) @options = args.last.is_a?(::Hash) ? args.pop : {} super(args) end end end octokit-3.8.0/lib/octokit/client.rb0000644000004100000410000002641512511016543017261 0ustar www-datawww-datarequire 'sawyer' require 'octokit/arguments' require 'octokit/repo_arguments' require 'octokit/configurable' require 'octokit/authentication' require 'octokit/gist' require 'octokit/rate_limit' require 'octokit/repository' require 'octokit/user' require 'octokit/organization' require 'octokit/client/authorizations' require 'octokit/client/commits' require 'octokit/client/commit_comments' require 'octokit/client/contents' require 'octokit/client/downloads' require 'octokit/client/deployments' require 'octokit/client/emojis' require 'octokit/client/events' require 'octokit/client/feeds' require 'octokit/client/gists' require 'octokit/client/gitignore' require 'octokit/client/hooks' require 'octokit/client/issues' require 'octokit/client/labels' require 'octokit/client/legacy_search' require 'octokit/client/meta' require 'octokit/client/markdown' require 'octokit/client/milestones' require 'octokit/client/notifications' require 'octokit/client/objects' require 'octokit/client/organizations' require 'octokit/client/pages' require 'octokit/client/pub_sub_hubbub' require 'octokit/client/pull_requests' require 'octokit/client/rate_limit' require 'octokit/client/refs' require 'octokit/client/releases' require 'octokit/client/repositories' require 'octokit/client/say' require 'octokit/client/search' require 'octokit/client/service_status' require 'octokit/client/stats' require 'octokit/client/statuses' require 'octokit/client/users' module Octokit # Client for the GitHub API # # @see https://developer.github.com class Client include Octokit::Authentication include Octokit::Configurable include Octokit::Client::Authorizations include Octokit::Client::Commits include Octokit::Client::CommitComments include Octokit::Client::Contents include Octokit::Client::Deployments include Octokit::Client::Downloads include Octokit::Client::Emojis include Octokit::Client::Events include Octokit::Client::Feeds include Octokit::Client::Gists include Octokit::Client::Gitignore include Octokit::Client::Hooks include Octokit::Client::Issues include Octokit::Client::Labels include Octokit::Client::LegacySearch include Octokit::Client::Meta include Octokit::Client::Markdown include Octokit::Client::Milestones include Octokit::Client::Notifications include Octokit::Client::Objects include Octokit::Client::Organizations include Octokit::Client::Pages include Octokit::Client::PubSubHubbub include Octokit::Client::PullRequests include Octokit::Client::RateLimit include Octokit::Client::Refs include Octokit::Client::Releases include Octokit::Client::Repositories include Octokit::Client::Say include Octokit::Client::Search include Octokit::Client::ServiceStatus include Octokit::Client::Stats include Octokit::Client::Statuses include Octokit::Client::Users # Header keys that can be passed in options hash to {#get},{#head} CONVENIENCE_HEADERS = Set.new([:accept, :content_type]) def initialize(options = {}) # Use options passed in, but fall back to module defaults Octokit::Configurable.keys.each do |key| instance_variable_set(:"@#{key}", options[key] || Octokit.instance_variable_get(:"@#{key}")) end login_from_netrc unless user_authenticated? || application_authenticated? end # Compares client options to a Hash of requested options # # @param opts [Hash] Options to compare with current client options # @return [Boolean] def same_options?(opts) opts.hash == options.hash end # Text representation of the client, masking tokens and passwords # # @return [String] def inspect inspected = super # mask password inspected = inspected.gsub! @password, "*******" if @password # Only show last 4 of token, secret if @access_token inspected = inspected.gsub! @access_token, "#{'*'*36}#{@access_token[36..-1]}" end if @client_secret inspected = inspected.gsub! @client_secret, "#{'*'*36}#{@client_secret[36..-1]}" end inspected end # Make a HTTP GET request # # @param url [String] The path, relative to {#api_endpoint} # @param options [Hash] Query and header params for request # @return [Sawyer::Resource] def get(url, options = {}) request :get, url, parse_query_and_convenience_headers(options) end # Make a HTTP POST request # # @param url [String] The path, relative to {#api_endpoint} # @param options [Hash] Body and header params for request # @return [Sawyer::Resource] def post(url, options = {}) request :post, url, options end # Make a HTTP PUT request # # @param url [String] The path, relative to {#api_endpoint} # @param options [Hash] Body and header params for request # @return [Sawyer::Resource] def put(url, options = {}) request :put, url, options end # Make a HTTP PATCH request # # @param url [String] The path, relative to {#api_endpoint} # @param options [Hash] Body and header params for request # @return [Sawyer::Resource] def patch(url, options = {}) request :patch, url, options end # Make a HTTP DELETE request # # @param url [String] The path, relative to {#api_endpoint} # @param options [Hash] Query and header params for request # @return [Sawyer::Resource] def delete(url, options = {}) request :delete, url, options end # Make a HTTP HEAD request # # @param url [String] The path, relative to {#api_endpoint} # @param options [Hash] Query and header params for request # @return [Sawyer::Resource] def head(url, options = {}) request :head, url, parse_query_and_convenience_headers(options) end # Make one or more HTTP GET requests, optionally fetching # the next page of results from URL in Link response header based # on value in {#auto_paginate}. # # @param url [String] The path, relative to {#api_endpoint} # @param options [Hash] Query and header params for request # @param block [Block] Block to perform the data concatination of the # multiple requests. The block is called with two parameters, the first # contains the contents of the requests so far and the second parameter # contains the latest response. # @return [Sawyer::Resource] def paginate(url, options = {}, &block) opts = parse_query_and_convenience_headers(options.dup) if @auto_paginate || @per_page opts[:query][:per_page] ||= @per_page || (@auto_paginate ? 100 : nil) end data = request(:get, url, opts) if @auto_paginate while @last_response.rels[:next] && rate_limit.remaining > 0 @last_response = @last_response.rels[:next].get if block_given? yield(data, @last_response) else data.concat(@last_response.data) if @last_response.data.is_a?(Array) end end end data end # Hypermedia agent for the GitHub API # # @return [Sawyer::Agent] def agent @agent ||= Sawyer::Agent.new(api_endpoint, sawyer_options) do |http| http.headers[:accept] = default_media_type http.headers[:content_type] = "application/json" http.headers[:user_agent] = user_agent if basic_authenticated? http.basic_auth(@login, @password) elsif token_authenticated? http.authorization 'token', @access_token elsif application_authenticated? http.params = http.params.merge application_authentication end end end # Fetch the root resource for the API # # @return [Sawyer::Resource] def root get "/" end # Response for last HTTP request # # @return [Sawyer::Response] def last_response @last_response if defined? @last_response end # Duplicate client using client_id and client_secret as # Basic Authentication credentials. # @example # Octokit.client_id = "foo" # Octokit.client_secret = "bar" # # # GET https://api.github.com/?client_id=foo&client_secret=bar # Octokit.get "/" # # Octokit.client.as_app do |client| # # GET https://foo:bar@api.github.com/ # client.get "/" # end def as_app(key = client_id, secret = client_secret, &block) if key.to_s.empty? || secret.to_s.empty? raise ApplicationCredentialsRequired, "client_id and client_secret required" end app_client = self.dup app_client.client_id = app_client.client_secret = nil app_client.login = key app_client.password = secret yield app_client if block_given? end # Set username for authentication # # @param value [String] GitHub username def login=(value) reset_agent @login = value end # Set password for authentication # # @param value [String] GitHub password def password=(value) reset_agent @password = value end # Set OAuth access token for authentication # # @param value [String] 40 character GitHub OAuth access token def access_token=(value) reset_agent @access_token = value end # Set OAuth app client_id # # @param value [String] 20 character GitHub OAuth app client_id def client_id=(value) reset_agent @client_id = value end # Set OAuth app client_secret # # @param value [String] 40 character GitHub OAuth app client_secret def client_secret=(value) reset_agent @client_secret = value end # Wrapper around Kernel#warn to print warnings unless # OCTOKIT_SILENT is set to true. # # @return [nil] def octokit_warn(*message) unless ENV['OCTOKIT_SILENT'] warn message end end private def reset_agent @agent = nil end def request(method, path, data, options = {}) if data.is_a?(Hash) options[:query] = data.delete(:query) || {} options[:headers] = data.delete(:headers) || {} if accept = data.delete(:accept) options[:headers][:accept] = accept end end @last_response = response = agent.call(method, URI::Parser.new.escape(path.to_s), data, options) response.data end # Executes the request, checking if it was successful # # @return [Boolean] True on success, false otherwise def boolean_from_response(method, path, options = {}) request(method, path, options) @last_response.status == 204 rescue Octokit::NotFound false end def sawyer_options opts = { :links_parser => Sawyer::LinkParsers::Simple.new } conn_opts = @connection_options conn_opts[:builder] = @middleware if @middleware conn_opts[:proxy] = @proxy if @proxy opts[:faraday] = Faraday.new(conn_opts) opts end def parse_query_and_convenience_headers(options) headers = options.fetch(:headers, {}) CONVENIENCE_HEADERS.each do |h| if header = options.delete(h) headers[h] = header end end query = options.delete(:query) opts = {:query => options} opts[:query].merge!(query) if query && query.is_a?(Hash) opts[:headers] = headers unless headers.empty? opts end end end octokit-3.8.0/lib/octokit/user.rb0000644000004100000410000000060612511016543016753 0ustar www-datawww-datamodule Octokit # GitHub user class to generate API path urls class User # Get the api path for a user # # @param user [String, Integer] GitHub user login or id # @return [String] User Api path def self.path user case user when String "users/#{user}" when Integer "user/#{user}" else "user" end end end end octokit-3.8.0/lib/octokit/client/0000755000004100000410000000000012511016543016724 5ustar www-datawww-dataoctokit-3.8.0/lib/octokit/client/contents.rb0000644000004100000410000001624512511016543021116 0ustar www-datawww-datarequire 'base64' module Octokit class Client # Methods for the Repo Contents API # # @see https://developer.github.com/v3/repos/contents/ module Contents # Receive the default Readme for a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @option options [String] :ref name of the Commit/Branch/Tag. Defaults to “master”. # @return [Sawyer::Resource] The detail of the readme # @see https://developer.github.com/v3/repos/contents/#get-the-readme # @example Get the readme file for a repo # Octokit.readme("octokit/octokit.rb") def readme(repo, options={}) get "#{Repository.path repo}/readme", options end # Receive a listing of a repository folder or the contents of a file # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @option options [String] :path A folder or file path # @option options [String] :ref name of the Commit/Branch/Tag. Defaults to “master”. # @return [Sawyer::Resource] The contents of a file or list of the files in the folder # @see https://developer.github.com/v3/repos/contents/#get-contents # @example List the contents of lib/octokit.rb # Octokit.contents("octokit/octokit.rb", :path => 'lib/octokit.rb') def contents(repo, options={}) repo_path = options.delete :path url = "#{Repository.path repo}/contents/#{repo_path}" get url, options end alias :content :contents # Add content to a repository # # @overload create_contents(repo, path, message, content = nil, options = {}) # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param path [String] A path for the new content # @param message [String] A commit message for adding the content # @param optional content [String] The content for the file # @option options [String] :branch The branch on which to add the content # @option options [String] :file Path or Ruby File object for content # @return [Sawyer::Resource] The contents and commit info for the addition # @see https://developer.github.com/v3/repos/contents/#create-a-file # @example Add content at lib/octokit.rb # Octokit.create_contents("octokit/octokit.rb", # "lib/octokit.rb", # "Adding content", # "File content", # :branch => "my-new-feature") def create_contents(*args) options = args.last.is_a?(Hash) ? args.pop : {} repo = args.shift path = args.shift message = args.shift content = args.shift if content.nil? && file = options.delete(:file) case file when String if File.exist?(file) file = File.open(file, "r") content = file.read file.close end when File, Tempfile content = file.read file.close end end raise ArgumentError.new("content or :file option required") if content.nil? options[:content] = Base64.respond_to?(:strict_encode64) ? Base64.strict_encode64(content) : Base64.encode64(content).delete("\n") # Ruby 1.9.2 options[:message] = message url = "#{Repository.path repo}/contents/#{path}" put url, options end alias :create_content :create_contents alias :add_content :create_contents alias :add_contents :create_contents # Update content in a repository # # @overload update_contents(repo, path, message, sha, content = nil, options = {}) # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param path [String] A path for the content to update # @param message [String] A commit message for updating the content # @param sha [String] The _blob sha_ of the content to update # @param content [String] The content for the file # @option options [String] :branch The branch on which to update the content # @option options [String] :file Path or Ruby File object for content # @return [Sawyer::Resource] The contents and commit info for the update # @see https://developer.github.com/v3/repos/contents/#update-a-file # @example Update content at lib/octokit.rb # Octokit.update_contents("octokit/octokit.rb", # "lib/octokit.rb", # "Updating content", # "7eb95f97e1a0636015df3837478d3f15184a5f49", # "File content", # :branch => "my-new-feature") def update_contents(*args) options = args.last.is_a?(Hash) ? args.pop : {} repo = args.shift path = args.shift message = args.shift sha = args.shift content = args.shift options.merge!(:sha => sha) create_contents(repo, path, message, content, options) end alias :update_content :update_contents # Delete content in a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param path [String] A path for the content to delete # @param message [String] A commit message for deleting the content # @param sha [String] The _blob sha_ of the content to delete # @option options [String] :branch The branch on which to delete the content # @return [Sawyer::Resource] The commit info for the delete # @see https://developer.github.com/v3/repos/contents/#delete-a-file # @example Delete content at lib/octokit.rb # Octokit.delete_contents("octokit/octokit.rb", # "lib/octokit.rb", # "Deleting content", # "7eb95f97e1a0636015df3837478d3f15184a5f49", # :branch => "my-new-feature") def delete_contents(repo, path, message, sha, options = {}) options[:message] = message options[:sha] = sha url = "#{Repository.path repo}/contents/#{path}" delete url, options end alias :delete_content :delete_contents alias :remove_content :delete_contents alias :remove_contents :delete_contents # This method will provide a URL to download a tarball or zipball archive for a repository. # # @param repo [Integer, String, Repository, Hash] A GitHub repository. # @option options format [String] Either tarball (default) or zipball. # @option options [String] :ref Optional valid Git reference, defaults to master. # @return [String] Location of the download # @see https://developer.github.com/v3/repos/contents/#get-archive-link # @example Get archive link for octokit/octokit.rb # Octokit.archive_link("octokit/octokit.rb") def archive_link(repo, options={}) repo_ref = options.delete :ref format = (options.delete :format) || 'tarball' url = "#{Repository.path repo}/#{format}/#{repo_ref}" request :head, url, options last_response.headers['Location'] end end end end octokit-3.8.0/lib/octokit/client/pub_sub_hubbub.rb0000644000004100000410000001242512511016543022243 0ustar www-datawww-datamajor, minor, patch = RUBY_VERSION.split('.').map(&:to_i) if (major == 1 && minor < 9) || (major == 1 && minor == 9 && patch < 2) # pull in backports require 'octokit/backports/uri' end module Octokit class Client # Methods for the PubSubHubbub API # # @see https://developer.github.com/v3/repos/hooks/#pubsubhubbub module PubSubHubbub # Subscribe to a pubsub topic # # @param topic [String] A recoginized and supported pubsub topic # @param callback [String] A callback url to be posted to when the topic event is fired # @param secret [String] An optional shared secret used to generate a SHA1 HMAC of the outgoing body content # @return [Boolean] true if the subscribe was successful, otherwise an error is raised # @see https://developer.github.com/v3/repos/hooks/#subscribing # @example Subscribe to push events from one of your repositories, having an email sent when fired # client = Octokit::Client.new(:oauth_token = "token") # client.subscribe("https://github.com/joshk/devise_imapable/events/push", "github://Email?address=josh.kalderimis@gmail.com") def subscribe(topic, callback, secret = nil) options = { :"hub.callback" => callback, :"hub.mode" => "subscribe", :"hub.topic" => topic } options.merge!(:"hub.secret" => secret) unless secret.nil? response = pub_sub_hubbub_request(options) response.status == 204 end # Unsubscribe from a pubsub topic # # @param topic [String] A recoginized pubsub topic # @param callback [String] A callback url to be unsubscribed from # @return [Boolean] true if the unsubscribe was successful, otherwise an error is raised # @see https://developer.github.com/v3/repos/hooks/#subscribing # @example Unsubscribe to push events from one of your repositories, no longer having an email sent when fired # client = Octokit::Client.new(:oauth_token = "token") # client.unsubscribe("https://github.com/joshk/devise_imapable/events/push", "github://Email?address=josh.kalderimis@gmail.com") def unsubscribe(topic, callback) options = { :"hub.callback" => callback, :"hub.mode" => "unsubscribe", :"hub.topic" => topic } response = pub_sub_hubbub_request(options) response.status == 204 end # Subscribe to a repository through pubsub # # @param repo [String, Repository, Hash] A GitHub repository # @param service_name [String] service name owner # @param service_arguments [Hash] params that will be passed by subscribed hook. # List of services is available @ https://github.com/github/github-services/tree/master/docs. # Please refer Data node for complete list of arguments. # @param secret [String] An optional shared secret used to generate a SHA1 HMAC of the outgoing body content # @return [Boolean] True if subscription successful, false otherwise # @see https://developer.github.com/v3/repos/hooks/#subscribing # @example Subscribe to push events to one of your repositories to Travis-CI # client = Octokit::Client.new(:oauth_token = "token") # client.subscribe_service_hook('joshk/device_imapable', 'Travis', { :token => "test", :domain => "domain", :user => "user" }) def subscribe_service_hook(repo, service_name, service_arguments = {}, secret = nil) topic = "#{Octokit.web_endpoint}#{Repository.new(repo)}/events/push" callback = "github://#{service_name}?#{service_arguments.collect{ |k,v| [ k,v ].map{ |p| URI.encode_www_form_component(p) }.join("=") }.join("&") }" subscribe(topic, callback, secret) end # Unsubscribe repository through pubsub # # @param repo [String, Repository, Hash] A GitHub repository # @param service_name [String] service name owner # List of services is available @ https://github.com/github/github-services/tree/master/docs. # @see https://developer.github.com/v3/repos/hooks/#subscribing # @example Subscribe to push events to one of your repositories to Travis-CI # client = Octokit::Client.new(:oauth_token = "token") # client.unsubscribe_service_hook('joshk/device_imapable', 'Travis') def unsubscribe_service_hook(repo, service_name) topic = "#{Octokit.web_endpoint}#{Repository.new(repo)}/events/push" callback = "github://#{service_name}" unsubscribe(topic, callback) end private def pub_sub_hubbub_request(options = {}) # This method is janky, bypass normal stack so we don'tl # serialize request as JSON conn = Faraday.new(:url => @api_endpoint) do |http| http.headers[:user_agent] = user_agent if basic_authenticated? http.basic_auth(@login, @password) elsif token_authenticated? http.authorization 'token', @access_token end http.request :url_encoded http.use Octokit::Response::RaiseError http.adapter Faraday.default_adapter end conn.post do |req| req.url "hub" req.headers['Content-Type'] = 'application/x-www-form-urlencoded' req.body = options end end end end end octokit-3.8.0/lib/octokit/client/meta.rb0000644000004100000410000000077112511016543020204 0ustar www-datawww-datamodule Octokit class Client # Methods for the Meta API # # @see https://developer.github.com/v3/meta/ module Meta # Get meta information about GitHub.com, the service. # @see https://developer.github.com/v3/meta/#meta # @return [Sawyer::Resource] Hash with meta information. # @example Get GitHub meta information # @client.github_meta def meta(options = {}) get "meta", options end alias :github_meta :meta end end end octokit-3.8.0/lib/octokit/client/releases.rb0000644000004100000410000001504112511016543021055 0ustar www-datawww-datamodule Octokit class Client # Methods for the Releases API # # @see https://developer.github.com/v3/repos/releases/ module Releases # List releases for a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @return [Array] A list of releases # @see https://developer.github.com/v3/repos/releases/#list-releases-for-a-repository def releases(repo, options = {}) paginate "#{Repository.path repo}/releases", options end alias :list_releases :releases # Create a release # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param tag_name [String] Git tag from which to create release # @option options [String] :target_commitish Specifies the commitish value that determines where the Git tag is created from. # @option options [String] :name Name for the release # @option options [String] :body Content for release notes # @option options [Boolean] :draft Mark this release as a draft # @option options [Boolean] :prerelease Mark this release as a pre-release # @return [Sawyer::Resource] The release # @see https://developer.github.com/v3/repos/releases/#create-a-release def create_release(repo, tag_name, options = {}) opts = options.merge(:tag_name => tag_name) post "#{Repository.path repo}/releases", opts end # Get a release # # @param url [String] URL for the release as returned from .releases # @return [Sawyer::Resource] The release # @see https://developer.github.com/v3/repos/releases/#get-a-single-release def release(url, options = {}) get url, options end # Update a release # # @param url [String] URL for the release as returned from .releases # @option options [String] :target_commitish Specifies the commitish value that determines where the Git tag is created from. # @option options [String] :name Name for the release # @option options [String] :body Content for release notes # @option options [Boolean] :draft Mark this release as a draft # @option options [Boolean] :prerelease Mark this release as a pre-release # @return [Sawyer::Resource] The release # @see https://developer.github.com/v3/repos/releases/#edit-a-release def update_release(url, options = {}) patch url, options end alias :edit_release :update_release # Delete a release # # @param url [String] URL for the release as returned from .releases # @return [Boolean] Success or failure # @see https://developer.github.com/v3/repos/releases/#delete-a-release def delete_release(url, options = {}) boolean_from_response(:delete, url, options) end # List release assets # # @param release_url [String] URL for the release as returned from .releases # @return [Array] A list of release assets # @see https://developer.github.com/v3/repos/releases/#list-assets-for-a-release def release_assets(release_url, options = {}) paginate release(release_url).rels[:assets].href, options end # Upload a release asset # # @param release_url [String] URL for the release as returned from .releases # @param path_or_file [String] Path to file to upload # @option options [String] :content_type The MIME type for the file to upload # @option options [String] :name The name for the file # @return [Sawyer::Resource] The release asset # @see https://developer.github.com/v3/repos/releases/#upload-a-release-asset def upload_asset(release_url, path_or_file, options = {}) file = path_or_file.respond_to?(:read) ? path_or_file : File.new(path_or_file, "r+b") options[:content_type] ||= content_type_from_file(file) raise Octokit::MissingContentType.new if options[:content_type].nil? unless name = options[:name] name = File.basename(file.path) end upload_url = release(release_url).rels[:upload].href_template.expand(:name => name) request :post, upload_url, file.read, parse_query_and_convenience_headers(options) ensure file.close if file end # Get a single release asset # # # @param asset_url [String] URL for the asset as returned from .release_assets # @return [Sawyer::Resource] The release asset # @see https://developer.github.com/v3/repos/releases/#get-a-single-release-asset def release_asset(asset_url, options = {}) get(asset_url, options) end # Update a release asset # # @param asset_url [String] URL for the asset as returned from .release_assets # @option options [String] :name The name for the file # @option options [String] :label The download text for the file # @return [Sawyer::Resource] The release asset # @see https://developer.github.com/v3/repos/releases/#edit-a-release-asset def update_release_asset(asset_url, options = {}) patch(asset_url, options) end alias :edit_release_asset :update_release_asset # Delete a release asset # # @param asset_url [String] URL for the asset as returned from .release_assets # @return [Boolean] Success or failure # @see https://developer.github.com/v3/repos/releases/#delete-a-release-asset def delete_release_asset(asset_url, options = {}) boolean_from_response(:delete, asset_url, options) end # Get the release for a given tag # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param tag_name [String] the name for a tag # @return [Sawyer::Resource] The release def release_for_tag(repo, tag_name, options = {}) get "#{Repository.path repo}/releases/tags/#{tag_name}", options end # Get the latest release # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @return [Sawyer::Resource] The release def latest_release(repo, options = {}) get "#{Repository.path repo}/releases/latest", options end private def content_type_from_file(file) require 'mime/types' if mime_type = MIME::Types.type_for(file.path).first mime_type.content_type end rescue LoadError msg = "Please pass content_type or install mime-types gem to guess content type from file" raise Octokit::MissingContentType.new(msg) end end end end octokit-3.8.0/lib/octokit/client/deployments.rb0000644000004100000410000000556112511016543021623 0ustar www-datawww-datamodule Octokit class Client # Methods for the Deployments API # # @see https://developer.github.com/v3/repos/commits/deployments/ module Deployments # List all deployments for a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @return [Array] A list of deployments # @see https://developer.github.com/v3/repos/deployments/#list-deployments def deployments(repo, options = {}) get("#{Repository.path repo}/deployments", options) end alias :list_deployments :deployments # Create a deployment for a ref # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param ref [String] The ref to deploy # @option options [String] :task Used by the deployment system to allow different execution paths. Defaults to "deploy". # @option options [String] :payload Meta info about the deployment # @option options [Boolean] :auto_merge Optional parameter to merge the default branch into the requested deployment branch if necessary. Default: true # @option options [Array] :required_contexts Optional array of status contexts verified against commit status checks. # @option options [String] :environment Optional name for the target deployment environment (e.g., production, staging, qa). Default: "production" # @option options [String] :description Optional short description. # @return [Sawyer::Resource] A deployment # @see https://developer.github.com/v3/repos/deployments/#create-a-deployment def create_deployment(repo, ref, options = {}) options[:ref] = ref post("#{Repository.path repo}/deployments", options) end # List all statuses for a Deployment # # @param deployment_url [String] A URL for a deployment resource # @return [Array] A list of deployment statuses # @see https://developer.github.com/v3/repos/deployments/#list-deployment-statuses def deployment_statuses(deployment_url, options = {}) deployment = get(deployment_url, :accept => options[:accept]) get(deployment.rels[:statuses].href, options) end alias :list_deployment_statuses :deployment_statuses # Create a deployment status for a Deployment # # @param deployment_url [String] A URL for a deployment resource # @param state [String] The state: pending, success, failure, error # @return [Sawyer::Resource] A deployment status # @see https://developer.github.com/v3/repos/deployments/#create-a-deployment-status def create_deployment_status(deployment_url, state, options = {}) deployment = get(deployment_url, :accept => options[:accept]) options[:state] = state.to_s.downcase post(deployment.rels[:statuses].href, options) end end end end octokit-3.8.0/lib/octokit/client/commit_comments.rb0000644000004100000410000000775412511016543022463 0ustar www-datawww-datamodule Octokit class Client # Methods for the Commit Comments API # # @see https://developer.github.com/v3/repos/comments/ module CommitComments # List all commit comments # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @return [Array] List of commit comments # @see https://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository def list_commit_comments(repo, options = {}) get "#{Repository.path repo}/comments", options end # List comments for a single commit # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param sha [String] The SHA of the commit whose comments will be fetched # @return [Array] List of commit comments # @see https://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit def commit_comments(repo, sha, options = {}) get "#{Repository.path repo}/commits/#{sha}/comments", options end # Get a single commit comment # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param id [String] The ID of the comment to fetch # @return [Sawyer::Resource] Commit comment # @see https://developer.github.com/v3/repos/comments/#get-a-single-commit-comment def commit_comment(repo, id, options = {}) get "#{Repository.path repo}/comments/#{id}", options end # Create a commit comment # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param sha [String] Sha of the commit to comment on # @param body [String] Message # @param path [String] Relative path of file to comment on # @param line [Integer] Line number in the file to comment on # @param position [Integer] Line index in the diff to comment on # @return [Sawyer::Resource] Commit comment # @see https://developer.github.com/v3/repos/comments/#create-a-commit-comment # @example Create a commit comment # comment = Octokit.create_commit_comment("octocat/Hello-World", "827efc6d56897b048c772eb4087f854f46256132", "My comment message", "README.md", 10, 1) # comment.commit_id # => "827efc6d56897b048c772eb4087f854f46256132" # comment.id # => 54321 # comment.body # => "My comment message" # comment.path # => "README.md" # comment.line # => 10 # comment.position # => 1 def create_commit_comment(repo, sha, body, path=nil, line=nil, position=nil, options = {}) params = { :body => body, :path => path, :line => line, :position => position } post "#{Repository.path repo}/commits/#{sha}/comments", options.merge(params) end # Update a commit comment # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param id [String] The ID of the comment to update # @param body [String] Message # @return [Sawyer::Resource] Updated commit comment # @see https://developer.github.com/v3/repos/comments/#update-a-commit-comment # @example Update a commit comment # comment = Octokit.update_commit_comment("octocat/Hello-World", "860296", "Updated commit comment") # comment.id # => 860296 # comment.body # => "Updated commit comment" def update_commit_comment(repo, id, body, options = {}) params = { :body => body } patch "#{Repository.path repo}/comments/#{id}", options.merge(params) end # Delete a commit comment # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param id [String] The ID of the comment to delete # @return [Boolean] Success # @see https://developer.github.com/v3/repos/comments/#delete-a-commit-comment def delete_commit_comment(repo, id, options = {}) boolean_from_response :delete, "#{Repository.path repo}/comments/#{id}", options end end end end octokit-3.8.0/lib/octokit/client/statuses.rb0000644000004100000410000000373412511016543021133 0ustar www-datawww-datamodule Octokit class Client # Methods for the Commit Statuses API # # @see https://developer.github.com/v3/repos/statuses/ module Statuses # List all statuses for a given commit # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param sha [String] The SHA1 for the commit # @return [Array] A list of statuses # @see https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref def statuses(repo, sha, options = {}) get "#{Repository.path repo}/statuses/#{sha}", options end alias :list_statuses :statuses # Get the combined status for a ref # # @param repo [Integer, String, Repository, Hash] a GitHub repository # @param ref [String] A Sha or Ref to fetch the status of # @return [Sawyer::Resource] The combined status for the commit # @see https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref def combined_status(repo, ref, options = {}) get "#{Repository.path repo}/commits/#{ref}/status", options end alias :status :combined_status # Create status for a commit # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param sha [String] The SHA1 for the commit # @param state [String] The state: pending, success, failure, error # @option options [String] :context A context to differentiate this status from others # @option options [String] :target_url A link to more details about this status # @option options [String] :description A short human-readable description of this status # @return [Sawyer::Resource] A status # @see https://developer.github.com/v3/repos/statuses/#create-a-status def create_status(repo, sha, state, options = {}) options.merge!(:state => state) post "#{Repository.path repo}/statuses/#{sha}", options end end end end octokit-3.8.0/lib/octokit/client/rate_limit.rb0000644000004100000410000000337612511016543021413 0ustar www-datawww-datamodule Octokit class Client # Methods for API rate limiting info # # @see https://developer.github.com/v3/#rate-limiting module RateLimit # Get rate limit info from last response if available # or make a new request to fetch rate limit # # @see https://developer.github.com/v3/rate_limit/#rate-limit # @return [Octokit::RateLimit] Rate limit info def rate_limit(options = {}) return rate_limit! if last_response.nil? Octokit::RateLimit.from_response(last_response) end alias ratelimit rate_limit # Get number of rate limted requests remaining # # @see https://developer.github.com/v3/rate_limit/#rate-limit # @return [Fixnum] Number of requests remaining in this period def rate_limit_remaining(options = {}) octokit_warn "Deprecated: Please use .rate_limit.remaining" rate_limit.remaining end alias ratelimit_remaining rate_limit_remaining # Refresh rate limit info by making a new request # # @see https://developer.github.com/v3/rate_limit/#rate-limit # @return [Octokit::RateLimit] Rate limit info def rate_limit!(options = {}) get "rate_limit" Octokit::RateLimit.from_response(last_response) end alias ratelimit! rate_limit! # Refresh rate limit info and get number of rate limted requests remaining # # @see https://developer.github.com/v3/rate_limit/#rate-limit # @return [Fixnum] Number of requests remaining in this period def rate_limit_remaining!(options = {}) octokit_warn "Deprecated: Please use .rate_limit!.remaining" rate_limit!.remaining end alias ratelimit_remaining! rate_limit_remaining! end end end octokit-3.8.0/lib/octokit/client/service_status.rb0000644000004100000410000000213712511016543022317 0ustar www-datawww-datamodule Octokit class Client # Methods for the GitHub Status API # # @see https://status.github.com/api module ServiceStatus # Root for status API # @private STATUS_ROOT = 'https://status.github.com/api.json' # Returns the current system status # # @return [Sawyer::Resource] GitHub status # @see https://status.github.com/api#api-current-status def github_status get(STATUS_ROOT).rels[:status].get.data end # Returns the last human communication, status, and timestamp. # # @return [Sawyer::Resource] GitHub status last message # @see https://status.github.com/api#api-last-message def github_status_last_message get(STATUS_ROOT).rels[:last_message].get.data end # Returns the most recent human communications with status and timestamp. # # @return [Array] GitHub status messages # @see https://status.github.com/api#api-recent-messages def github_status_messages get(STATUS_ROOT).rels[:messages].get.data end end end end octokit-3.8.0/lib/octokit/client/pages.rb0000644000004100000410000000261112511016543020350 0ustar www-datawww-datamodule Octokit class Client # Methods for the Pages API # # @see https://developer.github.com/v3/repos/pages/ module Pages # List Pages information for a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @return Sawyer::Resource A GitHub Pages resource # @see https://developer.github.com/v3/repos/pages/#get-information-about-a-pages-site def pages(repo, options = {}) get "#{Repository.path repo}/pages", options end # List Pages builds for a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @return [Array] A list of build history for a repository. # @see https://developer.github.com/v3/repos/pages/#list-pages-builds def pages_builds(repo, options = {}) get "#{Repository.path repo}/pages/builds", options end alias :list_pages_builds :pages_builds # List the latest Pages build information for a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @return Sawyer::Resource A GitHub Pages resource about a build # @see https://developer.github.com/v3/repos/pages/#list-latest-pages-build def latest_pages_build(repo, options = {}) get "#{Repository.path repo}/pages/builds/latest", options end end end end octokit-3.8.0/lib/octokit/client/say.rb0000644000004100000410000000055312511016543020050 0ustar www-datawww-datamodule Octokit class Client # Methods for the unpublished Octocat API module Say # Return a nifty ASCII Octocat with GitHub wisdom # or your own # # @return [String] def say(text = nil, options = {}) options[:s] = text if text get "octocat", options end alias :octocat :say end end end octokit-3.8.0/lib/octokit/client/milestones.rb0000644000004100000410000001132712511016543021437 0ustar www-datawww-datamodule Octokit class Client # Methods for the Issues Milestones API # # @see https://developer.github.com/v3/issues/milestones/ module Milestones # List milestones for a repository # # @param repository [String, Repository, Hash] A GitHub repository. # @param options [Hash] A customizable set of options. # @option options [Integer] :milestone Milestone number. # @option options [String] :state (open) State: open or closed. # @option options [String] :sort (created) Sort: created, updated, or comments. # @option options [String] :direction (desc) Direction: asc or desc. # @return [Array] A list of milestones for a repository. # @see https://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository # @example List milestones for a repository # Octokit.list_milestones("octokit/octokit.rb") def list_milestones(repository, options = {}) paginate "repos/#{Repository.new(repository)}/milestones", options end alias :milestones :list_milestones # Get a single milestone for a repository # # @param repository [String, Repository, Hash] A GitHub repository. # @param options [Hash] A customizable set of options. # @option options [Integer] :milestone Milestone number. # @option options [String] :state (open) State: open or closed. # @option options [String] :sort (created) Sort: created, updated, or comments. # @option options [String] :direction (desc) Direction: asc or desc. # @return [Sawyer::Resource] A single milestone from a repository. # @see https://developer.github.com/v3/issues/milestones/#get-a-single-milestone # @example Get a single milestone for a repository # Octokit.milestone("octokit/octokit.rb", 1) def milestone(repository, number, options = {}) get "repos/#{Repository.new(repository)}/milestones/#{number}", options end # Create a milestone for a repository # # @param repository [String, Repository, Hash] A GitHub repository. # @param title [String] A unique title. # @param options [Hash] A customizable set of options. # @option options [String] :state (open) State: open or closed. # @option options [String] :description A meaningful description # @option options [Time] :due_on Set if the milestone has a due date # @return [Sawyer::Resource] A single milestone object # @see https://developer.github.com/v3/issues/milestones/#create-a-milestone # @example Create a milestone for a repository # Octokit.create_milestone("octokit/octokit.rb", "0.7.0", {:description => 'Add support for v3 of Github API'}) def create_milestone(repository, title, options = {}) post "repos/#{Repository.new(repository)}/milestones", options.merge({:title => title}) end # Update a milestone for a repository # # @param repository [String, Repository, Hash] A GitHub repository. # @param number [String, Integer] ID of the milestone # @param options [Hash] A customizable set of options. # @option options [String] :title A unique title. # @option options [String] :state (open) State: open or closed. # @option options [String] :description A meaningful description # @option options [Time] :due_on Set if the milestone has a due date # @return [Sawyer::Resource] A single milestone object # @see https://developer.github.com/v3/issues/milestones/#update-a-milestone # @example Update a milestone for a repository # Octokit.update_milestone("octokit/octokit.rb", 1, {:description => 'Add support for v3 of Github API'}) def update_milestone(repository, number, options = {}) patch "repos/#{Repository.new(repository)}/milestones/#{number}", options end alias :edit_milestone :update_milestone # Delete a single milestone for a repository # # @param repository [String, Repository, Hash] A GitHub repository. # @param options [Hash] A customizable set of options. # @option options [Integer] :milestone Milestone number. # @return [Boolean] Success # @see https://developer.github.com/v3/issues/milestones/#delete-a-milestone # @example Delete a single milestone from a repository # Octokit.delete_milestone("octokit/octokit.rb", 1) def delete_milestone(repository, number, options = {}) boolean_from_response :delete, "repos/#{Repository.new(repository)}/milestones/#{number}", options end end end end octokit-3.8.0/lib/octokit/client/commits.rb0000644000004100000410000002556612511016543020742 0ustar www-datawww-datarequire 'date' module Octokit class Client # Methods for the Commits API # # @see https://developer.github.com/v3/repos/commits/ module Commits # List commits # # @overload commits(repo, sha_or_branch, options = {}) # @deprecated # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param sha_or_branch [String] A commit SHA or branch name # @param options [String] :sha Commit SHA or branch name from which to start the list # @overload commits(repo, options = {}) # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param options [String] :sha Commit SHA or branch name from which to start the list # @return [Array] An array of hashes representing commits # @see https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository def commits(*args) arguments = Octokit::RepoArguments.new(args) sha_or_branch = arguments.pop if sha_or_branch arguments.options[:sha] = sha_or_branch end paginate "#{Repository.new(arguments.repo).path}/commits", arguments.options end alias :list_commits :commits # Get commits after a specified date # # @overload commits_since(repo, date, options = {}) # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param date [String] Date on which we want to compare # @param options [String] :sha Commit SHA or branch name from which to start the list # @overload commits_since(repo, date, sha_or_branch, options = {}) # @deprecated # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param date [String] Date on which we want to compare # @param sha_or_branch [String] A commit SHA or branch name # @param options [String] :sha Commit SHA or branch name from which to start the list # @return [Array] An array of hashes representing commits # @see https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository # @example # Octokit.commits_since('octokit/octokit.rb', '2012-10-01') def commits_since(*args) arguments = Octokit::RepoArguments.new(args) date = parse_date(arguments.shift) params = arguments.options params.merge!(:since => iso8601(date)) sha_or_branch = arguments.pop if sha_or_branch params[:sha] = sha_or_branch end commits(arguments.repo, params) end # Get commits before a specified date # # @overload commits_before(repo, date, options = {}) # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param date [String] Date on which we want to compare # @overload commits_before(repo, date, sha_or_branch, options = {}) # @deprecated # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param date [String] Date on which we want to compare # @param sha_or_branch [String] Commit SHA or branch name from which to start the list # @return [Array] An array of hashes representing commits # @see https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository # @example # Octokit.commits_before('octokit/octokit.rb', '2012-10-01') def commits_before(*args) arguments = Octokit::RepoArguments.new(args) date = parse_date(arguments.shift) params = arguments.options params.merge!(:until => iso8601(date)) sha_or_branch = arguments.pop if sha_or_branch params[:sha] = sha_or_branch end commits(arguments.repo, params) end # Get commits on a specified date # # @overload commits_on(repo, date, options = {}) # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param date [String] Date on which we want to compare # @overload commits_on(repo, date, sha_or_branch, options = {}) # @deprecated # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param date [String] Date on which we want to compare # @param sha_or_branch [String] Commit SHA or branch name from which to start the list # @return [Array] An array of hashes representing commits # @see https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository # @example # Octokit.commits_on('octokit/octokit.rb', '2012-10-01') def commits_on(*args) arguments = Octokit::RepoArguments.new(args) date = parse_date(arguments.shift) params = arguments.options end_date = date + 1 params.merge!(:since => iso8601(date), :until => iso8601(end_date)) sha_or_branch = arguments.pop if sha_or_branch params[:sha] = sha_or_branch end commits(arguments.repo, params) end # Get commits made between two nominated dates # # @overload commits_between(repo, start_date, end_date, options = {}) # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param start_date [String] Start Date on which we want to compare # @param end_date [String] End Date on which we want to compare # @overload commits_between(repo, start_date, end_date, sha_or_branch, options = {}) # @deprecated # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param start_date [String] Start Date on which we want to compare # @param end_date [String] End Date on which we want to compare # @param sha_or_branch [String] Commit SHA or branch name from which to start the list # @return [Array] An array of hashes representing commits # @see https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository # @example # Octokit.commits_on('octokit/octokit.rb', '2012-10-01', '2012-11-01') def commits_between(*args) arguments = Octokit::RepoArguments.new(args) date = parse_date(arguments.shift) end_date = parse_date(arguments.shift) raise ArgumentError, "Start date #{date} does not precede #{end_date}" if date > end_date params = arguments.options params.merge!(:since => iso8601(date), :until => iso8601(end_date)) sha_or_branch = arguments.pop if sha_or_branch params[:sha] = sha_or_branch end commits(arguments.repo, params) end # Get a single commit # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param sha [String] The SHA of the commit to fetch # @return [Sawyer::Resource] A hash representing the commit # @see https://developer.github.com/v3/repos/commits/#get-a-single-commit def commit(repo, sha, options = {}) get "#{Repository.path repo}/commits/#{sha}", options end # Get a detailed git commit # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param sha [String] The SHA of the commit to fetch # @return [Sawyer::Resource] A hash representing the commit # @see https://developer.github.com/v3/git/commits/#get-a-commit def git_commit(repo, sha, options = {}) get "#{Repository.path repo}/git/commits/#{sha}", options end # Create a commit # # Optionally pass author and committer hashes in options # if you'd like manual control over those parameters. If absent, details will be # inferred from the authenticated user. See GitHub's documentation # for details about how to format committer identities. # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param message [String] The commit message # @param tree [String] The SHA of the tree object the new commit will point to # @param parents [String, Array] One SHA (for a normal commit) or an array of SHAs (for a merge) of the new commit's parent commits. If ommitted or empty, a root commit will be created # @return [Sawyer::Resource] A hash representing the new commit # @see https://developer.github.com/v3/git/commits/#create-a-commit # @example Create a commit # commit = Octokit.create_commit("octocat/Hello-World", "My commit message", "827efc6d56897b048c772eb4087f854f46256132", "7d1b31e74ee336d15cbd21741bc88a537ed063a0") # commit.sha # => "7638417db6d59f3c431d3e1f261cc637155684cd" # commit.tree.sha # => "827efc6d56897b048c772eb4087f854f46256132" # commit.message # => "My commit message" # commit.committer # => { "name" => "Wynn Netherland", "email" => "wynn@github.com", ... } def create_commit(repo, message, tree, parents=nil, options = {}) params = { :message => message, :tree => tree } params[:parents] = [parents].flatten if parents post "#{Repository.path repo}/git/commits", options.merge(params) end # Compare two commits # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param start [String] The sha of the starting commit # @param endd [String] The sha of the ending commit # @return [Sawyer::Resource] A hash representing the comparison # @see https://developer.github.com/v3/repos/commits/#compare-two-commits def compare(repo, start, endd, options = {}) get "#{Repository.path repo}/compare/#{start}...#{endd}", options end # Merge a branch or sha # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param base [String] The name of the base branch to merge into # @param head [String] The branch or SHA1 to merge # @option options [String] :commit_message The commit message for the merge # @return [Sawyer::Resource] A hash representing the comparison # @see https://developer.github.com/v3/repos/merging/#perform-a-merge def merge(repo, base, head, options = {}) params = { :base => base, :head => head }.merge(options) post "#{Repository.path repo}/merges", params end protected def iso8601(date) if date.respond_to?(:iso8601) date.iso8601 else date.strftime("%Y-%m-%dT%H:%M:%S%Z") end end # Parses the given string representation of a date, throwing a meaningful exception # (containing the date that failed to parse) in case of failure. # # @param date [String] String representation of a date # @return [DateTime] def parse_date(date) date = DateTime.parse(date.to_s) rescue ArgumentError raise ArgumentError, "#{date} is not a valid date" end end end end octokit-3.8.0/lib/octokit/client/labels.rb0000644000004100000410000001655612511016543020530 0ustar www-datawww-datarequire 'cgi' module Octokit class Client # Methods for the Issue Labels API # # @see https://developer.github.com/v3/issues/labels/ module Labels # List available labels for a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @return [Array] A list of the labels across the repository # @see https://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository # @example List labels for octokit/octokit.rb # Octokit.labels("octokit/octokit.rb") def labels(repo, options = {}) paginate "#{Repository.path repo}/labels", options end # Get single label for a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param name [String] Name of the label # @return [Sawyer::Resource] A single label from the repository # @see https://developer.github.com/v3/issues/labels/#get-a-single-label # @example Get the "V3 Addition" label from octokit/octokit.rb # Octokit.labels("octokit/octokit.rb", "V3 Addition") def label(repo, name, options = {}) get "#{Repository.path repo}/labels/#{name}", options end # Add a label to a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param label [String] A new label # @param color [String] A color, in hex, without the leading # # @return [Sawyer::Resource] The new label # @see https://developer.github.com/v3/issues/labels/#create-a-label # @example Add a new label "Version 1.0" with color "#cccccc" # Octokit.add_label("octokit/octokit.rb", "Version 1.0", "cccccc") def add_label(repo, label, color="ffffff", options = {}) post "#{Repository.path repo}/labels", options.merge({:name => label, :color => color}) end # Update a label # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param label [String] The name of the label which will be updated # @param options [Hash] A customizable set of options. # @option options [String] :name An updated label name # @option options [String] :color An updated color value, in hex, without leading # # @return [Sawyer::Resource] The updated label # @see https://developer.github.com/v3/issues/labels/#update-a-label # @example Update the label "Version 1.0" with new color "#cceeaa" # Octokit.update_label("octokit/octokit.rb", "Version 1.0", {:color => "cceeaa"}) def update_label(repo, label, options = {}) patch "#{Repository.path repo}/labels/#{label}", options end # Delete a label from a repository. # # This deletes the label from the repository, and removes it from all issues. # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param label [String] String name of the label # @return [Boolean] Success # @see https://developer.github.com/v3/issues/labels/#delete-a-label # @example Delete the label "Version 1.0" from the repository. # Octokit.delete_label!("octokit/octokit.rb", "Version 1.0") def delete_label!(repo, label, options = {}) boolean_from_response :delete, "#{Repository.path repo}/labels/#{label}", options end # Remove a label from an Issue # # This removes the label from the Issue # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param number [Fixnum] Number ID of the issue # @param label [String] String name of the label # @return [Array] A list of the labels currently on the issue # @see https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue # @example Remove the label "Version 1.0" from the repository. # Octokit.remove_label("octokit/octokit.rb", 23, "Version 1.0") def remove_label(repo, number, label, options = {}) delete "#{Repository.path repo}/issues/#{number}/labels/#{label}", options end # Remove all label from an Issue # # This removes the label from the Issue # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param number [Fixnum] Number ID of the issue # @return [Boolean] Success of operation # @see https://developer.github.com/v3/issues/labels/#remove-all-labels-from-an-issue # @example Remove all labels from Issue #23 # Octokit.remove_all_labels("octokit/octokit.rb", 23) def remove_all_labels(repo, number, options = {}) boolean_from_response :delete, "#{Repository.path repo}/issues/#{number}/labels", options end # List labels for a given issue # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param number [Fixnum] Number ID of the issue # @return [Array] A list of the labels currently on the issue # @see https://developer.github.com/v3/issues/labels/#list-labels-on-an-issue # @example List labels for octokit/octokit.rb, issue # 1 # Octokit.labels_for_issue("octokit/octokit.rb", 1) def labels_for_issue(repo, number, options = {}) paginate "#{Repository.path repo}/issues/#{number}/labels", options end # Add label(s) to an Issue # # @param repo [Integer, String, Repository, Hash] A Github repository # @param number [Fixnum] Number ID of the issue # @param labels [Array] An array of labels to apply to this Issue # @return [Array] A list of the labels currently on the issue # @see https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue # @example Add two labels for octokit/octokit.rb # Octokit.add_labels_to_an_issue("octokit/octokit.rb", 10, ['V3 Transition', 'Improvement']) def add_labels_to_an_issue(repo, number, labels) post "#{Repository.path repo}/issues/#{number}/labels", labels end # Replace all labels on an Issue # # @param repo [Integer, String, Repository, Hash] A Github repository # @param number [Fixnum] Number ID of the issue # @param labels [Array] An array of labels to use as replacement # @return [Array] A list of the labels currently on the issue # @see https://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue # @example Replace labels for octokit/octokit.rb Issue #10 # Octokit.replace_all_labels("octokit/octokit.rb", 10, ['V3 Transition', 'Improvement']) def replace_all_labels(repo, number, labels, options = {}) put "#{Repository.path repo}/issues/#{number}/labels", labels end # Get labels for every issue in a milestone # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param number [Fixnum] Number ID of the milestone # @return [Array] A list of the labels across the milestone # @see http://developer.github.com/v3/issues/labels/#get-labels-for-every-issue-in-a-milestone # @example List all labels for milestone #2 on octokit/octokit.rb # Octokit.labels_for_milestone("octokit/octokit.rb", 2) def labels_for_milestone(repo, number, options = {}) paginate "#{Repository.path repo}/milestones/#{number}/labels", options end end end end octokit-3.8.0/lib/octokit/client/issues.rb0000644000004100000410000003474412511016543020600 0ustar www-datawww-datamodule Octokit class Client # Methods for the Issues API # # @see https://developer.github.com/v3/issues/ module Issues # List issues for the authenticated user or repository # # @param repository [Integer, String, Repository, Hash] A GitHub repository. # @param options [Sawyer::Resource] A customizable set of options. # @option options [Integer] :milestone Milestone number. # @option options [String] :state (open) State: open or closed. # @option options [String] :assignee User login. # @option options [String] :creator User login. # @option options [String] :mentioned User login. # @option options [String] :labels List of comma separated Label names. Example: bug,ui,@high. # @option options [String] :sort (created) Sort: created, updated, or comments. # @option options [String] :direction (desc) Direction: asc or desc. # @option options [Integer] :page (1) Page number. # @return [Array] A list of issues for a repository. # @see https://developer.github.com/v3/issues/#list-issues-for-a-repository # @see https://developer.github.com/v3/issues/#list-issues # @example List issues for a repository # Octokit.list_issues("sferik/rails_admin") # @example List issues for the authenticated user across repositories # @client = Octokit::Client.new(:login => 'foo', :password => 'bar') # @client.list_issues def list_issues(repository = nil, options = {}) paginate "#{Repository.new(repository).path}/issues", options end alias :issues :list_issues # List all issues across owned and member repositories for the authenticated user # # @param options [Sawyer::Resource] A customizable set of options. # @option options [String] :filter (assigned) State: assigned, created, mentioned, subscribed or closed. # @option options [String] :state (open) State: open or closed. # @option options [String] :labels List of comma separated Label names. Example: bug,ui,@high. # @option options [String] :sort (created) Sort: created, updated, or comments. # @option options [String] :direction (desc) Direction: asc or desc. # @option options [Integer] :page (1) Page number. # @option options [String] :since Timestamp in ISO 8601 # format: YYYY-MM-DDTHH:MM:SSZ # @return [Array] A list of issues for a repository. # @see https://developer.github.com/v3/issues/#list-issues # @example List issues for the authenticated user across owned and member repositories # @client = Octokit::Client.new(:login => 'foo', :password => 'bar') # @client.user_issues def user_issues(options = {}) paginate 'user/issues', options end # List all issues for a given organization for the authenticated user # # @param org [String, Integer] Organization GitHub login or id. # @param options [Sawyer::Resource] A customizable set of options. # @option options [String] :filter (assigned) State: assigned, created, mentioned, subscribed or closed. # @option options [String] :state (open) State: open or closed. # @option options [String] :labels List of comma separated Label names. Example: bug,ui,@high. # @option options [String] :sort (created) Sort: created, updated, or comments. # @option options [String] :direction (desc) Direction: asc or desc. # @option options [Integer] :page (1) Page number. # @option options [String] :since Timestamp in ISO 8601 # format: YYYY-MM-DDTHH:MM:SSZ # @return [Array] A list of issues. # @see https://developer.github.com/v3/issues/#list-issues # @example List all issues for a given organization for the authenticated user # @client = Octokit::Client.new(:login => 'foo', :password => 'bar') # @client.org_issues("octokit") def org_issues(org, options = {}) paginate "#{Organization.path org}/issues", options end # Create an issue for a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param title [String] A descriptive title # @param body [String] An optional concise description # @param options [Hash] A customizable set of options. # @option options [String] :assignee User login. # @option options [Integer] :milestone Milestone number. # @option options [String] :labels List of comma separated Label names. Example: bug,ui,@high. # @return [Sawyer::Resource] Your newly created issue # @see https://developer.github.com/v3/issues/#create-an-issue # @example Create a new Issues for a repository # Octokit.create_issue("sferik/rails_admin", 'Updated Docs', 'Added some extra links') def create_issue(repo, title, body = nil, options = {}) options[:labels] = case options[:labels] when String options[:labels].split(",").map(&:strip) when Array options[:labels] else [] end parameters = { :title => title } parameters[:body] = body unless body.nil? post "#{Repository.path repo}/issues", options.merge(parameters) end alias :open_issue :create_issue # Get a single issue from a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param number [Integer] Number ID of the issue # @return [Sawyer::Resource] The issue you requested, if it exists # @see https://developer.github.com/v3/issues/#get-a-single-issue # @example Get issue #25 from octokit/octokit.rb # Octokit.issue("octokit/octokit.rb", "25") def issue(repo, number, options = {}) get "#{Repository.path repo}/issues/#{number}", options end # Close an issue # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param number [Integer] Number ID of the issue # @param options [Hash] A customizable set of options. # @option options [String] :assignee User login. # @option options [Integer] :milestone Milestone number. # @option options [String] :labels List of comma separated Label names. Example: bug,ui,@high. # @return [Sawyer::Resource] The updated Issue # @see https://developer.github.com/v3/issues/#edit-an-issue # @example Close Issue #25 from octokit/octokit.rb # Octokit.close_issue("octokit/octokit.rb", "25") def close_issue(repo, number, options = {}) patch "#{Repository.path repo}/issues/#{number}", options.merge({:state => "closed"}) end # Reopen an issue # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param number [Integer] Number ID of the issue # @param options [Hash] A customizable set of options. # @option options [String] :assignee User login. # @option options [Integer] :milestone Milestone number. # @option options [String] :labels List of comma separated Label names. Example: bug,ui,@high. # @return [Sawyer::Resource] The updated Issue # @see https://developer.github.com/v3/issues/#edit-an-issue # @example Reopen Issue #25 from octokit/octokit.rb # Octokit.reopen_issue("octokit/octokit.rb", "25") def reopen_issue(repo, number, options = {}) patch "#{Repository.path repo}/issues/#{number}", options.merge({:state => "open"}) end # Update an issue # # @overload update_issue(repo, number, title, body, options) # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param number [Integer] Number ID of the issue # @param title [String] Updated title for the issue # @param body [String] Updated body of the issue # @param options [Hash] A customizable set of options. # @option options [String] :assignee User login. # @option options [Integer] :milestone Milestone number. # @option options [String] :labels List of comma separated Label names. Example: bug,ui,@high. # @option options [String] :state State of the issue. open or closed # # @overload update_issue(repo, number, options) # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param number [Integer] Number ID of the issue # @param options [Hash] A customizable set of options. # @option options [String] :title Updated title for the issue # @option options [String] :body Updated body of the issue # @option options [String] :assignee User login. # @option options [Integer] :milestone Milestone number. # @option options [String] :labels List of comma separated Label names. Example: bug,ui,@high. # @option options [String] :state State of the issue. open or closed # @return [Sawyer::Resource] The updated Issue # @see https://developer.github.com/v3/issues/#edit-an-issue # # @example Change the title of Issue #25 # Octokit.update_issue("octokit/octokit.rb", "25", "A new title", "the same body") # # @example Change only the assignee of Issue #25 # Octokit.update_issue("octokit/octokit.rb", "25", :assignee => "pengwynn") def update_issue(repo, number, *args) arguments = Arguments.new(args) opts = arguments.options if arguments.length > 0 opts[:title] = arguments.shift opts[:body] = arguments.shift end patch "#{Repository.path repo}/issues/#{number}", opts end # Get all comments attached to issues for the repository # # By default, Issue Comments are ordered by ascending ID. # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param options [Hash] Optional parameters # @option options [String] :sort created or updated # @option options [String] :direction asc or desc. Ignored without sort # parameter. # @option options [String] :since Timestamp in ISO 8601 # format: YYYY-MM-DDTHH:MM:SSZ # # @return [Array] List of issues comments. # # @see https://developer.github.com/v3/issues/comments/#list-comments-in-a-repository # # @example Get the comments for issues in the octokit repository # @client.issues_comments("octokit/octokit.rb") # # @example Get issues comments, sort by updated descending since a time # @client.issues_comments("octokit/octokit.rb", { # :sort => 'desc', # :direction => 'asc', # :since => '2010-05-04T23:45:02Z' # }) def issues_comments(repo, options = {}) paginate "#{Repository.path repo}/issues/comments", options end # Get all comments attached to an issue # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param number [Integer] Number ID of the issue # @return [Array] Array of comments that belong to an issue # @see https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue # @example Get comments for issue #25 from octokit/octokit.rb # Octokit.issue_comments("octokit/octokit.rb", "25") def issue_comments(repo, number, options = {}) paginate "#{Repository.path repo}/issues/#{number}/comments", options end # Get a single comment attached to an issue # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param number [Integer] Number ID of the comment # @return [Sawyer::Resource] The specific comment in question # @see https://developer.github.com/v3/issues/comments/#get-a-single-comment # @example Get comment #1194549 from an issue on octokit/octokit.rb # Octokit.issue_comments("octokit/octokit.rb", 1194549) def issue_comment(repo, number, options = {}) paginate "#{Repository.path repo}/issues/comments/#{number}", options end # Add a comment to an issue # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param number [Integer] Issue number # @param comment [String] Comment to be added # @return [Sawyer::Resource] Comment # @see https://developer.github.com/v3/issues/comments/#create-a-comment # @example Add the comment "Almost to v1" to Issue #23 on octokit/octokit.rb # Octokit.add_comment("octokit/octokit.rb", 23, "Almost to v1") def add_comment(repo, number, comment, options = {}) post "#{Repository.path repo}/issues/#{number}/comments", options.merge({:body => comment}) end # Update a single comment on an issue # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param number [Integer] Comment number # @param comment [String] Body of the comment which will replace the existing body. # @return [Sawyer::Resource] Comment # @see https://developer.github.com/v3/issues/comments/#edit-a-comment # @example Update the comment #1194549 with body "I've started this on my 25-issue-comments-v3 fork" on an issue on octokit/octokit.rb # Octokit.update_comment("octokit/octokit.rb", 1194549, "Almost to v1, added this on my fork") def update_comment(repo, number, comment, options = {}) patch "#{Repository.path repo}/issues/comments/#{number}", options.merge({:body => comment}) end # Delete a single comment # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param number [Integer] Comment number # @return [Boolean] Success # @see https://developer.github.com/v3/issues/comments/#delete-a-comment # @example Delete the comment #1194549 on an issue on octokit/octokit.rb # Octokit.delete_comment("octokit/octokit.rb", 1194549) def delete_comment(repo, number, options = {}) boolean_from_response :delete, "#{Repository.path repo}/issues/comments/#{number}", options end end end end octokit-3.8.0/lib/octokit/client/markdown.rb0000644000004100000410000000161412511016543021075 0ustar www-datawww-datamodule Octokit class Client # Methods for the Markdown API # # @see https://developer.github.com/v3/markdown/ module Markdown # Render an arbitrary Markdown document # # @param text [String] Markdown source # @option options [String] (optional) :mode (`markdown` or `gfm`) # @option options [String] (optional) :context Repo context # @return [String] HTML renderization # @see https://developer.github.com/v3/markdown/#render-an-arbitrary-markdown-document # @example Render some GFM # Octokit.markdown('Fixed in #111', :mode => "gfm", :context => "octokit/octokit.rb") def markdown(text, options = {}) options[:text] = text options[:repo] = Repository.new(options[:repo]) if options[:repo] options[:accept] = 'application/vnd.github.raw' post "markdown", options end end end end octokit-3.8.0/lib/octokit/client/notifications.rb0000644000004100000410000001736112511016543022132 0ustar www-datawww-datamodule Octokit class Client # Methods for the Notifications API # # @see https://developer.github.com/v3/activity/notifications/ module Notifications # List your notifications # # @param options [Hash] Optional parameters # @option options [Boolean] :all 'true' to show notifications marked as # read. # @option options [Boolean] :participating 'true' to show only # notifications in which the user is directly participating or # mentioned. # @option options [String] :since Time filters out any notifications # updated before the given time. The time should be passed in as UTC in # the ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. Ex. '2012-10-09T23:39:01Z' # @return [Array] Array of notifications. # @see https://developer.github.com/v3/activity/notifications/#list-your-notifications # @example Get users notifications # @client.notifications # @example Get all notifications since a certain time. # @client.notifications({all: true, since: '2012-10-09T23:39:01Z'}) def notifications(options = {}) paginate "notifications", options end # List your notifications in a repository # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param options [Hash] Optional parameters # @option options [Boolean] :all 'true' to show notifications marked as # read. # @option options [Boolean] :participating 'true' to show only # notifications in which the user is directly participating or # mentioned. # @option options [String] :since Time filters out any notifications # updated before the given time. The time should be passed in as UTC in # the ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. Ex. '2012-10-09T23:39:01Z' # @return [Array] Array of notifications. # @see https://developer.github.com/v3/activity/notifications/#list-your-notifications-in-a-repository # @example Get your notifications for octokit/octokit.rb # @client.repository_notifications('octokit/octokit.rb') # @example Get your notifications for octokit/octokit.rb since a time. # @client.repository_notifications({since: '2012-10-09T23:39:01Z'}) def repository_notifications(repo, options = {}) paginate "#{Repository.path repo}/notifications", options end alias :repo_notifications :repository_notifications # Mark notifications as read # # @param options [Hash] Optional parameters # @option options [Boolean] :unread Changes the unread status of the # threads. # @option options [Boolean] :read Inverse of 'unread'. # @option options [String] :last_read_at ('Now') Describes the last point # that notifications were checked. Anything updated since this time # will not be updated. The time should be passed in as UTC in the # ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. Ex. '2012-10-09T23:39:01Z' # @return [Boolean] True if marked as read, false otherwise # @see https://developer.github.com/v3/activity/notifications/#mark-as-read # # @example # @client.mark_notifications_as_read def mark_notifications_as_read(options = {}) request :put, "notifications", options last_response.status == 205 end # Mark notifications from a specific repository as read # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param options [Hash] Optional parameters # @option options [Boolean] :unread Changes the unread status of the # threads. # @option options [Boolean] :read Inverse of 'unread'. # @option options [String] :last_read_at ('Now') Describes the last point # that notifications were checked. Anything updated since this time # will not be updated. The time should be passed in as UTC in the # ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. Ex. '2012-10-09T23:39:01Z' # @return [Boolean] True if marked as read, false otherwise # @see https://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository # @example # @client.mark_notifications_as_read("octokit/octokit.rb") def mark_repository_notifications_as_read(repo, options = {}) request :put, "#{Repository.path repo}/notifications", options last_response.status == 205 end alias :mark_repo_notifications_as_read :mark_repository_notifications_as_read # List notifications for a specific thread # # @param thread_id [Integer] Id of the thread. # @return [Array] Array of notifications. # @see https://developer.github.com/v3/activity/notifications/#view-a-single-thread # # @example # @client.notification_thread(1000) def thread_notifications(thread_id, options = {}) get "notifications/threads/#{thread_id}", options end # Mark thread as read # # @param thread_id [Integer] Id of the thread to update. # @param options [Hash] Optional parameters. # @option options [Boolean] :unread Changes the unread status of the # threads. # @option options [Boolean] :read Inverse of 'unread'. # @return [Boolean] True if updated, false otherwise. # @see https://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read # @example # @client.mark_thread_as_ready(1, :read => false) def mark_thread_as_read(thread_id, options = {}) request :patch, "notifications/threads/#{thread_id}", options last_response.status == 205 end # Get thread subscription # # @param thread_id [Integer] Id of the thread. # @return [Sawyer::Resource] Subscription. # @see https://developer.github.com/v3/activity/notifications/#get-a-thread-subscription # @example # @client.thread_subscription(1) def thread_subscription(thread_id, options = {}) get "notifications/threads/#{thread_id}/subscription", options end # Update thread subscription # # This lets you subscribe to a thread, or ignore it. Subscribing to a # thread is unnecessary if the user is already subscribed to the # repository. Ignoring a thread will mute all future notifications (until # you comment or get @mentioned). # # @param thread_id [Integer] Id of the thread. # @param options # @option options [Boolean] :subscribed Determines if notifications # should be received from this repository. # @option options [Boolean] :ignored Deterimines if all notifications # should be blocked from this repository. # @return [Sawyer::Resource] Updated subscription. # @see https://developer.github.com/v3/activity/notifications/#set-a-thread-subscription # @example Subscribe to notifications # @client.update_thread_subscription(1, :subscribed => true) # @example Ignore notifications from a repo # @client.update_thread_subscription(1, :ignored => true) def update_thread_subscription(thread_id, options = {}) put "notifications/threads/#{thread_id}/subscription", options end # Delete a thread subscription # # @param thread_id [Integer] Id of the thread. # @return [Boolean] True if delete successful, false otherwise. # @see https://developer.github.com/v3/activity/notifications/#delete-a-thread-subscription # @example # @client.delete_thread_subscription(1) def delete_thread_subscription(thread_id, options = {}) boolean_from_response :delete, "notifications/threads/#{thread_id}/subscription", options end end end end octokit-3.8.0/lib/octokit/client/downloads.rb0000644000004100000410000000406112511016543021244 0ustar www-datawww-datamodule Octokit class Client # Methods for the Repo Downloads API # # @see https://developer.github.com/v3/repos/downloads/ module Downloads # List available downloads for a repository # # @param repo [Integer, String, Repository, Hash] A Github Repository # @return [Array] A list of available downloads # @deprecated As of December 11th, 2012: https://github.com/blog/1302-goodbye-uploads # @see https://developer.github.com/v3/repos/downloads/#list-downloads-for-a-repository # @example List all downloads for Github/Hubot # Octokit.downloads("github/hubot") def downloads(repo, options={}) paginate "#{Repository.path repo}/downloads", options end alias :list_downloads :downloads # Get single download for a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param id [Integer] ID of the download # @return [Sawyer::Resource] A single download from the repository # @deprecated As of December 11th, 2012: https://github.com/blog/1302-goodbye-uploads # @see https://developer.github.com/v3/repos/downloads/#get-a-single-download # @example Get the "Robawt" download from Github/Hubot # Octokit.download("github/hubot") def download(repo, id, options={}) get "#{Repository.path repo}/downloads/#{id}", options end # Delete a single download for a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param id [Integer] ID of the download # @deprecated As of December 11th, 2012: https://github.com/blog/1302-goodbye-uploads # @see https://developer.github.com/v3/repos/downloads/#delete-a-download # @return [Boolean] Status # @example Get the "Robawt" download from Github/Hubot # Octokit.delete_download("github/hubot", 1234) def delete_download(repo, id, options = {}) boolean_from_response :delete, "#{Repository.path repo}/downloads/#{id}", options end end end end octokit-3.8.0/lib/octokit/client/gists.rb0000644000004100000410000001672712511016543020417 0ustar www-datawww-datamodule Octokit class Client # Methods for the Gists API # # @see https://developer.github.com/v3/gists/ module Gists # List gists for a user or all public gists # # @param user [String] An optional user to filter listing # @return [Array] A list of gists # @example Fetch all gists for defunkt # Octokit.gists('defunkt') # @example Fetch all public gists # Octokit.gists # @see https://developer.github.com/v3/gists/#list-gists def gists(user=nil, options = {}) if user.nil? paginate 'gists', options else paginate "#{User.path user}/gists", options end end alias :list_gists :gists # List public gists # # @return [Array] A list of gists # @example Fetch all public gists # Octokit.public_gists # @see https://developer.github.com/v3/gists/#list-gists def public_gists(options = {}) paginate 'gists/public', options end # List the authenticated user’s starred gists # # @return [Array] A list of gists # @see https://developer.github.com/v3/gists/#list-gists def starred_gists(options = {}) paginate 'gists/starred', options end # Get a single gist # # @param gist [String] ID of gist to fetch # @return [Sawyer::Resource] Gist information # @see https://developer.github.com/v3/gists/#get-a-single-gist def gist(gist, options = {}) get "gists/#{Gist.new(gist)}", options end # Create a gist # # @param options [Hash] Gist information. # @option options [String] :description # @option options [Boolean] :public Sets gist visibility # @option options [Array] :files Files that make up this gist. Keys # should be the filename, the value a Hash with a :content key with text # content of the Gist. # @return [Sawyer::Resource] Newly created gist info # @see https://developer.github.com/v3/gists/#create-a-gist def create_gist(options = {}) post 'gists', options end # Edit a gist # # @param options [Hash] Gist information. # @option options [String] :description # @option options [Boolean] :public Sets gist visibility # @option options [Hash] :files Files that make up this gist. Keys # should be the filename, the value a Hash with a :content key with text # content of the Gist. # # NOTE: All files from the previous version of the # gist are carried over by default if not included in the hash. Deletes # can be performed by including the filename with a null hash. # @return # [Sawyer::Resource] Newly created gist info # @see https://developer.github.com/v3/gists/#edit-a-gist # @example Update a gist # @client.edit_gist('some_id', { # :files => {"boo.md" => {"content" => "updated stuff"}} # }) def edit_gist(gist, options = {}) patch "gists/#{Gist.new(gist)}", options end # # Star a gist # # @param gist [String] Gist ID # @return [Boolean] Indicates if gist is starred successfully # @see https://developer.github.com/v3/gists/#star-a-gist def star_gist(gist, options = {}) boolean_from_response :put, "gists/#{Gist.new(gist)}/star", options end # Unstar a gist # # @param gist [String] Gist ID # @return [Boolean] Indicates if gist is unstarred successfully # @see https://developer.github.com/v3/gists/#unstar-a-gist def unstar_gist(gist, options = {}) boolean_from_response :delete, "gists/#{Gist.new(gist)}/star", options end # Check if a gist is starred # # @param gist [String] Gist ID # @return [Boolean] Indicates if gist is starred # @see https://developer.github.com/v3/gists/#check-if-a-gist-is-starred def gist_starred?(gist, options = {}) boolean_from_response :get, "gists/#{Gist.new(gist)}/star", options end # Fork a gist # # @param gist [String] Gist ID # @return [Sawyer::Resource] Data for the new gist # @see https://developer.github.com/v3/gists/#fork-a-gist def fork_gist(gist, options = {}) post "gists/#{Gist.new(gist)}/forks", options end # Delete a gist # # @param gist [String] Gist ID # @return [Boolean] Indicating success of deletion # @see https://developer.github.com/v3/gists/#delete-a-gist def delete_gist(gist, options = {}) boolean_from_response :delete, "gists/#{Gist.new(gist)}", options end # List gist comments # # @param gist_id [String] Gist Id. # @return [Array] Array of hashes representing comments. # @see https://developer.github.com/v3/gists/comments/#list-comments-on-a-gist # @example # Octokit.gist_comments('3528ae645') def gist_comments(gist_id, options = {}) paginate "gists/#{gist_id}/comments", options end # Get gist comment # # @param gist_id [String] Id of the gist. # @param gist_comment_id [Integer] Id of the gist comment. # @return [Sawyer::Resource] Hash representing gist comment. # @see https://developer.github.com/v3/gists/comments/#get-a-single-comment # @example # Octokit.gist_comment('208sdaz3', 1451398) def gist_comment(gist_id, gist_comment_id, options = {}) get "gists/#{gist_id}/comments/#{gist_comment_id}", options end # Create gist comment # # Requires authenticated client. # # @param gist_id [String] Id of the gist. # @param comment [String] Comment contents. # @return [Sawyer::Resource] Hash representing the new comment. # @see https://developer.github.com/v3/gists/comments/#create-a-comment # @example # @client.create_gist_comment('3528645', 'This is very helpful.') def create_gist_comment(gist_id, comment, options = {}) options.merge!({:body => comment}) post "gists/#{gist_id}/comments", options end # Update gist comment # # Requires authenticated client # # @param gist_id [String] Id of the gist. # @param gist_comment_id [Integer] Id of the gist comment to update. # @param comment [String] Updated comment contents. # @return [Sawyer::Resource] Hash representing the updated comment. # @see https://developer.github.com/v3/gists/comments/#edit-a-comment # @example # @client.update_gist_comment('208sdaz3', '3528645', ':heart:') def update_gist_comment(gist_id, gist_comment_id, comment, options = {}) options.merge!({:body => comment}) patch "gists/#{gist_id}/comments/#{gist_comment_id}", options end # Delete gist comment # # Requires authenticated client. # # @param gist_id [String] Id of the gist. # @param gist_comment_id [Integer] Id of the gist comment to delete. # @return [Boolean] True if comment deleted, false otherwise. # @see https://developer.github.com/v3/gists/comments/#delete-a-comment # @example # @client.delete_gist_comment('208sdaz3', '586399') def delete_gist_comment(gist_id, gist_comment_id, options = {}) boolean_from_response(:delete, "gists/#{gist_id}/comments/#{gist_comment_id}", options) end end end end octokit-3.8.0/lib/octokit/client/refs.rb0000644000004100000410000001275512511016543020222 0ustar www-datawww-datamodule Octokit class Client # Methods for References for Git Data API # # @see https://developer.github.com/v3/git/refs/ module Refs # List all refs for a given user and repo # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param namespace [String] The ref namespace, e.g. tag or heads # @return [Array] A list of references matching the repo and the namespace # @see https://developer.github.com/v3/git/refs/#get-all-references # @example Fetch all refs for sferik/rails_admin # Octokit.refs("sferik/rails_admin") def refs(repo, namespace = nil, options = {}) path = "#{Repository.path repo}/git/refs" path += "/#{namespace}" unless namespace.nil? paginate path, options end alias :list_refs :refs alias :references :refs alias :list_references :refs # Fetch a given reference # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param ref [String] The ref, e.g. tags/v0.0.3 # @return [Sawyer::Resource] The reference matching the given repo and the ref id # @see https://developer.github.com/v3/git/refs/#get-a-reference # @example Fetch tags/v0.0.3 for sferik/rails_admin # Octokit.ref("sferik/rails_admin","tags/v0.0.3") def ref(repo, ref, options = {}) get "#{Repository.path repo}/git/refs/#{ref}", options end alias :reference :ref # Create a reference # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param ref [String] The ref, e.g. tags/v0.0.3 # @param sha [String] A SHA, e.g. 827efc6d56897b048c772eb4087f854f46256132 # @return [Array] The list of references, already containing the new one # @see https://developer.github.com/v3/git/refs/#create-a-reference # @example Create refs/heads/master for octocat/Hello-World with sha 827efc6d56897b048c772eb4087f854f46256132 # Octokit.create_ref("octocat/Hello-World","heads/master", "827efc6d56897b048c772eb4087f854f46256132") def create_ref(repo, ref, sha, options = {}) parameters = { :ref => "refs/#{ref}", :sha => sha } post "#{Repository.path repo}/git/refs", options.merge(parameters) end alias :create_reference :create_ref # Update a reference # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param ref [String] The ref, e.g. tags/v0.0.3 # @param sha [String] A SHA, e.g. 827efc6d56897b048c772eb4087f854f46256132 # @param force [Boolean] A flag indicating one wants to force the update to make sure the update is a fast-forward update. # @return [Array] The list of references updated # @see https://developer.github.com/v3/git/refs/#update-a-reference # @example Force update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd # Octokit.update_ref("octocat/Hello-World","heads/sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd") def update_ref(repo, ref, sha, force = true, options = {}) parameters = { :sha => sha, :force => force } patch "#{Repository.path repo}/git/refs/#{ref}", options.merge(parameters) end alias :update_reference :update_ref # Update a branch # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param branch [String] The ref, e.g. feature/new-shiny # @param sha [String] A SHA, e.g. 827efc6d56897b048c772eb4087f854f46256132 # @param force [Boolean] A flag indicating one wants to force the update to make sure the update is a fast-forward update. # @return [Array] The list of references updated # @see https://developer.github.com/v3/git/refs/#update-a-reference # @example Force update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd # Octokit.update_ref("octocat/Hello-World","sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd") def update_branch(repo, branch, sha, force = true, options = {}) update_ref repo, "heads/#{branch}", sha, force, options end # Delete a single branch # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param branch [String] The branch, e.g. fix-refs # @return [Boolean] Success # @see https://developer.github.com/v3/git/refs/#delete-a-reference # @example Delete uritemplate for sigmavirus24/github3.py # Octokit.delete_branch("sigmavirus24/github3.py", "uritemplate") def delete_branch(repo, branch, options = {}) delete_ref repo, "heads/#{branch}", options end # Delete a single reference # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param ref [String] The ref, e.g. tags/v0.0.3 # @return [Boolean] Success # @see https://developer.github.com/v3/git/refs/#delete-a-reference # @example Delete tags/v0.0.3 for sferik/rails_admin # Octokit.delete_ref("sferik/rails_admin","tags/v0.0.3") def delete_ref(repo, ref, options = {}) boolean_from_response :delete, "#{Repository.path repo}/git/refs/#{ref}", options end alias :delete_reference :delete_ref end end end octokit-3.8.0/lib/octokit/client/feeds.rb0000644000004100000410000000150012511016543020333 0ustar www-datawww-datamodule Octokit class Client # Methods for the Feeds API # # @see https://developer.github.com/v3/activity/feeds/ module Feeds # List Feeds # # The feeds returned depend on authentication, see the GitHub API docs # for more information. # # @return [Array] list of feeds # @see https://developer.github.com/v3/activity/feeds/#list-feeds def feeds get "feeds" end # Get a Feed by name # # @param name [Symbol, String] Name of feed to retrieve. # @return [Feed] Parsed feed in the format returned by the configured # parser. def feed(name, options = {}) if rel = feeds._links[name] get rel.href, :accept => rel.type, :options => options end end end end end octokit-3.8.0/lib/octokit/client/repositories.rb0000644000004100000410000005735512511016543022017 0ustar www-datawww-datamodule Octokit class Client # Methods for the Repositories API # # @see https://developer.github.com/v3/repos/ module Repositories # Check if a repository exists # # @see https://developer.github.com/v3/repos/#get # @param repo [Integer, String, Hash, Repository] A GitHub repository # @return [Sawyer::Resource] if a repository exists, false otherwise def repository?(repo, options = {}) !!repository(repo, options) rescue Octokit::NotFound false end # Get a single repository # # @see https://developer.github.com/v3/repos/#get # @param repo [Integer, String, Hash, Repository] A GitHub repository # @return [Sawyer::Resource] Repository information def repository(repo, options = {}) get Repository.path(repo), options end alias :repo :repository # Edit a repository # # @see https://developer.github.com/v3/repos/#edit # @param repo [String, Hash, Repository] A GitHub repository # @param options [Hash] Repository information to update # @option options [String] :name Name of the repo # @option options [String] :description Description of the repo # @option options [String] :homepage Home page of the repo # @option options [String] :private `true` makes the repository private, and `false` makes it public. # @option options [String] :has_issues `true` enables issues for this repo, `false` disables issues. # @option options [String] :has_wiki `true` enables wiki for this repo, `false` disables wiki. # @option options [String] :has_downloads `true` enables downloads for this repo, `false` disables downloads. # @option options [String] :default_branch Update the default branch for this repository. # @return [Sawyer::Resource] Repository information def edit_repository(repo, options = {}) repo = Repository.new(repo) options[:name] ||= repo.name patch "repos/#{repo}", options end alias :edit :edit_repository alias :update_repository :edit_repository alias :update :edit_repository # List user repositories # # If user is not supplied, repositories for the current # authenticated user are returned. # # @note If the user provided is a GitHub organization, only the # organization's public repositories will be listed. For retrieving # organization repositories the {Organizations#organization_repositories} # method should be used instead. # @see https://developer.github.com/v3/repos/#list-your-repositories # @see https://developer.github.com/v3/repos/#list-user-repositories # @param user [Integer, String] Optional GitHub user login or id for which # to list repos. # @return [Array] List of repositories def repositories(user=nil, options = {}) paginate "#{User.path user}/repos", options end alias :list_repositories :repositories alias :list_repos :repositories alias :repos :repositories # List all repositories # # This provides a dump of every repository, in the order that they were # created. # # @see https://developer.github.com/v3/repos/#list-all-public-repositories # # @param options [Hash] Optional options # @option options [Integer] :since The integer ID of the last Repository # that you’ve seen. # @return [Array] List of repositories. def all_repositories(options = {}) paginate 'repositories', options end # Star a repository # # @param repo [String, Hash, Repository] A GitHub repository # @return [Boolean] `true` if successfully starred # @see https://developer.github.com/v3/activity/starring/#star-a-repository def star(repo, options = {}) boolean_from_response :put, "user/starred/#{Repository.new(repo)}", options end # Unstar a repository # # @param repo [String, Hash, Repository] A GitHub repository # @return [Boolean] `true` if successfully unstarred # @see https://developer.github.com/v3/activity/starring/#unstar-a-repository def unstar(repo, options = {}) boolean_from_response :delete, "user/starred/#{Repository.new(repo)}", options end # Watch a repository # # @param repo [String, Hash, Repository] A GitHub repository # @return [Boolean] `true` if successfully watched # @deprecated Use #star instead # @see https://developer.github.com/v3/activity/watching/#watch-a-repository-legacy def watch(repo, options = {}) boolean_from_response :put, "user/watched/#{Repository.new(repo)}", options end # Unwatch a repository # # @param repo [String, Hash, Repository] A GitHub repository # @return [Boolean] `true` if successfully unwatched # @deprecated Use #unstar instead # @see https://developer.github.com/v3/activity/watching/#stop-watching-a-repository-legacy def unwatch(repo, options = {}) boolean_from_response :delete, "user/watched/#{Repository.new(repo)}", options end # Fork a repository # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @return [Sawyer::Resource] Repository info for the new fork # @see https://developer.github.com/v3/repos/forks/#create-a-fork def fork(repo, options = {}) post "#{Repository.path repo}/forks", options end # Create a repository for a user or organization # # @param name [String] Name of the new repo # @option options [String] :description Description of the repo # @option options [String] :homepage Home page of the repo # @option options [String] :private `true` makes the repository private, and `false` makes it public. # @option options [String] :has_issues `true` enables issues for this repo, `false` disables issues. # @option options [String] :has_wiki `true` enables wiki for this repo, `false` disables wiki. # @option options [String] :has_downloads `true` enables downloads for this repo, `false` disables downloads. # @option options [String] :organization Short name for the org under which to create the repo. # @option options [Integer] :team_id The id of the team that will be granted access to this repository. This is only valid when creating a repo in an organization. # @option options [Boolean] :auto_init `true` to create an initial commit with empty README. Default is `false`. # @option options [String] :gitignore_template Desired language or platform .gitignore template to apply. Ignored if auto_init parameter is not provided. # @return [Sawyer::Resource] Repository info for the new repository # @see https://developer.github.com/v3/repos/#create def create_repository(name, options = {}) organization = options.delete :organization options.merge! :name => name if organization.nil? post 'user/repos', options else post "orgs/#{organization}/repos", options end end alias :create_repo :create_repository alias :create :create_repository # Delete repository # # Note: If OAuth is used, 'delete_repo' scope is required # # @see https://developer.github.com/v3/repos/#delete-a-repository # @param repo [Integer, String, Hash, Repository] A GitHub repository # @return [Boolean] `true` if repository was deleted def delete_repository(repo, options = {}) boolean_from_response :delete, Repository.path(repo), options end alias :delete_repo :delete_repository # Hide a public repository # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @return [Sawyer::Resource] Updated repository info def set_private(repo, options = {}) # GitHub Api for setting private updated to use private attr, rather than public update_repository repo, options.merge({ :private => true }) end # Unhide a private repository # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @return [Sawyer::Resource] Updated repository info def set_public(repo, options = {}) # GitHub Api for setting private updated to use private attr, rather than public update_repository repo, options.merge({ :private => false }) end # Get deploy keys on a repo # # Requires authenticated client. # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @return [Array] Array of hashes representing deploy keys. # @see https://developer.github.com/v3/repos/keys/#list # @example # @client.deploy_keys('octokit/octokit.rb') # @example # @client.list_deploy_keys('octokit/octokit.rb') def deploy_keys(repo, options = {}) paginate "#{Repository.path repo}/keys", options end alias :list_deploy_keys :deploy_keys # Get a single deploy key for a repo # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param id [Integer] Deploy key ID. # @return [Sawyer::Resource] Deploy key. # @see https://developer.github.com/v3/repos/keys/#get # @example # @client.deploy_key('octokit/octokit.rb', 8675309) def deploy_key(repo, id, options={}) get "#{Repository.path repo}/keys/#{id}", options end # Add deploy key to a repo # # Requires authenticated client. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param title [String] Title reference for the deploy key. # @param key [String] Public key. # @return [Sawyer::Resource] Hash representing newly added key. # @see https://developer.github.com/v3/repos/keys/#create # @example # @client.add_deploy_key('octokit/octokit.rb', 'Staging server', 'ssh-rsa AAA...') def add_deploy_key(repo, title, key, options = {}) post "#{Repository.path repo}/keys", options.merge(:title => title, :key => key) end # Edit a deploy key # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param id [Integer] Deploy key ID. # @param options [Hash] Attributes to edit. # @option title [String] Key title. # @option key [String] Public key. # @return [Sawyer::Resource] Updated deploy key. # @deprecated This method is no longer supported in the API # @see https://developer.github.com/changes/2014-02-24-finer-grained-scopes-for-ssh-keys/ # @see https://developer.github.com/v3/repos/keys/#edit # @example Update the key for a deploy key. # @client.edit_deploy_key('octokit/octokit.rb', 8675309, :key => 'ssh-rsa BBB...') # @example # @client.update_deploy_key('octokit/octokit.rb', 8675309, :title => 'Uber', :key => 'ssh-rsa BBB...')) def edit_deploy_key(repo, id, options) patch "#{Repository.path repo}/keys/#{id}", options end alias :update_deploy_key :edit_deploy_key # Remove deploy key from a repo # # Requires authenticated client. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param id [Integer] Id of the deploy key to remove. # @return [Boolean] True if key removed, false otherwise. # @see https://developer.github.com/v3/repos/keys/#delete # @example # @client.remove_deploy_key('octokit/octokit.rb', 100000) def remove_deploy_key(repo, id, options = {}) boolean_from_response :delete, "#{Repository.path repo}/keys/#{id}", options end # List collaborators # # Requires authenticated client for private repos. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @return [Array] Array of hashes representing collaborating users. # @see https://developer.github.com/v3/repos/collaborators/#list # @example # Octokit.collaborators('octokit/octokit.rb') # @example # Octokit.collabs('octokit/octokit.rb') # @example # @client.collabs('octokit/octokit.rb') def collaborators(repo, options = {}) paginate "#{Repository.path repo}/collaborators", options end alias :collabs :collaborators # Add collaborator to repo # # Requires authenticated client. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param collaborator [String] Collaborator GitHub username to add. # @return [Boolean] True if collaborator added, false otherwise. # @see https://developer.github.com/v3/repos/collaborators/#add-collaborator # @example # @client.add_collaborator('octokit/octokit.rb', 'holman') # @example # @client.add_collab('octokit/octokit.rb', 'holman') def add_collaborator(repo, collaborator, options = {}) boolean_from_response :put, "#{Repository.path repo}/collaborators/#{collaborator}", options end alias :add_collab :add_collaborator # Remove collaborator from repo. # # Requires authenticated client. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param collaborator [String] Collaborator GitHub username to remove. # @return [Boolean] True if collaborator removed, false otherwise. # @see https://developer.github.com/v3/repos/collaborators/#remove-collaborator # @example # @client.remove_collaborator('octokit/octokit.rb', 'holman') # @example # @client.remove_collab('octokit/octokit.rb', 'holman') def remove_collaborator(repo, collaborator, options = {}) boolean_from_response :delete, "#{Repository.path repo}/collaborators/#{collaborator}", options end alias :remove_collab :remove_collaborator # Checks if a user is a collaborator for a repo. # # Requires authenticated client. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param collaborator [String] Collaborator GitHub username to check. # @return [Boolean] True if user is a collaborator, false otherwise. # @see https://developer.github.com/v3/repos/collaborators/#get # @example # @client.collaborator?('octokit/octokit.rb', 'holman') def collaborator?(repo, collaborator, options={}) boolean_from_response :get, "#{Repository.path repo}/collaborators/#{collaborator}", options end # List teams for a repo # # Requires authenticated client that is an owner or collaborator of the repo. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @return [Array] Array of hashes representing teams. # @see https://developer.github.com/v3/repos/#list-teams # @example # @client.repository_teams('octokit/pengwynn') # @example # @client.repo_teams('octokit/pengwynn') # @example # @client.teams('octokit/pengwynn') def repository_teams(repo, options = {}) paginate "#{Repository.path repo}/teams", options end alias :repo_teams :repository_teams alias :teams :repository_teams # List contributors to a repo # # Requires authenticated client for private repos. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param anon [Boolean] Set true to include anonymous contributors. # @return [Array] Array of hashes representing users. # @see https://developer.github.com/v3/repos/#list-contributors # @example # Octokit.contributors('octokit/octokit.rb', true) # @example # Octokit.contribs('octokit/octokit.rb') # @example # @client.contribs('octokit/octokit.rb') def contributors(repo, anon = nil, options = {}) options[:anon] = 1 if anon.to_s[/1|true/] paginate "#{Repository.path repo}/contributors", options end alias :contribs :contributors # List stargazers of a repo # # Requires authenticated client for private repos. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @return [Array] Array of hashes representing users. # @see https://developer.github.com/v3/activity/starring/#list-stargazers # @example # Octokit.stargazers('octokit/octokit.rb') # @example # @client.stargazers('octokit/octokit.rb') def stargazers(repo, options = {}) paginate "#{Repository.path repo}/stargazers", options end # @deprecated Use {#stargazers} instead # # List watchers of repo. # # Requires authenticated client for private repos. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @return [Array] Array of hashes representing users. # @see https://developer.github.com/v3/repos/watching/#list-watchers # @example # Octokit.watchers('octokit/octokit.rb') # @example # @client.watchers('octokit/octokit.rb') def watchers(repo, options = {}) paginate "#{Repository.path repo}/watchers", options end # List forks # # Requires authenticated client for private repos. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @return [Array] Array of hashes representing repos. # @see https://developer.github.com/v3/repos/forks/#list-forks # @example # Octokit.forks('octokit/octokit.rb') # @example # Octokit.network('octokit/octokit.rb') # @example # @client.forks('octokit/octokit.rb') def forks(repo, options = {}) paginate "#{Repository.path repo}/forks", options end alias :network :forks # List languages of code in the repo. # # Requires authenticated client for private repos. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @return [Array] Array of Hashes representing languages. # @see https://developer.github.com/v3/repos/#list-languages # @example # Octokit.languages('octokit/octokit.rb') # @example # @client.languages('octokit/octokit.rb') def languages(repo, options = {}) paginate "#{Repository.path repo}/languages", options end # List tags # # Requires authenticated client for private repos. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @return [Array] Array of hashes representing tags. # @see https://developer.github.com/v3/repos/#list-tags # @example # Octokit.tags('octokit/octokit.rb') # @example # @client.tags('octokit/octokit.rb') def tags(repo, options = {}) paginate "#{Repository.path repo}/tags", options end # List branches # # Requires authenticated client for private repos. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @return [Array] Array of hashes representing branches. # @see https://developer.github.com/v3/repos/#list-branches # @example # Octokit.branches('octokit/octokit.rb') # @example # @client.branches('octokit/octokit.rb') def branches(repo, options = {}) paginate "#{Repository.path repo}/branches", options end # Get a single branch from a repository # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param branch [String] Branch name # @return [Sawyer::Resource] The branch requested, if it exists # @see https://developer.github.com/v3/repos/#get-branch # @example Get branch 'master` from octokit/octokit.rb # Octokit.branch("octokit/octokit.rb", "master") def branch(repo, branch, options = {}) get "#{Repository.path repo}/branches/#{branch}", options end alias :get_branch :branch # List users available for assigning to issues. # # Requires authenticated client for private repos. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @return [Array] Array of hashes representing users. # @see https://developer.github.com/v3/issues/assignees/#list-assignees # @example # Octokit.repository_assignees('octokit/octokit.rb') # @example # Octokit.repo_assignees('octokit/octokit.rb') # @example # @client.repository_assignees('octokit/octokit.rb') def repository_assignees(repo, options = {}) paginate "#{Repository.path repo}/assignees", options end alias :repo_assignees :repository_assignees # Check to see if a particular user is an assignee for a repository. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param assignee [String] User login to check # @return [Boolean] True if assignable on project, false otherwise. # @see https://developer.github.com/v3/issues/assignees/#check-assignee # @example # Octokit.check_assignee('octokit/octokit.rb', 'andrew') def check_assignee(repo, assignee, options = {}) boolean_from_response :get, "#{Repository.path repo}/assignees/#{assignee}", options end # List watchers subscribing to notifications for a repo # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @return [Array] Array of users watching. # @see https://developer.github.com/v3/activity/watching/#list-watchers # @example # @client.subscribers("octokit/octokit.rb") def subscribers(repo, options = {}) paginate "#{Repository.path repo}/subscribers", options end # Get a repository subscription # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @return [Sawyer::Resource] Repository subscription. # @see https://developer.github.com/v3/activity/watching/#get-a-repository-subscription # @example # @client.subscription("octokit/octokit.rb") def subscription(repo, options = {}) get "#{Repository.path repo}/subscription", options end # Update repository subscription # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param options [Hash] # # @option options [Boolean] :subscribed Determines if notifications # should be received from this repository. # @option options [Boolean] :ignored Deterimines if all notifications # should be blocked from this repository. # @return [Sawyer::Resource] Updated repository subscription. # @see https://developer.github.com/v3/activity/watching/#set-a-repository-subscription # @example Subscribe to notifications for a repository # @client.update_subscription("octokit/octokit.rb", {subscribed: true}) def update_subscription(repo, options = {}) put "#{Repository.path repo}/subscription", options end # Delete a repository subscription # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @return [Boolean] True if subscription deleted, false otherwise. # @see https://developer.github.com/v3/activity/watching/#delete-a-repository-subscription # # @example # @client.delete_subscription("octokit/octokit.rb") def delete_subscription(repo, options = {}) boolean_from_response :delete, "#{Repository.path repo}/subscription", options end end end end octokit-3.8.0/lib/octokit/client/emojis.rb0000644000004100000410000000062312511016543020540 0ustar www-datawww-datamodule Octokit class Client # Methods for the Emojis API module Emojis # List all emojis used on GitHub # # @return [Sawyer::Resource] A list of all emojis on GitHub # @see https://developer.github.com/v3/emojis/#emojis # @example List all emojis # Octokit.emojis def emojis(options = {}) get "emojis", options end end end end octokit-3.8.0/lib/octokit/client/stats.rb0000644000004100000410000000720312511016543020411 0ustar www-datawww-datamodule Octokit class Client # Methods for the Repository Statistics API # # @see https://developer.github.com/v3/repos/statistics/ module Stats # Get contributors list with additions, deletions, and commit counts # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @return [Array] Array of contributor stats # @see https://developer.github.com/v3/repos/statistics/#contributors # @example Get contributor stats for octokit # @client.contributors_stats('octokit/octokit.rb') def contributors_stats(repo, options = {}) get_stats(repo, "contributors", options) end alias :contributor_stats :contributors_stats # Get the last year of commit activity data # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @return [Array] The last year of commit activity grouped by # week. The days array is a group of commits per day, starting on Sunday. # @see https://developer.github.com/v3/repos/statistics/#get-the-last-year-of-commit-activity-data # @example Get commit activity for octokit # @client.commit_activity_stats('octokit/octokit.rb') def commit_activity_stats(repo, options = {}) get_stats(repo, "commit_activity", options) end # Get the number of additions and deletions per week # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @return [Array] Weekly aggregate of the number of additions # and deletions pushed to a repository. # @see https://developer.github.com/v3/repos/statistics/#code-frequency # @example Get code frequency stats for octokit # @client.code_frequency_stats('octokit/octokit.rb') def code_frequency_stats(repo, options = {}) get_stats(repo, "code_frequency", options) end # Get the weekly commit count for the repo owner and everyone else # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @return [Sawyer::Resource] Total commit counts for the owner and total commit # counts in all. all is everyone combined, including the owner in the last # 52 weeks. If you’d like to get the commit counts for non-owners, you can # subtract all from owner. # @see https://developer.github.com/v3/repos/statistics/#participation # @example Get weekly commit counts for octokit # @client.participation_stats("octokit/octokit.rb") def participation_stats(repo, options = {}) get_stats(repo, "participation", options) end # Get the number of commits per hour in each day # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @return [Array] Arrays containing the day number, hour number, and # number of commits # @see https://developer.github.com/v3/repos/statistics/#punch-card # @example Get octokit punch card # @octokit.punch_card_stats def punch_card_stats(repo, options = {}) get_stats(repo, "punch_card", options) end alias :punch_card :punch_card_stats private # @private Get stats for a repository # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param metric [String] The metrics you are looking for # @return [Array] Magical unicorn stats def get_stats(repo, metric, options = {}) data = get("#{Repository.path repo}/stats/#{metric}", options) last_response.status == 202 ? nil : data end end end end octokit-3.8.0/lib/octokit/client/events.rb0000644000004100000410000001502612511016543020561 0ustar www-datawww-datamodule Octokit class Client # Method for the Events API # # @see https://developer.github.com/v3/activity/events/ # @see https://developer.github.com/v3/issues/events/ module Events # List all public events for GitHub # # @return [Array] A list of all public events from GitHub # @see https://developer.github.com/v3/activity/events/#list-public-events # @example List all pubilc events # Octokit.public_events def public_events(options = {}) paginate "events", options end # List all user events # # @param user [Integer, String] GitHub user login or id. # @return [Array] A list of all user events # @see https://developer.github.com/v3/activity/events/#list-events-performed-by-a-user # @example List all user events # Octokit.user_events("sferik") def user_events(user, options = {}) paginate "#{User.path user}/events", options end # List public user events # # @param user [Integer, String] GitHub user login or id # @return [Array] A list of public user events # @see https://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user # @example List public user events # Octokit.user_events("sferik") def user_public_events(user, options = {}) paginate "#{User.path user}/events/public", options end # List events that a user has received # # @param user [Integer, String] GitHub user login or id # @return [Array] A list of all user received events # @see https://developer.github.com/v3/activity/events/#list-events-that-a-user-has-received # @example List all user received events # Octokit.received_events("sferik") def received_events(user, options = {}) paginate "#{User.path user}/received_events", options end # List public events a user has received # # @param user [Integer, String] GitHub user login or id # @return [Array] A list of public user received events # @see https://developer.github.com/v3/activity/events/#list-public-events-that-a-user-has-received # @example List public user received events # Octokit.received_public_events("sferik") def received_public_events(user, options = {}) paginate "#{User.path user}/received_events/public", options end # List events for a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @return [Array] A list of events for a repository # @see https://developer.github.com/v3/activity/events/#list-repository-events # @example List events for a repository # Octokit.repository_events("sferik/rails_admin") def repository_events(repo, options = {}) paginate "#{Repository.path repo}/events", options end # List public events for a repository's network # # @param repo [String, Repository, Hash] A GitHub repository # @return [Array] A list of events for a repository's network # @see https://developer.github.com/v3/activity/events/#list-public-events-for-a-network-of-repositories # @example List events for a repository's network # Octokit.repository_network_events("sferik/rails_admin") def repository_network_events(repo, options = {}) paginate "networks/#{Repository.new(repo)}/events", options end # List all events for an organization # # Requires authenticated client. # # @param org [String] Organization GitHub handle # @return [Array] List of all events from a GitHub organization # @see https://developer.github.com/v3/activity/events/#list-events-for-an-organization # @example List events for the lostisland organization # @client.organization_events("lostisland") def organization_events(org, options = {}) paginate "users/#{login}/events/orgs/#{org}", options end # List an organization's public events # # @param org [String, Integer] Organization GitHub login or id. # @return [Array] List of public events from a GitHub organization # @see https://developer.github.com/v3/activity/events/#list-public-events-for-an-organization # @example List public events for GitHub # Octokit.organization_public_events("GitHub") def organization_public_events(org, options = {}) paginate "#{Organization.path org}/events", options end # Get all Issue Events for a given Repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository # # @return [Array] Array of all Issue Events for this Repository # @see https://developer.github.com/v3/issues/events/#list-events-for-a-repository # @see https://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository # @example Get all Issue Events for Octokit # Octokit.repository_issue_events("octokit/octokit.rb") def repository_issue_events(repo, options = {}) paginate "#{Repository.path repo}/issues/events", options end alias :repo_issue_events :repository_issue_events # List events for an Issue # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param number [Integer] Issue number # # @return [Array] Array of events for that issue # @see https://developer.github.com/v3/issues/events/#list-events-for-an-issue # @example List all issues events for issue #38 on octokit/octokit.rb # Octokit.issue_events("octokit/octokit.rb", 38) def issue_events(repo, number, options = {}) paginate "#{Repository.path repo}/issues/#{number}/events", options end # Get information on a single Issue Event # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param number [Integer] Event number # # @return [Sawyer::Resource] A single Event for an Issue # @see https://developer.github.com/v3/issues/events/#get-a-single-event # @example Get Event information for ID 3094334 (a pull request was closed) # Octokit.issue_event("octokit/octokit.rb", 3094334) def issue_event(repo, number, options = {}) paginate "#{Repository.path repo}/issues/events/#{number}", options end end end end octokit-3.8.0/lib/octokit/client/users.rb0000644000004100000410000003231312511016543020414 0ustar www-datawww-datamodule Octokit class Client # Methods for the Users API # # @see https://developer.github.com/v3/users/ module Users # List all GitHub users # # This provides a dump of every user, in the order that they signed up # for GitHub. # # @param options [Hash] Optional options. # @option options [Integer] :since The integer ID of the last User that # you’ve seen. # # @see https://developer.github.com/v3/users/#get-all-users # # @return [Array] List of GitHub users. def all_users(options = {}) paginate "users", options end # Get a single user # # @param user [Integer, String] GitHub user login or id. # @return [Sawyer::Resource] # @see https://developer.github.com/v3/users/#get-a-single-user # @see https://developer.github.com/v3/users/#get-the-authenticated-user # @example # Octokit.user("sferik") def user(user=nil, options = {}) get User.path(user), options end # Retrieve the access_token. # # @param code [String] Authorization code generated by GitHub. # @param app_id [String] Client Id we received when our application was registered with GitHub. Defaults to client_id. # @param app_secret [String] Client Secret we received when our application was registered with GitHub. Defaults to client_secret. # @return [Sawyer::Resource] Hash holding the access token. # @see https://developer.github.com/v3/oauth/#web-application-flow # @example # Octokit.exchange_code_for_token('aaaa', 'xxxx', 'yyyy', {:accept => 'application/json'}) def exchange_code_for_token(code, app_id = client_id, app_secret = client_secret, options = {}) options.merge!({ :code => code, :client_id => app_id, :client_secret => app_secret, :headers => { :content_type => 'application/json', :accept => 'application/json' } }) post "#{web_endpoint}login/oauth/access_token", options end # Validate user username and password # # @param options [Hash] User credentials # @option options [String] :login GitHub login # @option options [String] :password GitHub password # @return [Boolean] True if credentials are valid def validate_credentials(options = {}) !self.class.new(options).user.nil? rescue Octokit::Unauthorized false end # Update the authenticated user # # @param options [Hash] A customizable set of options. # @option options [String] :name # @option options [String] :email Publically visible email address. # @option options [String] :blog # @option options [String] :company # @option options [String] :location # @option options [Boolean] :hireable # @option options [String] :bio # @return [Sawyer::Resource] # @see https://developer.github.com/v3/users/#update-the-authenticated-user # @example # Octokit.update_user(:name => "Erik Michaels-Ober", :email => "sferik@gmail.com", :company => "Code for America", :location => "San Francisco", :hireable => false) def update_user(options) patch "user", options end # Get a user's followers. # # @param user [Integer, String] GitHub user login or id of the user whose # list of followers you are getting. # @return [Array] Array of hashes representing users # followers. # @see https://developer.github.com/v3/users/followers/#list-followers-of-a-user # @example # Octokit.followers('pengwynn') def followers(user=login, options = {}) paginate "#{User.path user}/followers", options end # Get list of users a user is following. # # @param user [Intger, String] GitHub user login or id of the user who you # are getting the list of the people they follow. # @return [Array] Array of hashes representing users a # user is following. # @see https://developer.github.com/v3/users/followers/#list-users-followed-by-another-user # @example # Octokit.following('pengwynn') def following(user=login, options = {}) paginate "#{User.path user}/following", options end # Check if you are following a user. Alternatively, check if a given user # is following a target user. # # Requries an authenticated client. # # @overload follows?(target) # @param target [String] GitHub login of the user that you want to # check if you are following. # @overload follows?(user, target) # @param user [Integer, String] GitHub user login or id of first user # @param target [String] GitHub login of the target user # @return [Boolean] True following target user, false otherwise. # @see https://developer.github.com/v3/users/followers/#check-if-you-are-following-a-user # @see https://developer.github.com/v3/users/followers/#check-if-one-user-follows-another # @example # @client.follows?('pengwynn') # @example # @client.follows?('catsby', 'pengwynn') def follows?(*args) target = args.pop user = args.first boolean_from_response :get, "#{User.path user}/following/#{target}" end # Follow a user. # # Requires authenticatied client. # # @param user [String] Username of the user to follow. # @return [Boolean] True if follow was successful, false otherwise. # @see https://developer.github.com/v3/users/followers/#follow-a-user # @example # @client.follow('holman') def follow(user, options = {}) boolean_from_response :put, "user/following/#{user}", options end # Unfollow a user. # # Requires authenticated client. # # @param user [String] Username of the user to unfollow. # @return [Boolean] True if unfollow was successful, false otherwise. # @see https://developer.github.com/v3/users/followers/#unfollow-a-user # @example # @client.unfollow('holman') def unfollow(user, options = {}) boolean_from_response :delete, "user/following/#{user}", options end # Get list of repos starred by a user. # # @param user [Integer, String] GitHub user login of the user to get the # list of their starred repositories. # @param options [Hash] Optional options # @option options [String] :sort (created) Sort: created or updated. # @option options [String] :direction (desc) Direction: asc or desc. # @return [Array] Array of hashes representing repositories starred by user. # @see https://developer.github.com/v3/activity/starring/#list-repositories-being-starred # @example # Octokit.starred('pengwynn') def starred(user=login, options = {}) paginate user_path(user, 'starred'), options end # Check if you are starring a repo. # # Requires authenticated client. # # @param repo [String, Hash, Repository] A GitHub repository # @return [Boolean] True if you are following the repo, false otherwise. # @see https://developer.github.com/v3/activity/starring/#check-if-you-are-starring-a-repository # @example # @client.starred?('pengwynn/octokit') def starred?(repo, options = {}) boolean_from_response :get, "user/starred/#{Repository.new(repo)}", options end # Get a public key. # # Note, when using dot notation to retrieve the values, ruby will return # the hash key for the public keys value instead of the actual value, use # symbol or key string to retrieve the value. See example. # # Requires authenticated client. # # @param key_id [Integer] Key to retreive. # @return [Sawyer::Resource] Hash representing the key. # @see https://developer.github.com/v3/users/keys/#get-a-single-public-key # @example # @client.key(1) # @example Retrieve public key contents # public_key = @client.key(1) # public_key.key # # => Error # # public_key[:key] # # => "ssh-rsa AAA..." # # public_key['key'] # # => "ssh-rsa AAA..." def key(key_id, options = {}) get "user/keys/#{key_id}", options end # Get list of public keys for user. # # Requires authenticated client. # # @return [Array] Array of hashes representing public keys. # @see https://developer.github.com/v3/users/keys/#list-your-public-keys # @example # @client.keys def keys(options = {}) paginate "user/keys", options end # Get list of public keys for user. # # @param user [Integer, String] GitHub user login or id. # @return [Array] Array of hashes representing public keys. # @see https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user # @example # @client.user_keys('pengwynn') def user_keys(user, options = {}) # TODO: Roll this into .keys paginate "#{User.path user}/keys", options end # Add public key to user account. # # Requires authenticated client. # # @param title [String] Title to give reference to the public key. # @param key [String] Public key. # @return [Sawyer::Resource] Hash representing the newly added public key. # @see https://developer.github.com/v3/users/keys/#create-a-public-key # @example # @client.add_key('Personal projects key', 'ssh-rsa AAA...') def add_key(title, key, options = {}) post "user/keys", options.merge({:title => title, :key => key}) end # Update a public key # # Requires authenticated client # # @param key_id [Integer] Id of key to update. # @param options [Hash] Hash containing attributes to update. # @option options [String] :title # @option options [String] :key # @return [Sawyer::Resource] Hash representing the updated public key. # # @deprecated This method is no longer supported in the API # @see https://developer.github.com/v3/users/keys/#update-a-public-key # @see https://developer.github.com/changes/2014-02-24-finer-grained-scopes-for-ssh-keys/ # @example # @client.update_key(1, :title => 'new title', :key => "ssh-rsa BBB") def update_key(key_id, options = {}) patch "user/keys/#{key_id}", options end # Remove a public key from user account. # # Requires authenticated client. # # @param id [String] Id of the public key to remove. # @return [Boolean] True if removal was successful, false otherwise. # @see https://developer.github.com/v3/users/keys/#delete-a-public-key # @example # @client.remove_key(1) def remove_key(id, options = {}) boolean_from_response :delete, "user/keys/#{id}", options end # List email addresses for a user. # # Requires authenticated client. # # @return [Array] Array of email addresses. # @see https://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user # @example # @client.emails def emails(options = {}) paginate "user/emails", options end # Add email address to user. # # Requires authenticated client. # # @param email [String] Email address to add to the user. # @return [Array] Array of all email addresses of the user. # @see https://developer.github.com/v3/users/emails/#add-email-addresses # @example # @client.add_email('new_email@user.com') def add_email(email, options = {}) email = Array(email) post "user/emails", email end # Remove email from user. # # Requires authenticated client. # # @param email [String] Email address to remove. # @return [Array] Array of all email addresses of the user. # @see https://developer.github.com/v3/users/emails/#delete-email-addresses # @example # @client.remove_email('old_email@user.com') def remove_email(email) email = Array(email) boolean_from_response :delete, "user/emails", email end # List repositories being watched by a user. # # @param user [Integer, String] GitHub user login or id. # @return [Array] Array of repositories. # @see https://developer.github.com/v3/activity/watching/#list-repositories-being-watched # @example # @client.subscriptions("pengwynn") def subscriptions(user=login, options = {}) paginate user_path(user, 'subscriptions'), options end alias :watched :subscriptions end private # convenience method for constructing a user specific path, if the user is logged in def user_path(user, path) if user == login && user_authenticated? "user/#{path}" else "#{User.path user}/#{path}" end end end end octokit-3.8.0/lib/octokit/client/hooks.rb0000644000004100000410000002656112511016543020406 0ustar www-datawww-datamodule Octokit class Client # Methods for the Hooks API module Hooks ORG_HOOKS_PREVIEW_MEDIA_TYPE = "application/vnd.github.sersi-preview+json".freeze # List all Service Hooks supported by GitHub # # @return [Sawyer::Resource] A list of all hooks on GitHub # @see https://developer.github.com/v3/repos/hooks/#services # @example List all hooks # Octokit.available_hooks def available_hooks(options = {}) get "hooks", options end # List repo hooks # # Requires authenticated client. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @return [Array] Array of hashes representing hooks. # @see https://developer.github.com/v3/repos/hooks/#list-hooks # @example # @client.hooks('octokit/octokit.rb') def hooks(repo, options = {}) paginate "#{Repository.path repo}/hooks", options end # Get single hook # # Requires authenticated client. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param id [Integer] Id of the hook to get. # @return [Sawyer::Resource] Hash representing hook. # @see https://developer.github.com/v3/repos/hooks/#get-single-hook # @example # @client.hook('octokit/octokit.rb', 100000) def hook(repo, id, options = {}) get "#{Repository.path repo}/hooks/#{id}", options end # Create a hook # # Requires authenticated client. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param name [String] The name of the service that is being called. See # {https://api.github.com/hooks Hooks} for the possible names. # @param config [Hash] A Hash containing key/value pairs to provide # settings for this hook. These settings vary between the services and # are defined in the {https://github.com/github/github-services github-services} repo. # @option options [Array] :events ('["push"]') Determines what # events the hook is triggered for. # @option options [Boolean] :active Determines whether the hook is # actually triggered on pushes. # @return [Sawyer::Resource] Hook info for the new hook # @see https://api.github.com/hooks # @see https://github.com/github/github-services # @see https://developer.github.com/v3/repos/hooks/#create-a-hook # @example # @client.create_hook( # 'octokit/octokit.rb', # 'web', # { # :url => 'http://something.com/webhook', # :content_type => 'json' # }, # { # :events => ['push', 'pull_request'], # :active => true # } # ) def create_hook(repo, name, config, options = {}) options = {:name => name, :config => config, :events => ["push"], :active => true}.merge(options) post "#{Repository.path repo}/hooks", options end # Edit a hook # # Requires authenticated client. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param id [Integer] Id of the hook being updated. # @param name [String] The name of the service that is being called. See # {https://api.github.com/hooks Hooks} for the possible names. # @param config [Hash] A Hash containing key/value pairs to provide # settings for this hook. These settings vary between the services and # are defined in the {https://github.com/github/github-services github-services} repo. # @option options [Array] :events ('["push"]') Determines what # events the hook is triggered for. # @option options [Array] :add_events Determines a list of events # to be added to the list of events that the Hook triggers for. # @option options [Array] :remove_events Determines a list of events # to be removed from the list of events that the Hook triggers for. # @option options [Boolean] :active Determines whether the hook is # actually triggered on pushes. # @return [Sawyer::Resource] Hook info for the updated hook # @see https://api.github.com/hooks # @see https://github.com/github/github-services # @see https://developer.github.com/v3/repos/hooks/#edit-a-hook # @example # @client.edit_hook( # 'octokit/octokit.rb', # 100000, # 'web', # { # :url => 'http://something.com/webhook', # :content_type => 'json' # }, # { # :add_events => ['status'], # :remove_events => ['pull_request'], # :active => true # } # ) def edit_hook(repo, id, name, config, options = {}) options = {:name => name, :config => config, :events => ["push"], :active => true}.merge(options) patch "#{Repository.path repo}/hooks/#{id}", options end # Delete hook # # Requires authenticated client. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param id [Integer] Id of the hook to remove. # @return [Boolean] True if hook removed, false otherwise. # @see https://developer.github.com/v3/repos/hooks/#delete-a-hook # @example # @client.remove_hook('octokit/octokit.rb', 1000000) def remove_hook(repo, id, options = {}) boolean_from_response :delete, "#{Repository.path repo}/hooks/#{id}", options end # Test hook # # Requires authenticated client. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param id [Integer] Id of the hook to test. # @return [Boolean] Success # @see https://developer.github.com/v3/repos/hooks/#test-a-push-hook # @example # @client.test_hook('octokit/octokit.rb', 1000000) def test_hook(repo, id, options = {}) boolean_from_response :post, "#{Repository.path repo}/hooks/#{id}/tests", options end # List org hooks # # Requires client authenticated as admin for the org. # # @param org [String] A GitHub organization login. # @return [Array] Array of hashes representing hooks. # @see https://developer.github.com/v3/orgs/hooks/#list-hooks # @example # @client.org_hooks('octokit') def org_hooks(org, options = {}) options = ensure_org_hooks_api_media_type(options) paginate "orgs/#{org}/hooks", options end alias :list_org_hooks :org_hooks # Get an org hook # # Requires client authenticated as admin for the org. # # @param org [String] A GitHub organization login. # @param id [Integer] Id of the hook to get. # @return [Sawyer::Resource] Hash representing hook. # @see https://developer.github.com/v3/orgs/hooks/#get-single-hook # @example # @client.org_hook('octokit', 123) def org_hook(org, id, options = {}) options = ensure_org_hooks_api_media_type(options) get "orgs/#{org}/hooks/#{id}", options end # Create an org hook # # Requires client authenticated as admin for the org. # # @param org [String] A GitHub organization login. # @param config [Hash] A Hash containing key/value pairs to provide # settings for this hook. # @option options [Array] :events ('["push"]') Determines what # events the hook is triggered for. # @option options [Boolean] :active Determines whether the hook is # actually triggered on pushes. # @return [Sawyer::Resource] Hook info for the new hook # @see https://api.github.com/hooks # @see https://developer.github.com/v3/orgs/hooks/#create-a-hook # @example # @client.create_org_hook( # 'octokit', # { # :url => 'http://something.com/webhook', # :content_type => 'json' # }, # { # :events => ['push', 'pull_request'], # :active => true # } # ) def create_org_hook(org, config, options = {}) options = ensure_org_hooks_api_media_type(options) options = { :name => "web", :config => config }.merge(options) post "orgs/#{org}/hooks", options end # Update an org hook # # Requires client authenticated as admin for the org. # # @param org [String] A GitHub organization login. # @param id [Integer] Id of the hook to update. # @param config [Hash] A Hash containing key/value pairs to provide # settings for this hook. # @option options [Array] :events ('["push"]') Determines what # events the hook is triggered for. # @option options [Boolean] :active Determines whether the hook is # actually triggered on pushes. # @return [Sawyer::Resource] Hook info for the new hook # @see https://api.github.com/hooks # @see https://developer.github.com/v3/orgs/hooks/#edit-a-hook # @example # @client.edit_org_hook( # 'octokit', # 123, # { # :url => 'http://something.com/webhook', # :content_type => 'json' # }, # { # :events => ['push', 'pull_request'], # :active => true # } # ) def edit_org_hook(org, id, config, options = {}) options = ensure_org_hooks_api_media_type(options) options = { :config => config }.merge(options) patch "orgs/#{org}/hooks/#{id}", options end alias :update_org_hook :edit_org_hook # Ping org hook # # Requires client authenticated as admin for the org. # # @param org [String] A GitHub organization login. # @param id [Integer] Id of the hook to update. # @return [Boolean] Success # @see https://developer.github.com/v3/orgs/hooks/#ping-a-hook # @example # @client.ping_org_hook('octokit', 1000000) def ping_org_hook(org, id, options = {}) options = ensure_org_hooks_api_media_type(options) boolean_from_response :post, "orgs/#{org}/hooks/#{id}/pings", options end # Remove org hook # # Requires client authenticated as admin for the org. # # @param org [String] A GitHub organization login. # @param id [Integer] Id of the hook to update. # @return [Boolean] True if hook removed, false otherwise. # @see https://developer.github.com/v3/orgs/hooks/#delete-a-hook # @example # @client.remove_org_hook('octokit', 1000000) def remove_org_hook(org, id, options = {}) options = ensure_org_hooks_api_media_type(options) boolean_from_response :delete, "orgs/#{org}/hooks/#{id}", options end private def ensure_org_hooks_api_media_type(options = {}) if options[:accept].nil? options[:accept] = ORG_HOOKS_PREVIEW_MEDIA_TYPE warn_org_hooks_preview end options end def warn_org_hooks_preview octokit_warn <<-EOS WARNING: The preview version of the Org Hooks API is not yet suitable for production use. You can avoid this message by supplying an appropriate media type in the 'Accept' request header. See the blog post for details: http://git.io/uucWqg EOS end end end end octokit-3.8.0/lib/octokit/client/search.rb0000644000004100000410000000555712511016543020532 0ustar www-datawww-datamodule Octokit class Client # Methods for the Search API # # @see https://developer.github.com/v3/search/ module Search # Search code # # @param query [String] Search term and qualifiers # @param options [Hash] Sort and pagination options # @option options [String] :sort Sort field # @option options [String] :order Sort order (asc or desc) # @option options [Fixnum] :page Page of paginated results # @option options [Fixnum] :per_page Number of items per page # @return [Sawyer::Resource] Search results object # @see https://developer.github.com/v3/search/#search-code def search_code(query, options = {}) search "search/code", query, options end # Search issues # # @param query [String] Search term and qualifiers # @param options [Hash] Sort and pagination options # @option options [String] :sort Sort field # @option options [String] :order Sort order (asc or desc) # @option options [Fixnum] :page Page of paginated results # @option options [Fixnum] :per_page Number of items per page # @return [Sawyer::Resource] Search results object # @see https://developer.github.com/v3/search/#search-issues def search_issues(query, options = {}) search "search/issues", query, options end # Search repositories # # @param query [String] Search term and qualifiers # @param options [Hash] Sort and pagination options # @option options [String] :sort Sort field # @option options [String] :order Sort order (asc or desc) # @option options [Fixnum] :page Page of paginated results # @option options [Fixnum] :per_page Number of items per page # @return [Sawyer::Resource] Search results object # @see https://developer.github.com/v3/search/#search-repositories def search_repositories(query, options = {}) search "search/repositories", query, options end alias :search_repos :search_repositories # Search users # # @param query [String] Search term and qualifiers # @param options [Hash] Sort and pagination options # @option options [String] :sort Sort field # @option options [String] :order Sort order (asc or desc) # @option options [Fixnum] :page Page of paginated results # @option options [Fixnum] :per_page Number of items per page # @return [Sawyer::Resource] Search results object # @see https://developer.github.com/v3/search/#search-users def search_users(query, options = {}) search "search/users", query, options end private def search(path, query, options = {}) opts = options.merge(:q => query) paginate(path, opts) do |data, last_response| data.items.concat last_response.data.items end end end end end octokit-3.8.0/lib/octokit/client/pull_requests.rb0000644000004100000410000003517112511016543022167 0ustar www-datawww-datamodule Octokit class Client # Methods for the Pull Requests API # # @see https://developer.github.com/v3/pulls/ module PullRequests # List pull requests for a repository # # @overload pull_requests(repo, options) # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param options [Hash] Method options # @option options [String] :state `open` or `closed`. # @overload pull_requests(repo, state, options) # @deprecated # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param state [String] `open` or `closed`. # @param options [Hash] Method options # @return [Array] Array of pulls # @see https://developer.github.com/v3/pulls/#list-pull-requests # @example # Octokit.pull_requests('rails/rails', :state => 'closed') def pull_requests(*args) arguments = Arguments.new(args) opts = arguments.options repo = arguments.shift if state = arguments.shift octokit_warn "DEPRECATED: Client#pull_requests: Passing state as positional argument is deprecated. Please use :state => '#{state}'" opts[:state] = state if state end paginate "#{Repository.path repo}/pulls", opts end alias :pulls :pull_requests # Get a pull request # # @see https://developer.github.com/v3/pulls/#get-a-single-pull-request # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param number [Integer] Number of the pull request to fetch # @return [Sawyer::Resource] Pull request info def pull_request(repo, number, options = {}) get "#{Repository.path repo}/pulls/#{number}", options end alias :pull :pull_request # Create a pull request # # @see https://developer.github.com/v3/pulls/#create-a-pull-request # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param base [String] The branch (or git ref) you want your changes # pulled into. This should be an existing branch on the current # repository. You cannot submit a pull request to one repo that requests # a merge to a base of another repo. # @param head [String] The branch (or git ref) where your changes are implemented. # @param title [String] Title for the pull request # @param body [String] The body for the pull request (optional). Supports GFM. # @return [Sawyer::Resource] The newly created pull request # @example # @client.create_pull_request("octokit/octokit.rb", "master", "feature-branch", # "Pull Request title", "Pull Request body") def create_pull_request(repo, base, head, title, body = nil, options = {}) pull = { :base => base, :head => head, :title => title, } pull[:body] = body unless body.nil? post "#{Repository.path repo}/pulls", options.merge(pull) end # Create a pull request from existing issue # # @see https://developer.github.com/v3/pulls/#alternative-input # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param base [String] The branch (or git ref) you want your changes # pulled into. This should be an existing branch on the current # repository. You cannot submit a pull request to one repo that requests # a merge to a base of another repo. # @param head [String] The branch (or git ref) where your changes are implemented. # @param issue [Integer] Number of Issue on which to base this pull request # @return [Sawyer::Resource] The newly created pull request def create_pull_request_for_issue(repo, base, head, issue, options = {}) pull = { :base => base, :head => head, :issue => issue } post "#{Repository.path repo}/pulls", options.merge(pull) end # Update a pull request # @overload update_pull_request(repo, id, title=nil, body=nil, state=nil, options = {}) # @deprecated # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param number [Integer] Number of pull request to update. # @param title [String] Title for the pull request. # @param body [String] Body content for pull request. Supports GFM. # @param state [String] State of the pull request. `open` or `closed`. # @overload update_pull_request(repo, id, options = {}) # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param number [Integer] Number of pull request to update. # @option options [String] :title Title for the pull request. # @option options [String] :body Body for the pull request. # @option options [String] :state State for the pull request. # @return [Sawyer::Resource] Hash representing updated pull request. # @see https://developer.github.com/v3/pulls/#update-a-pull-request # @example # @client.update_pull_request('octokit/octokit.rb', 67, 'new title', 'updated body', 'closed') # @example Passing nil for optional attributes to update specific attributes. # @client.update_pull_request('octokit/octokit.rb', 67, nil, nil, 'open') # @example Empty body by passing empty string # @client.update_pull_request('octokit/octokit.rb', 67, nil, '') def update_pull_request(*args) arguments = Octokit::Arguments.new(args) repo = arguments.shift number = arguments.shift patch "#{Repository.path repo}/pulls/#{number}", arguments.options end # Close a pull request # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param number [Integer] Number of pull request to update. # @return [Sawyer::Resource] Hash representing updated pull request. # @see https://developer.github.com/v3/pulls/#update-a-pull-request # @example # @client.close_pull_request('octokit/octokit.rb', 67) def close_pull_request(repo, number, options = {}) options.merge! :state => 'closed' update_pull_request(repo, number, options) end # List commits on a pull request # # @see https://developer.github.com/v3/pulls/#list-commits-on-a-pull-request # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param number [Integer] Number of pull request # @return [Array] List of commits def pull_request_commits(repo, number, options = {}) paginate "#{Repository.path repo}/pulls/#{number}/commits", options end alias :pull_commits :pull_request_commits # List pull request comments for a repository # # By default, Review Comments are ordered by ascending ID. # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @param options [Hash] Optional parameters # @option options [String] :sort created or updated # @option options [String] :direction asc or desc. Ignored without sort # parameter. # @option options [String] :since Timestamp in ISO 8601 # format: YYYY-MM-DDTHH:MM:SSZ # # @return [Array] List of pull request review comments. # # @see https://developer.github.com/v3/pulls/comments/#list-comments-in-a-repository # # @example Get the pull request review comments in the octokit repository # @client.issues_comments("octokit/octokit.rb") # # @example Get review comments, sort by updated asc since a time # @client.pull_requests_comments("octokit/octokit.rb", { # :sort => 'asc', # :direction => 'down', # :since => '2010-05-04T23:45:02Z' # }) def pull_requests_comments(repo, options = {}) paginate("#{Repository.path repo}/pulls/comments", options) end alias :pulls_comments :pull_requests_comments alias :reviews_comments :pull_requests_comments # List comments on a pull request # # @see https://developer.github.com/v3/pulls/comments/#list-comments-on-a-pull-request # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param number [Integer] Number of pull request # @return [Array] List of comments def pull_request_comments(repo, number, options = {}) # return the comments for a pull request paginate("#{Repository.path repo}/pulls/#{number}/comments", options) end alias :pull_comments :pull_request_comments alias :review_comments :pull_request_comments # Get a pull request comment # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param comment_id [Integer] Id of comment to get # @return [Sawyer::Resource] Hash representing the comment # @see https://developer.github.com/v3/pulls/comments/#get-a-single-comment # @example # @client.pull_request_comment("pengwynn/octkit", 1903950) def pull_request_comment(repo, comment_id, options = {}) get "#{Repository.path repo}/pulls/comments/#{comment_id}", options end alias :pull_comment :pull_request_comment alias :review_comment :pull_request_comment # Create a pull request comment # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param pull_id [Integer] Pull request id # @param body [String] Comment content # @param commit_id [String] Sha of the commit to comment on. # @param path [String] Relative path of the file to comment on. # @param position [Integer] Line index in the diff to comment on. # @return [Sawyer::Resource] Hash representing the new comment # @see https://developer.github.com/v3/pulls/comments/#create-a-comment # @example # @client.create_pull_request_comment("octokit/octokit.rb", 163, ":shipit:", # "2d3201e4440903d8b04a5487842053ca4883e5f0", "lib/octokit/request.rb", 47) def create_pull_request_comment(repo, pull_id, body, commit_id, path, position, options = {}) options.merge!({ :body => body, :commit_id => commit_id, :path => path, :position => position }) post "#{Repository.path repo}/pulls/#{pull_id}/comments", options end alias :create_pull_comment :create_pull_request_comment alias :create_view_comment :create_pull_request_comment # Create reply to a pull request comment # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param pull_id [Integer] Pull request id # @param body [String] Comment contents # @param comment_id [Integer] Comment id to reply to # @return [Sawyer::Resource] Hash representing new comment # @see https://developer.github.com/v3/pulls/comments/#create-a-comment # @example # @client.create_pull_request_comment_reply("octokit/octokit.rb", 1903950, "done.") def create_pull_request_comment_reply(repo, pull_id, body, comment_id, options = {}) options.merge!({ :body => body, :in_reply_to => comment_id }) post "#{Repository.path repo}/pulls/#{pull_id}/comments", options end alias :create_pull_reply :create_pull_request_comment_reply alias :create_review_reply :create_pull_request_comment_reply # Update pull request comment # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param comment_id [Integer] Id of the comment to update # @param body [String] Updated comment content # @return [Sawyer::Resource] Hash representing the updated comment # @see https://developer.github.com/v3/pulls/comments/#edit-a-comment # @example # @client.update_pull_request_comment("octokit/octokit.rb", 1903950, ":shipit:") def update_pull_request_comment(repo, comment_id, body, options = {}) options.merge! :body => body patch("#{Repository.path repo}/pulls/comments/#{comment_id}", options) end alias :update_pull_comment :update_pull_request_comment alias :update_review_comment :update_pull_request_comment # Delete pull request comment # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param comment_id [Integer] Id of the comment to delete # @return [Boolean] True if deleted, false otherwise # @see https://developer.github.com/v3/pulls/comments/#delete-a-comment # @example # @client.delete_pull_request_comment("octokit/octokit.rb", 1902707) def delete_pull_request_comment(repo, comment_id, options = {}) boolean_from_response(:delete, "#{Repository.path repo}/pulls/comments/#{comment_id}", options) end alias :delete_pull_comment :delete_pull_request_comment alias :delete_review_comment :delete_pull_request_comment # List files on a pull request # # @see https://developer.github.com/v3/pulls/#list-pull-requests-files # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param number [Integer] Number of pull request # @return [Array] List of files def pull_request_files(repo, number, options = {}) paginate "#{Repository.path repo}/pulls/#{number}/files", options end alias :pull_files :pull_request_files # Merge a pull request # # @see https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-buttontrade # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param number [Integer] Number of pull request # @param commit_message [String] Optional commit message for the merge commit # @return [Array] Merge commit info if successful def merge_pull_request(repo, number, commit_message='', options = {}) put "#{Repository.path repo}/pulls/#{number}/merge", options.merge({:commit_message => commit_message}) end # Check pull request merge status # # @see https://developer.github.com/v3/pulls/#get-if-a-pull-request-has-been-merged # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param number [Integer] Number of pull request # @return [Boolean] True if the pull request has been merged def pull_merged?(repo, number, options = {}) boolean_from_response :get, "#{Repository.path repo}/pulls/#{number}/merge", options end alias :pull_request_merged? :pull_merged? end end end octokit-3.8.0/lib/octokit/client/legacy_search.rb0000644000004100000410000000313712511016543022046 0ustar www-datawww-datamodule Octokit class Client # Methods for the Legacy Search API # # @see https://developer.github.com/v3/search/ module LegacySearch # Legacy repository search # # @see https://developer.github.com/v3/search/#search-repositories # @param q [String] Search keyword # @return [Array] List of repositories found def legacy_search_repositories(q, options = {}) get("legacy/repos/search/#{q}", options)['repositories'] end # Legacy search issues within a repository # # @param repo [String, Repository, Hash] A GitHub repository # @param search_term [String] The term to search for # @param state [String] :state (open) open or closed. # @return [Array] A list of issues matching the search term and state # @example Search for 'test' in the open issues for sferik/rails_admin # Octokit.search_issues("sferik/rails_admin", 'test', 'open') def legacy_search_issues(repo, search_term, state='open', options = {}) get("legacy/issues/search/#{Repository.new(repo)}/#{state}/#{search_term}", options)['issues'] end # Search for user. # # @param search [String] User to search for. # @return [Array] Array of hashes representing users. # @see https://developer.github.com/v3/search/#search-users # @example # Octokit.search_users('pengwynn') def legacy_search_users(search, options = {}) get("legacy/user/search/#{search}", options)['users'] end end end end octokit-3.8.0/lib/octokit/client/authorizations.rb0000644000004100000410000002647412511016543022351 0ustar www-datawww-datamodule Octokit class Client # Methods for the Authorizations API # # @see https://developer.github.com/v3/oauth_authorizations/#oauth-authorizations-api module Authorizations # List the authenticated user's authorizations # # API for users to manage their own tokens. # You can only access your own tokens, and only through # Basic Authentication. # # @return [Array] A list of authorizations for the authenticated user # @see https://developer.github.com/v3/oauth_authorizations/#list-your-authorizations # @example List authorizations for user ctshryock # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret') # client.authorizations def authorizations(options = {}) paginate 'authorizations', options end # Get a single authorization for the authenticated user. # # You can only access your own tokens, and only through # Basic Authentication. # # @return [Sawyer::Resource] A single authorization for the authenticated user # @see https://developer.github.com/v3/oauth_authorizations/#get-a-single-authorization # @example Show authorization for user ctshryock's Travis auth # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret') # client.authorization(999999) def authorization(number, options = {}) get "authorizations/#{number}", options end # Create an authorization for the authenticated user. # # You can create your own tokens, and only through # Basic Authentication. # # @param options [Hash] A customizable set of options. # @option options [Array] :scopes A list of scopes that this authorization is in. # @option options [String] :note A note to remind you what the OAuth token is for. # @option options [String] :note_url A URL to remind you what app the OAuth token is for. # @option options [Boolean] :idempotent If true, will return an existing authorization if one has already been created. # @option options [String] :client_id Client Id we received when our application was registered with GitHub. # @option options [String] :client_secret Client Secret we received when our application was registered with GitHub. # # @return [Sawyer::Resource] A single authorization for the authenticated user # @see https://developer.github.com/v3/oauth/#scopes Available scopes # @see https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization # @see https://developer.github.com/v3/oauth_authorizations/#get-or-create-an-authorization-for-a-specific-app # @example Create a new authorization for user ctshryock's project Zoidberg # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret') # client.create_authorization({:scopes => ["public_repo","gist"], :note => "Why not Zoidberg?", :note_url=> "https://en.wikipedia.org/wiki/Zoidberg"}) # @example Create a new OR return an existing authorization to be used by a specific client for user ctshryock's project Zoidberg # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret') # client.create_authorization({:idempotent => true, :client_id => 'xxxx', :client_secret => 'yyyy', :scopes => ["user"]}) def create_authorization(options = {}) # Techincally we can omit scopes as GitHub has a default, however the # API will reject us if we send a POST request with an empty body. if options.delete :idempotent client_id, client_secret = fetch_client_id_and_secret(options) raise ArgumentError.new("Client ID and Secret required for idempotent authorizations") unless client_id && client_secret put "authorizations/clients/#{client_id}", options.merge(:client_secret => client_secret) else post 'authorizations', options end end # Update an authorization for the authenticated user. # # You can update your own tokens, but only through # Basic Authentication. # # @param options [Hash] A customizable set of options. # @option options [Array] :scopes Replace the authorization scopes with these. # @option options [Array] :add_scopes A list of scopes to add to this authorization. # @option options [Array] :remove_scopes A list of scopes to remove from this authorization. # @option options [String] :note A note to remind you what the OAuth token is for. # @option options [String] :note_url A URL to remind you what app the OAuth token is for. # # @return [Sawyer::Resource] A single (updated) authorization for the authenticated user # @see https://developer.github.com/v3/oauth_authorizations/#update-an-existing-authorization # @see https://developer.github.com/v3/oauth/#scopes for available scopes # @example Update the authorization for user ctshryock's project Zoidberg # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret') # client.update_authorization(999999, {:add_scopes => ["gist", "repo"], :note => "Why not Zoidberg possibly?"}) def update_authorization(number, options = {}) patch "authorizations/#{number}", options end # Delete an authorization for the authenticated user. # # You can delete your own tokens, and only through # Basic Authentication. # # @param number [Number] An existing Authorization ID # # @return [Boolean] Success # @see https://developer.github.com/v3/oauth_authorizations/#delete-an-authorization # @example Delete an authorization # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret') # client.delete_authorization(999999) def delete_authorization(number, options = {}) boolean_from_response :delete, "authorizations/#{number}", options end # Check scopes for a token # # @param token [String] GitHub OAuth token # @return [Array] OAuth scopes # @see https://developer.github.com/v3/oauth/#scopes def scopes(token = @access_token) raise ArgumentError.new("Access token required") if token.nil? agent.call(:get, "user", :headers => {"Authorization" => "token #{token}" }). headers['X-OAuth-Scopes']. to_s. split(','). map(&:strip). sort end # Check if a token is valid. # # Applications can check if a token is valid without rate limits. # # @param token [String] 40 character GitHub OAuth access token # # @return [Sawyer::Resource] A single authorization for the authenticated user # @see https://developer.github.com/v3/oauth_authorizations/#check-an-authorization # @example # client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret') # client.check_application_authorization('deadbeef1234567890deadbeef987654321') def check_application_authorization(token, options = {}) opts = options.dup key = opts.delete(:client_id) || client_id secret = opts.delete(:client_secret) || client_secret as_app(key, secret) do |app_client| app_client.get "/applications/#{client_id}/tokens/#{token}", opts end end # Reset a token # # Applications can reset a token without requiring a user to re-authorize. # # @param token [String] 40 character GitHub OAuth access token # # @return [Sawyer::Resource] A single authorization for the authenticated user # @see https://developer.github.com/v3/oauth_authorizations/#reset-an-authorization # @example # client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret') # client.reset_application_authorization('deadbeef1234567890deadbeef987654321') def reset_application_authorization(token, options = {}) opts = options.dup key = opts.delete(:client_id) || client_id secret = opts.delete(:client_secret) || client_secret as_app(key, secret) do |app_client| app_client.post "/applications/#{client_id}/tokens/#{token}", opts end end # Revoke a token # # Applications can revoke (delete) a token # # @param token [String] 40 character GitHub OAuth access token # # @return [Boolean] Result # @see https://developer.github.com/v3/oauth_authorizations/#revoke-an-authorization-for-an-application # @example # client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret') # client.revoke_application_authorization('deadbeef1234567890deadbeef987654321') def revoke_application_authorization(token, options = {}) opts = options.dup key = opts.delete(:client_id) || client_id secret = opts.delete(:client_secret) || client_secret as_app(key, secret) do |app_client| app_client.delete "/applications/#{client_id}/tokens/#{token}", opts app_client.last_response.status == 204 end rescue Octokit::NotFound false end alias :delete_application_authorization :revoke_application_authorization # Revoke all tokens for an app # # Applications can revoke all of their tokens in a single request # # @return [Boolean] Result # @see https://developer.github.com/v3/oauth_authorizations/#revoke-all-authorizations-for-an-application # @example # client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret') # client.revoke_all_application_authorizations def revoke_all_application_authorizations(options = {}) opts = options.dup key = opts.delete(:client_id) || client_id secret = opts.delete(:client_secret) || client_secret as_app(key, secret) do |app_client| app_client.delete "/applications/#{client_id}/tokens", opts app_client.last_response.status == 204 end rescue Octokit::NotFound false end alias :delete_application_authorization :revoke_application_authorization # Get the URL to authorize a user for an application via the web flow # # @param app_id [String] Client Id we received when our application was registered with GitHub. # @option options [String] :redirect_uri The url to redirect to after authorizing. # @option options [String] :scope The scopes to request from the user. # @option options [String] :state A random string to protect against CSRF. # @return [String] The url to redirect the user to authorize. # @see Octokit::Client # @see https://developer.github.com/v3/oauth/#web-application-flow # @example # @client.authorize_url('xxxx') def authorize_url(app_id = client_id, options = {}) if app_id.to_s.empty? raise Octokit::ApplicationCredentialsRequired.new "client_id required" end authorize_url = options.delete(:endpoint) || Octokit.web_endpoint authorize_url += "login/oauth/authorize?client_id=" + app_id options.each do |key, value| authorize_url += "&" + key.to_s + "=" + value end authorize_url end end end end octokit-3.8.0/lib/octokit/client/organizations.rb0000644000004100000410000005550012511016543022145 0ustar www-datawww-datamodule Octokit class Client # Methods for the Organizations API # # @see https://developer.github.com/v3/orgs/ module Organizations # Get an organization # # @param org [String, Integer] Organization GitHub login or id. # @return [Sawyer::Resource] Hash representing GitHub organization. # @see https://developer.github.com/v3/orgs/#get-an-organization # @example # Octokit.organization('github') # @example # Octokit.org('github') def organization(org, options = {}) get Organization.path(org), options end alias :org :organization # Update an organization. # # Requires authenticated client with proper organization permissions. # # @param org [String, Integer] Organization GitHub login or id. # @param values [Hash] The updated organization attributes. # @option values [String] :billing_email Billing email address. This address is not publicized. # @option values [String] :company Company name. # @option values [String] :email Publicly visible email address. # @option values [String] :location Location of organization. # @option values [String] :name GitHub username for organization. # @return [Sawyer::Resource] Hash representing GitHub organization. # @see https://developer.github.com/v3/orgs/#edit-an-organization # @example # @client.update_organization('github', { # :billing_email => 'support@github.com', # :company => 'GitHub', # :email => 'support@github.com', # :location => 'San Francisco', # :name => 'github' # }) # @example # @client.update_org('github', {:company => 'Unicorns, Inc.'}) def update_organization(org, values, options = {}) patch Organization.path(org), options.merge({:organization => values}) end alias :update_org :update_organization # Get organizations for a user. # # Nonauthenticated calls to this method will return organizations that # the user is a public member. # # Use an authenicated client to get both public and private organizations # for a user. # # Calling this method on a `@client` will return that users organizations. # Private organizations are included only if the `@client` is authenticated. # # @param user [Integer, String] GitHub user login or id of the user to get # list of organizations. # @return [Array] Array of hashes representing organizations. # @see https://developer.github.com/v3/orgs/#list-user-organizations # @example # Octokit.organizations('pengwynn') # @example # @client.organizations('pengwynn') # @example # Octokit.orgs('pengwynn') # @example # Octokit.list_organizations('pengwynn') # @example # Octokit.list_orgs('pengwynn') # @example # @client.organizations def organizations(user=nil, options = {}) get "#{User.path user}/orgs", options end alias :list_organizations :organizations alias :list_orgs :organizations alias :orgs :organizations # List organization repositories # # Public repositories are available without authentication. Private repos # require authenticated organization member. # # @param org [String, Integer] Organization GitHub login or id for which # to list repos. # @option options [String] :type ('all') Filter by repository type. # `all`, `public`, `member`, `sources`, `forks`, or `private`. # # @return [Array] List of repositories # @see https://developer.github.com/v3/repos/#list-organization-repositories # @example # Octokit.organization_repositories('github') # @example # Octokit.org_repositories('github') # @example # Octokit.org_repos('github') # @example # @client.org_repos('github', {:type => 'private'}) def organization_repositories(org, options = {}) paginate "#{Organization.path org}/repos", options end alias :org_repositories :organization_repositories alias :org_repos :organization_repositories # Get organization members # # Public members of the organization are returned by default. An # authenticated client that is a member of the GitHub organization # is required to get private members. # # @param org [String, Integer] Organization GitHub login or id. # @return [Array] Array of hashes representing users. # @see https://developer.github.com/v3/orgs/members/#members-list # @example # Octokit.organization_members('github') # @example # Octokit.org_members('github') def organization_members(org, options = {}) path = "public_" if options.delete(:public) paginate "#{Organization.path org}/#{path}members", options end alias :org_members :organization_members # Get organization public members # # Lists the public members of an organization # # @param org [String] Organization GitHub username. # @return [Array] Array of hashes representing users. # @see https://developer.github.com/v3/orgs/members/#public-members-list # @example # Octokit.organization_public_members('github') # @example # Octokit.org_public_members('github') def organization_public_members(org, options = {}) organization_members org, options.merge(:public => true) end alias :org_public_members :organization_public_members # Check if a user is a member of an organization. # # Use this to check if another user is a member of an organization that # you are a member. If you are not in the organization you are checking, # use .organization_public_member? instead. # # @param org [String, Integer] Organization GitHub login or id. # @param user [String] GitHub username of the user to check. # # @return [Boolean] Is a member? # # @see https://developer.github.com/v3/orgs/members/#check-membership # # @example Check if a user is in your organization # @client.organization_member?('your_organization', 'pengwynn') # => false def organization_member?(org, user, options = {}) result = boolean_from_response(:get, "#{Organization.path org}/members/#{user}", options) if !result && last_response && last_response.status == 302 boolean_from_response :get, last_response.headers['Location'] else result end end alias :org_member? :organization_member? # Check if a user is a public member of an organization. # # If you are checking for membership of a user of an organization that # you are in, use .organization_member? instead. # # @param org [String, Integer] Organization GitHub login or id. # @param user [String] GitHub username of the user to check. # # @return [Boolean] Is a public member? # # @see https://developer.github.com/v3/orgs/members/#check-public-membership # # @example Check if a user is a hubbernaut # @client.organization_public_member?('github', 'pengwynn') # => true def organization_public_member?(org, user, options = {}) boolean_from_response :get, "#{Organization.path org}/public_members/#{user}", options end alias :org_public_member? :organization_public_member? # List teams # # Requires authenticated organization member. # # @param org [String, Integer] Organization GitHub login or id. # @return [Array] Array of hashes representing teams. # @see https://developer.github.com/v3/orgs/teams/#list-teams # @example # @client.organization_teams('github') # @example # @client.org_teams('github') def organization_teams(org, options = {}) paginate "#{Organization.path org}/teams", options end alias :org_teams :organization_teams # Create team # # Requires authenticated organization owner. # # @param org [String, Integer] Organization GitHub login or id. # @option options [String] :name Team name. # @option options [Array] :repo_names Repositories for the team. # @option options [String, optional] :permission ('pull') Permissions the # team has for team repositories. # # `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. # @return [Sawyer::Resource] Hash representing new team. # @see https://developer.github.com/v3/orgs/teams/#create-team # @example # @client.create_team('github', { # :name => 'Designers', # :repo_names => ['github/dotfiles'], # :permission => 'push' # }) def create_team(org, options = {}) post "#{Organization.path org}/teams", options end # Get team # # Requires authenticated organization member. # # @param team_id [Integer] Team id. # @return [Sawyer::Resource] Hash representing team. # @see https://developer.github.com/v3/orgs/teams/#get-team # @example # @client.team(100000) def team(team_id, options = {}) get "teams/#{team_id}", options end # Update team # # Requires authenticated organization owner. # # @param team_id [Integer] Team id. # @option options [String] :name Team name. # @option options [String] :permission Permissions the team has for team repositories. # # `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. # @return [Sawyer::Resource] Hash representing updated team. # @see https://developer.github.com/v3/orgs/teams/#edit-team # @example # @client.update_team(100000, { # :name => 'Front-end Designers', # :permission => 'push' # }) def update_team(team_id, options = {}) patch "teams/#{team_id}", options end # Delete team # # Requires authenticated organization owner. # # @param team_id [Integer] Team id. # @return [Boolean] True if deletion successful, false otherwise. # @see https://developer.github.com/v3/orgs/teams/#delete-team # @example # @client.delete_team(100000) def delete_team(team_id, options = {}) boolean_from_response :delete, "teams/#{team_id}", options end # List team members # # Requires authenticated organization member. # # @param team_id [Integer] Team id. # @return [Array] Array of hashes representing users. # @see https://developer.github.com/v3/orgs/teams/#list-team-members # @example # @client.team_members(100000) def team_members(team_id, options = {}) paginate "teams/#{team_id}/members", options end # Add team member # # Requires authenticated organization owner or member with team # `admin` permission. # # @param team_id [Integer] Team id. # @param user [String] GitHub username of new team member. # @return [Boolean] True on successful addition, false otherwise. # @see https://developer.github.com/v3/orgs/teams/#add-team-member # @example # @client.add_team_member(100000, 'pengwynn') # # @example # # Opt-in to future behavior for this endpoint. Adds the member to the # # team if they're already an org member. If not, the method will return # # 422 and indicate the user should call the new Team Membership endpoint. # @client.add_team_member \ # 100000, # 'pengwynn', # :accept => "application/vnd.github.the-wasp-preview+json" # @see https://developer.github.com/changes/2014-08-05-team-memberships-api/ def add_team_member(team_id, user, options = {}) # There's a bug in this API call. The docs say to leave the body blank, # but it fails if the body is both blank and the content-length header # is not 0. boolean_from_response :put, "teams/#{team_id}/members/#{user}", options.merge({:name => user}) end # Remove team member # # Requires authenticated organization owner or member with team # `admin` permission. # # @param team_id [Integer] Team id. # @param user [String] GitHub username of the user to boot. # @return [Boolean] True if user removed, false otherwise. # @see https://developer.github.com/v3/orgs/teams/#remove-team-member # @example # @client.remove_team_member(100000, 'pengwynn') def remove_team_member(team_id, user, options = {}) boolean_from_response :delete, "teams/#{team_id}/members/#{user}", options end # Check if a user is a member of a team. # # Use this to check if another user is a member of a team that # you are a member. # # @param team_id [Integer] Team id. # @param user [String] GitHub username of the user to check. # # @return [Boolean] Is a member? # # @see https://developer.github.com/v3/orgs/teams/#get-team-member # # @example Check if a user is in your team # @client.team_member?('your_team', 'pengwynn') # => false def team_member?(team_id, user, options = {}) boolean_from_response :get, "teams/#{team_id}/members/#{user}", options end # List team repositories # # Requires authenticated organization member. # # @param team_id [Integer] Team id. # @return [Array] Array of hashes representing repositories. # @see https://developer.github.com/v3/orgs/teams/#list-team-repos # @example # @client.team_repositories(100000) # @example # @client.team_repos(100000) def team_repositories(team_id, options = {}) paginate "teams/#{team_id}/repos", options end alias :team_repos :team_repositories # Check if a repo is managed by a specific team # # @param team_id [Integer] Team ID. # @param repo [String, Hash, Repository] A GitHub repository. # @return [Boolean] True if managed by a team. False if not managed by # the team OR the requesting user does not have authorization to access # the team information. # @see https://developer.github.com/v3/orgs/teams/#get-team-repo # @example # @client.team_repository?(8675309, 'octokit/octokit.rb') # @example # @client.team_repo?(8675309, 'octokit/octokit.rb') def team_repository?(team_id, repo, options = {}) boolean_from_response :get, "teams/#{team_id}/repos/#{Repository.new(repo)}" end alias :team_repo? :team_repository? # Add team repository # # Requires authenticated user to be an owner of the organization that the # team is associated with. Also, the repo must be owned by the # organization, or a direct form of a repo owned by the organization. # # @param team_id [Integer] Team id. # @param repo [String, Hash, Repository] A GitHub repository. # @return [Boolean] True if successful, false otherwise. # @see Octokit::Repository # @see https://developer.github.com/v3/orgs/teams/#add-team-repo # @example # @client.add_team_repository(100000, 'github/developer.github.com') # @example # @client.add_team_repo(100000, 'github/developer.github.com') def add_team_repository(team_id, repo, options = {}) boolean_from_response :put, "teams/#{team_id}/repos/#{Repository.new(repo)}", options.merge(:name => Repository.new(repo)) end alias :add_team_repo :add_team_repository # Remove team repository # # Removes repository from team. Does not delete the repository. # # Requires authenticated organization owner. # # @param team_id [Integer] Team id. # @param repo [String, Hash, Repository] A GitHub repository. # @return [Boolean] Return true if repo removed from team, false otherwise. # @see Octokit::Repository # @see https://developer.github.com/v3/orgs/teams/#remove-team-repo # @example # @client.remove_team_repository(100000, 'github/developer.github.com') # @example # @client.remove_team_repo(100000, 'github/developer.github.com') def remove_team_repository(team_id, repo, options = {}) boolean_from_response :delete, "teams/#{team_id}/repos/#{Repository.new(repo)}" end alias :remove_team_repo :remove_team_repository # Remove organization member # # Requires authenticated organization owner or member with team `admin` access. # # @param org [String, Integer] Organization GitHub login or id. # @param user [String] GitHub username of user to remove. # @return [Boolean] True if removal is successful, false otherwise. # @see https://developer.github.com/v3/orgs/members/#remove-a-member # @example # @client.remove_organization_member('github', 'pengwynn') # @example # @client.remove_org_member('github', 'pengwynn') def remove_organization_member(org, user, options = {}) # this is a synonym for: for team in org.teams: remove_team_member(team.id, user) # provided in the GH API v3 boolean_from_response :delete, "#{Organization.path org}/members/#{user}", options end alias :remove_org_member :remove_organization_member # Publicize a user's membership of an organization # # Requires authenticated organization owner. # # @param org [String, Integer] Organization GitHub login or id. # @param user [String] GitHub username of user to publicize. # @return [Boolean] True if publicization successful, false otherwise. # @see https://developer.github.com/v3/orgs/members/#publicize-a-users-membership # @example # @client.publicize_membership('github', 'pengwynn') def publicize_membership(org, user, options = {}) boolean_from_response :put, "#{Organization.path org}/public_members/#{user}", options end # Conceal a user's membership of an organization. # # Requires authenticated organization owner. # # @param org [String, Integer] Organization GitHub login or id. # @param user [String] GitHub username of user to unpublicize. # @return [Boolean] True of unpublicization successful, false otherwise. # @see https://developer.github.com/v3/orgs/members/#conceal-a-users-membership # @example # @client.unpublicize_membership('github', 'pengwynn') # @example # @client.conceal_membership('github', 'pengwynn') def unpublicize_membership(org, user, options = {}) boolean_from_response :delete, "#{Organization.path org}/public_members/#{user}", options end alias :conceal_membership :unpublicize_membership # List all teams for the authenticated user across all their orgs # # @return [Array] Array of team resources. # @see https://developer.github.com/v3/orgs/teams/#list-user-teams def user_teams(options = {}) paginate "/user/teams", options end # Check if a user has a team membership. # # @param team_id [Integer] Team id. # @param user [String] GitHub username of the user to check. # # @return [Sawyer::Resource] Hash of team membership info # # @see https://developer.github.com/v3/orgs/teams/#get-team-membership # # @example Check if a user has a membership for a team # @client.team_membership(1234, 'pengwynn') def team_membership(team_id, user, options = {}) get "teams/#{team_id}/memberships/#{user}", options end # Add or invite a user to a team # # @param team_id [Integer] Team id. # @param user [String] GitHub username of the user to invite. # # @return [Sawyer::Resource] Hash of team membership info # # @see https://developer.github.com/v3/orgs/teams/#add-team-membership # # @example Check if a user has a membership for a team # @client.add_team_membership(1234, 'pengwynn') def add_team_membership(team_id, user, options = {}) put "teams/#{team_id}/memberships/#{user}", options end # Remove team membership # # @param team_id [Integer] Team id. # @param user [String] GitHub username of the user to boot. # @return [Boolean] True if user removed, false otherwise. # @see https://developer.github.com/v3/orgs/teams/#remove-team-membership # @example # @client.remove_team_membership(100000, 'pengwynn') def remove_team_membership(team_id, user, options = {}) boolean_from_response :delete, "teams/#{team_id}/memberships/#{user}", options end # List all organizations memberships for the authenticated user # # @return [Array] Array of organizations memberships. # @see https://developer.github.com/v3/orgs/members/#list-your-organization-memberships def organization_memberships(options = {}) paginate "user/memberships/orgs", options end alias :org_memberships :organization_memberships # Get an organization membership for the authenticated user # # @param org [String] Organization GitHub login. # @return [Sawyer::Resource] Hash representing the organization membership. # @see https://developer.github.com/v3/orgs/members/#get-your-organization-membership def organization_membership(org, options = {}) get "user/memberships/orgs/#{org}", options end alias :org_membership :organization_membership # Edit an organization membership for the authenticated user # # @param org [String] Organization GitHub login. # @option options [String] :state The state that the membership should be in. # @return [Sawyer::Resource] Hash representing the updated organization membership. # @see https://developer.github.com/v3/orgs/members/#edit-your-organization-membership def update_organization_membership(org, options = {}) patch "user/memberships/orgs/#{org}", options end alias :update_org_membership :update_organization_membership end end end octokit-3.8.0/lib/octokit/client/objects.rb0000644000004100000410000001465312511016543020713 0ustar www-datawww-datamodule Octokit class Client # Methods for the Git Data API # # @see https://developer.github.com/v3/git/ module Objects # Get a single tree, fetching information about its root-level objects # # Pass :recursive => true in options to fetch information about all of the tree's objects, including those in subdirectories. # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param tree_sha [String] The SHA of the tree to fetch # @return [Sawyer::Resource] A hash representing the fetched tree # @see https://developer.github.com/v3/git/trees/#get-a-tree # @see https://developer.github.com/v3/git/trees/#get-a-tree-recursively # @example Fetch a tree and inspect the path of one of its files # tree = Octokit.tree("octocat/Hello-World", "9fb037999f264ba9a7fc6274d15fa3ae2ab98312") # tree.tree.first.path # => "file.rb" # @example Fetch a tree recursively # tree = Octokit.tree("octocat/Hello-World", "fc6274d15fa3ae2ab983129fb037999f264ba9a7", :recursive => true) # tree.tree.first.path # => "subdir/file.txt" def tree(repo, tree_sha, options = {}) get "#{Repository.path repo}/git/trees/#{tree_sha}", options end # Create a tree # # Pass :base_tree => "827efc6..." in options to update an existing tree with new data. # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param tree [Array] An array of hashes representing a tree structure # @return [Sawyer::Resource] A hash representing the new tree # @see https://developer.github.com/v3/git/trees/#create-a-tree # @example Create a tree containing one file # tree = Octokit.create_tree("octocat/Hello-World", [ { :path => "file.rb", :mode => "100644", :type => "blob", :sha => "44b4fc6d56897b048c772eb4087f854f46256132" } ]) # tree.sha # => "cd8274d15fa3ae2ab983129fb037999f264ba9a7" # tree.tree.first.path # => "file.rb" def create_tree(repo, tree, options = {}) parameters = { :tree => tree } post "#{Repository.path repo}/git/trees", options.merge(parameters) end # Get a single blob, fetching its content and encoding # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param blob_sha [String] The SHA of the blob to fetch # @return [Sawyer::Resource] A hash representing the fetched blob # @see https://developer.github.com/v3/git/blobs/#get-a-blob # @example Fetch a blob and inspect its contents # blob = Octokit.blob("octocat/Hello-World", "827efc6d56897b048c772eb4087f854f46256132") # blob.encoding # => "utf-8" # blob.content # => "Foo bar baz" # @example Fetch a base64-encoded blob and inspect its contents # require "base64" # blob = Octokit.blob("octocat/Hello-World", "827efc6d56897b048c772eb4087f854f46256132") # blob.encoding # => "base64" # blob.content # => "Rm9vIGJhciBiYXo=" # Base64.decode64(blob.content) # => "Foo bar baz" def blob(repo, blob_sha, options = {}) get "#{Repository.path repo}/git/blobs/#{blob_sha}", options end # Create a blob # # @param repo [Integer, String, Hash, Repository] A GitHub repository # @param content [String] Content of the blob # @param encoding [String] The content's encoding. utf-8 and base64 are accepted. If your data cannot be losslessly sent as a UTF-8 string, you can base64 encode it # @return [String] The new blob's SHA, e.g. 827efc6d56897b048c772eb4087f854f46256132 # @see https://developer.github.com/v3/git/blobs/#create-a-blob # @example Create a blob containing foo bar baz # Octokit.create_blob("octocat/Hello-World", "foo bar baz") # @example Create a blob containing foo bar baz, encoded using base64 # require "base64" # Octokit.create_blob("octocat/Hello-World", Base64.encode64("foo bar baz"), "base64") def create_blob(repo, content, encoding="utf-8", options = {}) parameters = { :content => content, :encoding => encoding } blob = post "#{Repository.path repo}/git/blobs", options.merge(parameters) blob.sha end # Get a tag # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param tag_sha [String] The SHA of the tag to fetch. # @return [Sawyer::Resource] Hash representing the tag. # @see https://developer.github.com/v3/git/tags/#get-a-tag # @example Fetch a tag # Octokit.tag('octokit/octokit.rb', '23aad20633f4d2981b1c7209a800db3014774e96') def tag(repo, tag_sha, options = {}) get "#{Repository.path repo}/git/tags/#{tag_sha}", options end # Create a tag # # Requires authenticated client. # # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @param tag [String] Tag string. # @param message [String] Tag message. # @param object_sha [String] SHA of the git object this is tagging. # @param type [String] Type of the object we're tagging. Normally this is # a `commit` but it can also be a `tree` or a `blob`. # @param tagger_name [String] Name of the author of the tag. # @param tagger_email [String] Email of the author of the tag. # @param tagger_date [string] Timestamp of when this object was tagged. # @return [Sawyer::Resource] Hash representing new tag. # @see https://developer.github.com/v3/git/tags/#create-a-tag-object # @example # @client.create_tag( # "octokit/octokit.rb", # "v9000.0.0", # "Version 9000\n", # "f4cdf6eb734f32343ce3f27670c17b35f54fd82e", # "commit", # "Wynn Netherland", # "wynn.netherland@gmail.com", # "2012-06-03T17:03:11-07:00" # ) def create_tag(repo, tag, message, object_sha, type, tagger_name, tagger_email, tagger_date, options = {}) options.merge!( :tag => tag, :message => message, :object => object_sha, :type => type, :tagger => { :name => tagger_name, :email => tagger_email, :date => tagger_date } ) post "#{Repository.path repo}/git/tags", options end end end end octokit-3.8.0/lib/octokit/client/gitignore.rb0000644000004100000410000000251012511016543021236 0ustar www-datawww-datamodule Octokit class Client # Methods for the Gitignore API # # @see https://developer.github.com/v3/gitignore/ module Gitignore # Listing available gitignore templates. # # These templates can be passed option when creating a repository. # # @see https://developer.github.com/v3/gitignore/#listing-available-templates # # @return [Array] List of templates. # # @example Git all the gitignore templates # @client.gitignore_templates def gitignore_templates(options = {}) get "gitignore/templates", options end # Get a gitignore template. # # Use the raw {http://developer.github.com/v3/media/ media type} to get # the raw contents. # # @param template_name [String] Name of the template. Template names are # case sensitive, make sure to use a valid name from the # .gitignore_templates list. # # @see https://developer.github.com/v3/gitignore/#get-a-single-template # # @return [Sawyer::Resource] Gitignore template # # @example Get the Ruby gitignore template # @client.gitignore_template('Ruby') def gitignore_template(template_name, options = {}) get "gitignore/templates/#{template_name}", options end end end end octokit-3.8.0/lib/octokit/version.rb0000644000004100000410000000045512511016543017464 0ustar www-datawww-datamodule Octokit # Current major release. # @return [Integer] MAJOR = 3 # Current minor release. # @return [Integer] MINOR = 8 # Current patch level. # @return [Integer] PATCH = 0 # Full release version. # @return [String] VERSION = [MAJOR, MINOR, PATCH].join('.').freeze end octokit-3.8.0/lib/octokit/repo_arguments.rb0000644000004100000410000000051712511016543021030 0ustar www-datawww-datamodule Octokit # Class to extract options from Ruby arguments for # Repository-related methods class RepoArguments < Arguments # !@attribute [r] repo # @return [Repository] attr_reader :repo def initialize(args) arguments = super(args) @repo = arguments.shift arguments end end end octokit-3.8.0/lib/octokit/repository.rb0000644000004100000410000000326712511016543020222 0ustar www-datawww-datamodule Octokit # Class to parse GitHub repository owner and name from # URLs and to generate URLs class Repository attr_accessor :owner, :name, :id # Instantiate from a GitHub repository URL # # @return [Repository] def self.from_url(url) Repository.new(URI.parse(url).path[1..-1]) end def initialize(repo) case repo when Integer @id = repo when String @owner, @name = repo.split('/') unless @owner && @name raise ArgumentError, "Invalid Repository. Use user/repo format." end when Repository @owner = repo.owner @name = repo.name when Hash @name = repo[:repo] ||= repo[:name] @owner = repo[:owner] ||= repo[:user] ||= repo[:username] end end # Repository owner/name # @return [String] def slug "#{@owner}/#{@name}" end alias :to_s :slug # @return [String] Repository API path def path return named_api_path if @owner && @name return id_api_path if @id end # Get the api path for a repo # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @return [String] Api path. def self.path repo new(repo).path end # @return [String] Api path for owner/name identified repos def named_api_path "repos/#{slug}" end # @return [String] Api path for id identified repos def id_api_path "repositories/#{@id}" end # Repository URL based on {Octokit::Client#web_endpoint} # @return [String] def url "#{Octokit.web_endpoint}#{slug}" end alias :user :owner alias :username :owner alias :repo :name end end octokit-3.8.0/lib/octokit/backports/0000755000004100000410000000000012511016543017436 5ustar www-datawww-dataoctokit-3.8.0/lib/octokit/backports/uri.rb0000644000004100000410000000320312511016543020560 0ustar www-datawww-data# :stopdoc: # Stolen from ruby core's uri/common.rb, with modifications to support 1.8.x # # https://github.com/ruby/ruby/blob/trunk/lib/uri/common.rb # # module URI TBLENCWWWCOMP_ = {} # :nodoc: 256.times do |i| TBLENCWWWCOMP_[i.chr] = '%%%02X' % i end TBLENCWWWCOMP_[' '] = '+' TBLENCWWWCOMP_.freeze TBLDECWWWCOMP_ = {} # :nodoc: 256.times do |i| h, l = i>>4, i&15 TBLDECWWWCOMP_['%%%X%X' % [h, l]] = i.chr TBLDECWWWCOMP_['%%%x%X' % [h, l]] = i.chr TBLDECWWWCOMP_['%%%X%x' % [h, l]] = i.chr TBLDECWWWCOMP_['%%%x%x' % [h, l]] = i.chr end TBLDECWWWCOMP_['+'] = ' ' TBLDECWWWCOMP_.freeze # Encode given +s+ to URL-encoded form data. # # This method doesn't convert *, -, ., 0-9, A-Z, _, a-z, but does convert SP # (ASCII space) to + and converts others to %XX. # # This is an implementation of # http://www.w3.org/TR/html5/forms.html#url-encoded-form-data # # See URI.decode_www_form_component, URI.encode_www_form def self.encode_www_form_component(s) str = s.to_s if RUBY_VERSION < "1.9" && $KCODE =~ /u/i str.gsub(/([^ a-zA-Z0-9_.-]+)/) do '%' + $1.unpack('H2' * Rack::Utils.bytesize($1)).join('%').upcase end.tr(' ', '+') else str.gsub(/[^*\-.0-9A-Z_a-z]/) {|m| TBLENCWWWCOMP_[m]} end end # Decode given +str+ of URL-encoded form data. # # This decodes + to SP. # # See URI.encode_www_form_component, URI.decode_www_form def self.decode_www_form_component(str, enc=nil) raise ArgumentError, "invalid %-encoding (#{str})" unless /\A(?:%[0-9a-fA-F]{2}|[^%])*\z/ =~ str str.gsub(/\+|%[0-9a-fA-F]{2}/) {|m| TBLDECWWWCOMP_[m]} end end octokit-3.8.0/lib/octokit/configurable.rb0000644000004100000410000000752412511016543020443 0ustar www-datawww-datamodule Octokit # Configuration options for {Client}, defaulting to values # in {Default} module Configurable # @!attribute [w] access_token # @see https://developer.github.com/v3/oauth/ # @return [String] OAuth2 access token for authentication # @!attribute api_endpoint # @return [String] Base URL for API requests. default: https://api.github.com/ # @!attribute auto_paginate # @return [Boolean] Auto fetch next page of results until rate limit reached # @!attribute client_id # @see https://developer.github.com/v3/oauth/ # @return [String] Configure OAuth app key # @!attribute [w] client_secret # @see https://developer.github.com/v3/oauth/ # @return [String] Configure OAuth app secret # @!attribute default_media_type # @see https://developer.github.com/v3/media/ # @return [String] Configure preferred media type (for API versioning, for example) # @!attribute connection_options # @see https://github.com/lostisland/faraday # @return [Hash] Configure connection options for Faraday # @!attribute login # @return [String] GitHub username for Basic Authentication # @!attribute middleware # @see https://github.com/lostisland/faraday # @return [Faraday::Builder or Faraday::RackBuilder] Configure middleware for Faraday # @!attribute netrc # @return [Boolean] Instruct Octokit to get credentials from .netrc file # @!attribute netrc_file # @return [String] Path to .netrc file. default: ~/.netrc # @!attribute [w] password # @return [String] GitHub password for Basic Authentication # @!attribute per_page # @return [String] Configure page size for paginated results. API default: 30 # @!attribute proxy # @see https://github.com/lostisland/faraday # @return [String] URI for proxy server # @!attribute user_agent # @return [String] Configure User-Agent header for requests. # @!attribute web_endpoint # @return [String] Base URL for web URLs. default: https://github.com/ attr_accessor :access_token, :auto_paginate, :client_id, :client_secret, :default_media_type, :connection_options, :middleware, :netrc, :netrc_file, :per_page, :proxy, :user_agent attr_writer :password, :web_endpoint, :api_endpoint, :login class << self # List of configurable keys for {Octokit::Client} # @return [Array] of option keys def keys @keys ||= [ :access_token, :api_endpoint, :auto_paginate, :client_id, :client_secret, :connection_options, :default_media_type, :login, :middleware, :netrc, :netrc_file, :per_page, :password, :proxy, :user_agent, :web_endpoint ] end end # Set configuration options using a block def configure yield self end # Reset configuration options to default values def reset! Octokit::Configurable.keys.each do |key| instance_variable_set(:"@#{key}", Octokit::Default.options[key]) end self end alias setup reset! def api_endpoint File.join(@api_endpoint, "") end # Base URL for generated web URLs # # @return [String] Default: https://github.com/ def web_endpoint File.join(@web_endpoint, "") end def login @login ||= begin user.login if token_authenticated? end end def netrc? !!@netrc end private def options Hash[Octokit::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}] end def fetch_client_id_and_secret(overrides = {}) opts = options.merge(overrides) opts.values_at :client_id, :client_secret end end end octokit-3.8.0/lib/octokit/error.rb0000644000004100000410000001602512511016543017130 0ustar www-datawww-datamodule Octokit # Custom error class for rescuing from all GitHub errors class Error < StandardError # Returns the appropriate Octokit::Error subclass based # on status and response message # # @param [Hash] response HTTP response # @return [Octokit::Error] def self.from_response(response) status = response[:status].to_i body = response[:body].to_s headers = response[:response_headers] if klass = case status when 400 then Octokit::BadRequest when 401 then error_for_401(headers) when 403 then error_for_403(body) when 404 then Octokit::NotFound when 405 then Octokit::MethodNotAllowed when 406 then Octokit::NotAcceptable when 409 then Octokit::Conflict when 415 then Octokit::UnsupportedMediaType when 422 then Octokit::UnprocessableEntity when 400..499 then Octokit::ClientError when 500 then Octokit::InternalServerError when 501 then Octokit::NotImplemented when 502 then Octokit::BadGateway when 503 then Octokit::ServiceUnavailable when 500..599 then Octokit::ServerError end klass.new(response) end end def initialize(response=nil) @response = response super(build_error_message) end # Documentation URL returned by the API for some errors # # @return [String] def documentation_url data[:documentation_url] if data.is_a? Hash end # Returns most appropriate error for 401 HTTP status code # @private def self.error_for_401(headers) if Octokit::OneTimePasswordRequired.required_header(headers) Octokit::OneTimePasswordRequired else Octokit::Unauthorized end end # Returns most appropriate error for 403 HTTP status code # @private def self.error_for_403(body) if body =~ /rate limit exceeded/i Octokit::TooManyRequests elsif body =~ /login attempts exceeded/i Octokit::TooManyLoginAttempts elsif body =~ /abuse/i Octokit::AbuseDetected elsif body =~ /repository access blocked/i Octokit::RepositoryUnavailable else Octokit::Forbidden end end # Array of validation errors # @return [Array] Error info def errors if data && data.is_a?(Hash) data[:errors] || [] else [] end end private def data @data ||= if (body = @response[:body]) && !body.empty? if body.is_a?(String) && @response[:response_headers] && @response[:response_headers][:content_type] =~ /json/ Sawyer::Agent.serializer.decode(body) else body end else nil end end def response_message case data when Hash data[:message] when String data end end def response_error "Error: #{data[:error]}" if data.is_a?(Hash) && data[:error] end def response_error_summary return nil unless data.is_a?(Hash) && !Array(data[:errors]).empty? summary = "\nError summary:\n" summary << data[:errors].map do |hash| hash.map { |k,v| " #{k}: #{v}" } end.join("\n") summary end def build_error_message return nil if @response.nil? message = "#{@response[:method].to_s.upcase} " message << redact_url(@response[:url].to_s) + ": " message << "#{@response[:status]} - " message << "#{response_message}" unless response_message.nil? message << "#{response_error}" unless response_error.nil? message << "#{response_error_summary}" unless response_error_summary.nil? message << " // See: #{documentation_url}" unless documentation_url.nil? message end def redact_url(url_string) %w[client_secret access_token].each do |token| url_string.gsub!(/#{token}=\S+/, "#{token}=(redacted)") if url_string.include? token end url_string end end # Raised on errors in the 400-499 range class ClientError < Error; end # Raised when GitHub returns a 400 HTTP status code class BadRequest < ClientError; end # Raised when GitHub returns a 401 HTTP status code class Unauthorized < ClientError; end # Raised when GitHub returns a 401 HTTP status code # and headers include "X-GitHub-OTP" class OneTimePasswordRequired < ClientError #@private OTP_DELIVERY_PATTERN = /required; (\w+)/i #@private def self.required_header(headers) OTP_DELIVERY_PATTERN.match headers['X-GitHub-OTP'].to_s end # Delivery method for the user's OTP # # @return [String] def password_delivery @password_delivery ||= delivery_method_from_header end private def delivery_method_from_header if match = self.class.required_header(@response[:response_headers]) match[1] end end end # Raised when GitHub returns a 403 HTTP status code class Forbidden < ClientError; end # Raised when GitHub returns a 403 HTTP status code # and body matches 'rate limit exceeded' class TooManyRequests < Forbidden; end # Raised when GitHub returns a 403 HTTP status code # and body matches 'login attempts exceeded' class TooManyLoginAttempts < Forbidden; end # Raised when GitHub returns a 403 HTTP status code # and body matches 'abuse' class AbuseDetected < Forbidden; end # Raised when GitHub returns a 403 HTTP status code # and body matches 'repository access blocked' class RepositoryUnavailable < Forbidden; end # Raised when GitHub returns a 404 HTTP status code class NotFound < ClientError; end # Raised when GitHub returns a 405 HTTP status code class MethodNotAllowed < ClientError; end # Raised when GitHub returns a 406 HTTP status code class NotAcceptable < ClientError; end # Raised when GitHub returns a 409 HTTP status code class Conflict < ClientError; end # Raised when GitHub returns a 414 HTTP status code class UnsupportedMediaType < ClientError; end # Raised when GitHub returns a 422 HTTP status code class UnprocessableEntity < ClientError; end # Raised on errors in the 500-599 range class ServerError < Error; end # Raised when GitHub returns a 500 HTTP status code class InternalServerError < ServerError; end # Raised when GitHub returns a 501 HTTP status code class NotImplemented < ServerError; end # Raised when GitHub returns a 502 HTTP status code class BadGateway < ServerError; end # Raised when GitHub returns a 503 HTTP status code class ServiceUnavailable < ServerError; end # Raised when client fails to provide valid Content-Type class MissingContentType < ArgumentError; end # Raised when a method requires an application client_id # and secret but none is provided class ApplicationCredentialsRequired < StandardError; end end octokit-3.8.0/lib/octokit.rb0000644000004100000410000000163412511016543015777 0ustar www-datawww-datarequire 'octokit/client' require 'octokit/default' # Ruby toolkit for the GitHub API module Octokit class << self include Octokit::Configurable # API client based on configured options {Configurable} # # @return [Octokit::Client] API wrapper def client @client = Octokit::Client.new(options) unless defined?(@client) && @client.same_options?(options) @client end # @private def respond_to_missing?(method_name, include_private=false); client.respond_to?(method_name, include_private); end if RUBY_VERSION >= "1.9" # @private def respond_to?(method_name, include_private=false); client.respond_to?(method_name, include_private) || super; end if RUBY_VERSION < "1.9" private def method_missing(method_name, *args, &block) return super unless client.respond_to?(method_name) client.send(method_name, *args, &block) end end end Octokit.setup octokit-3.8.0/metadata.yml0000644000004100000410000000702012511016543015526 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: octokit version: !ruby/object:Gem::Version version: 3.8.0 platform: ruby authors: - Wynn Netherland - Erik Michaels-Ober - Clint Shryock autorequire: bindir: bin cert_chain: [] date: 2015-02-19 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: bundler requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.0' - !ruby/object:Gem::Dependency name: sawyer requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 0.5.3 - - "~>" - !ruby/object:Gem::Version version: 0.6.0 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 0.5.3 - - "~>" - !ruby/object:Gem::Version version: 0.6.0 description: Simple wrapper for the GitHub API email: - wynn.netherland@gmail.com - sferik@gmail.com - clint@ctshryock.com executables: [] extensions: [] extra_rdoc_files: [] files: - ".document" - CONTRIBUTING.md - LICENSE.md - README.md - Rakefile - lib/octokit.rb - lib/octokit/arguments.rb - lib/octokit/authentication.rb - lib/octokit/backports/uri.rb - lib/octokit/client.rb - lib/octokit/client/authorizations.rb - lib/octokit/client/commit_comments.rb - lib/octokit/client/commits.rb - lib/octokit/client/contents.rb - lib/octokit/client/deployments.rb - lib/octokit/client/downloads.rb - lib/octokit/client/emojis.rb - lib/octokit/client/events.rb - lib/octokit/client/feeds.rb - lib/octokit/client/gists.rb - lib/octokit/client/gitignore.rb - lib/octokit/client/hooks.rb - lib/octokit/client/issues.rb - lib/octokit/client/labels.rb - lib/octokit/client/legacy_search.rb - lib/octokit/client/markdown.rb - lib/octokit/client/meta.rb - lib/octokit/client/milestones.rb - lib/octokit/client/notifications.rb - lib/octokit/client/objects.rb - lib/octokit/client/organizations.rb - lib/octokit/client/pages.rb - lib/octokit/client/pub_sub_hubbub.rb - lib/octokit/client/pull_requests.rb - lib/octokit/client/rate_limit.rb - lib/octokit/client/refs.rb - lib/octokit/client/releases.rb - lib/octokit/client/repositories.rb - lib/octokit/client/say.rb - lib/octokit/client/search.rb - lib/octokit/client/service_status.rb - lib/octokit/client/stats.rb - lib/octokit/client/statuses.rb - lib/octokit/client/users.rb - lib/octokit/configurable.rb - lib/octokit/default.rb - lib/octokit/error.rb - lib/octokit/gist.rb - lib/octokit/organization.rb - lib/octokit/rate_limit.rb - lib/octokit/repo_arguments.rb - lib/octokit/repository.rb - lib/octokit/response/feed_parser.rb - lib/octokit/response/raise_error.rb - lib/octokit/user.rb - lib/octokit/version.rb - octokit.gemspec homepage: https://github.com/octokit/octokit.rb licenses: - MIT metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 1.9.2 required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 1.3.5 requirements: [] rubyforge_project: rubygems_version: 2.2.2 signing_key: specification_version: 4 summary: Ruby toolkit for working with the GitHub API test_files: [] has_rdoc: octokit-3.8.0/CONTRIBUTING.md0000644000004100000410000000200512511016543015452 0ustar www-datawww-data## Submitting a Pull Request 0. Check out Hacking on Octokit in the README guide for bootstrapping the project for local development. 1. [Fork the repository.][fork] 2. [Create a topic branch.][branch] 3. Add specs for your unimplemented feature or bug fix. 4. Run `script/test`. If your specs pass, return to step 3. 5. Implement your feature or bug fix. 6. Run `script/test`. If your specs fail, return to step 5. 7. Run `open coverage/index.html`. If your changes are not completely covered by your tests, return to step 4. 8. Add documentation for your feature or bug fix. 9. Run `bundle exec rake doc:yard`. If your changes are not 100% documented, go back to step 8. 10. Add, commit, and push your changes. For documentation-only fixes, please add "[ci skip]" to your commit message to avoid needless CI builds. 11. [Submit a pull request.][pr] [fork]: https://help.github.com/articles/fork-a-repo [branch]: http://learn.github.com/p/branching.html [pr]: https://help.github.com/articles/using-pull-requests octokit-3.8.0/octokit.gemspec0000644000004100000410000000171312511016543016247 0ustar www-datawww-data# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'octokit/version' Gem::Specification.new do |spec| spec.add_development_dependency 'bundler', '~> 1.0' spec.add_dependency 'sawyer', '>= 0.5.3', '~> 0.6.0' spec.authors = ["Wynn Netherland", "Erik Michaels-Ober", "Clint Shryock"] spec.description = %q{Simple wrapper for the GitHub API} spec.email = ['wynn.netherland@gmail.com', 'sferik@gmail.com', 'clint@ctshryock.com'] spec.files = %w(.document CONTRIBUTING.md LICENSE.md README.md Rakefile octokit.gemspec) spec.files += Dir.glob("lib/**/*.rb") spec.homepage = 'https://github.com/octokit/octokit.rb' spec.licenses = ['MIT'] spec.name = 'octokit' spec.require_paths = ['lib'] spec.required_ruby_version = '>= 1.9.2' spec.required_rubygems_version = '>= 1.3.5' spec.summary = "Ruby toolkit for working with the GitHub API" spec.version = Octokit::VERSION.dup end octokit-3.8.0/README.md0000644000004100000410000004654012511016543014514 0ustar www-datawww-data# Octokit Ruby toolkit for the GitHub API. ![Logo][logo] [logo]: http://cl.ly/image/3Y013H0A2z3z/gundam-ruby.png Upgrading? Check the [Upgrade Guide](#upgrading-guide) before bumping to a new [major version][semver]. ## Philosophy API wrappers [should reflect the idioms of the language in which they were written][wrappers]. Octokit.rb wraps the [GitHub API][github-api] in a flat API client that follows Ruby conventions and requires little knowledge of REST. Most methods have positional arguments for required input and an options hash for optional parameters, headers, or other options: ```ruby # Fetch a README with Accept header for HTML format Octokit.readme 'al3x/sovereign', :accept => 'application/vnd.github.html' ``` [wrappers]: http://wynnnetherland.com/journal/what-makes-a-good-api-wrapper [github-api]: http://developer.github.com ## Quick start Install via Rubygems gem install octokit ... or add to your Gemfile gem "octokit", "~> 3.0" ### Making requests [API methods][] are available as module methods (consuming module-level configuration) or as client instance methods. ```ruby # Provide authentication credentials Octokit.configure do |c| c.login = 'defunkt' c.password = 'c0d3b4ssssss!' end # Fetch the current user Octokit.user ``` or ```ruby # Provide authentication credentials client = Octokit::Client.new(:login => 'defunkt', :password => 'c0d3b4ssssss!') # Fetch the current user client.user ``` [API methods]: http://octokit.github.io/octokit.rb/method_list.html ### Consuming resources Most methods return a `Resource` object which provides dot notation and `[]` access for fields returned in the API response. ```ruby # Fetch a user user = Octokit.user 'jbarnette' puts user.name # => "John Barnette" puts user.fields # => puts user[:company] # => "GitHub" user.rels[:gists].href # => "https://api.github.com/users/jbarnette/gists" ``` **Note:** URL fields are culled into a separate `.rels` collection for easier [Hypermedia](#hypermedia-agent) support. ### Accessing HTTP responses While most methods return a `Resource` object or a Boolean, sometimes you may need access to the raw HTTP response headers. You can access the last HTTP response with `Client#last_response`: ```ruby user = Octokit.user 'andrewpthorp' response = Octokit.last_response etag = response.headers[:etag] ``` ## Authentication Octokit supports the various [authentication methods supported by the GitHub API][auth]: ### Basic Authentication Using your GitHub username and password is the easiest way to get started making authenticated requests: ```ruby client = Octokit::Client.new \ :login => 'defunkt', :password => 'c0d3b4ssssss!' user = client.user user.login # => "defunkt" ``` While Basic Authentication allows you to get started quickly, OAuth access tokens are the preferred way to authenticate on behalf of users. ### OAuth access tokens [OAuth access tokens][oauth] provide two main benefits over using your username and password: * **Revokable access**. Access tokens can be revoked, removing access for only that token without having to change your password everywhere. * **Limited access**. Access tokens have [access scopes][] which allow for more granular access to API resources. For instance, you can grant a third party access to your gists but not your private repositories. To use an access token with the Octokit client, pass your token in the `:access_token` options parameter in lieu of your username and password: ```ruby client = Octokit::Client.new(:access_token => "") user = client.user user.login # => "defunkt" ``` You can [create access tokens through your GitHub Account Settings](https://help.github.com/articles/creating-an-access-token-for-command-line-use) or with a basic authenticated Octokit client: ```ruby client = Octokit::Client.new \ :login => 'defunkt', :password => 'c0d3b4ssssss!' client.create_authorization(:scopes => ["user"], :note => "Name of token") # => ``` ### Two-Factor Authentication [Two-Factor Authentication](https://help.github.com/articles/about-two-factor-authentication) brings added security to the account by requiring more information to login. Using two-factor authentication for API calls is as simple as adding the [required header](http://developer.github.com/v3/auth/#working-with-two-factor-authentication) as an option: ```ruby client = Octokit::Client.new \ :login => 'defunkt', :password => 'c0d3b4ssssss!' user = client.user("defunkt", :headers => { "X-GitHub-OTP" => "" }) ``` As you can imagine, this gets annoying quick since two-factor auth tokens are very short lived. So it is recommended to create an oauth token for the user to communicate with the API: ```ruby client = Octokit::Client.new \ :login => 'defunkt', :password => 'c0d3b4ssssss!' client.create_authorization(:scopes => ["user"], :note => "Name of token", :headers => { "X-GitHub-OTP" => "" }) # => ``` ### Using a .netrc file Octokit supports reading credentials from a netrc file (defaulting to `~/.netrc`). Given these lines in your netrc: ``` machine api.github.com login defunkt password c0d3b4ssssss! ``` You can now create a client with those credentials: ```ruby client = Octokit::Client.new(:netrc => true) client.login # => "defunkt" ``` But _I want to use OAuth_ you say. Since the GitHub API supports using an OAuth token as a Basic password, you totally can: ``` machine api.github.com login defunkt password ``` **Note:** Support for netrc requires adding the [netrc gem][] to your Gemfile or `.gemspec`. ### Application authentication Octokit also supports application-only authentication [using OAuth application client credentials][app-creds]. Using application credentials will result in making anonymous API calls on behalf of an application in order to take advantage of the higher rate limit. ```ruby client = Octokit::Client.new \ :client_id => "", :client_secret => "" user = client.user 'defunkt' ``` [auth]: http://developer.github.com/v3/#authentication [oauth]: http://developer.github.com/v3/oauth/ [access scopes]: http://developer.github.com/v3/oauth/#scopes [app-creds]: http://developer.github.com/v3/#increasing-the-unauthenticated-rate-limit-for-oauth-applications ## Pagination Many GitHub API resources are [paginated][]. While you may be tempted to start adding `:page` parameters to your calls, the API returns links to the next, previous, and last pages for you in the `Link` response header as [Hypermedia link relations](#hypermedia-agent). ```ruby issues = Octokit.issues 'rails/rails', :per_page => 100 issues.concat Octokit.last_response.rels[:next].get.data ``` ### Auto pagination For smallish resource lists, Octokit provides auto pagination. When this is enabled, calls for paginated resources will fetch and concatenate the results from every page into a single array: ```ruby Octokit.auto_paginate = true issues = Octokit.issues 'rails/rails' issues.length # => 702 ``` **Note:** While Octokit auto pagination will set the page size to the maximum `100`, and seek to not overstep your rate limit, you probably want to use a custom pattern for traversing large lists. [paginated]: http://developer.github.com/v3/#pagination ## Configuration and defaults While `Octokit::Client` accepts a range of options when creating a new client instance, Octokit's configuration API allows you to set your configuration options at the module level. This is particularly handy if you're creating a number of client instances based on some shared defaults. ### Configuring module defaults Every writable attribute in {Octokit::Configurable} can be set one at a time: ```ruby Octokit.api_endpoint = 'http://api.github.dev' Octokit.web_endpoint = 'http://github.dev' ``` or in batch: ```ruby Octokit.configure do |c| c.api_endpoint = 'http://api.github.dev' c.web_endpoint = 'http://github.dev' end ``` ### Using ENV variables Default configuration values are specified in {Octokit::Default}. Many attributes will look for a default value from the ENV before returning Octokit's default. ```ruby # Given $OCTOKIT_API_ENDPOINT is "http://api.github.dev" Octokit.api_endpoint # => "http://api.github.dev" ``` Deprecation warnings and API endpoints in development preview warnings are printed to STDOUT by default, these can be disabled by setting the ENV `OCTOKIT_SILENT=true`. ## Hypermedia agent Starting in version 2.0, Octokit is [hypermedia][]-enabled. Under the hood, {Octokit::Client} uses [Sawyer][], a hypermedia client built on [Faraday][]. ### Hypermedia in Octokit Resources returned by Octokit methods contain not only data but hypermedia link relations: ```ruby user = Octokit.user 'technoweenie' # Get the repos rel, returned from the API # as repos_url in the resource user.rels[:repos].href # => "https://api.github.com/users/technoweenie/repos" repos = user.rels[:repos].get.data repos.last.name # => "faraday-zeromq" ``` When processing API responses, all `*_url` attributes are culled in to the link relations collection. Any `url` attribute becomes `.rels[:self]`. ### URI templates You might notice many link relations have variable placeholders. Octokit supports [URI Templates][uri-templates] for parameterized URI expansion: ```ruby repo = Octokit.repo 'pengwynn/pingwynn' rel = repo.rels[:issues] # => # # Get a page of issues rel.get.data # Get issue #2 rel.get(:uri => {:number => 2}).data ``` ### The Full Hypermedia Experience™ If you want to use Octokit as a pure hypermedia API client, you can start at the API root and follow link relations from there: ```ruby root = Octokit.root root.rels[:repository].get :uri => {:owner => "octokit", :repo => "octokit.rb" } ``` Octokit 3.0 aims to be hypermedia-driven, removing the internal URL construction currently used throughout the client. [hypermedia]: http://en.wikipedia.org/wiki/Hypermedia [Sawyer]: https://github.com/lostisland/sawyer [Faraday]: https://github.com/lostisland/faraday [uri-templates]: http://tools.ietf.org/html/rfc6570 ## Upgrading guide Version 3.0 includes a couple breaking changes when upgrading from v2.x.x: The [default media type][default-media-type] is now `v3` instead of `beta`. If you need to request the older media type, you can set the default media type for the client: ```ruby Octokit.default_media_type = "application/vnd.github.beta+json" ``` or per-request ```ruby Octokit.emails(:accept => "application/vnd.github.beta+json") ``` The long-deprecated `Octokit::Client#create_download` method has been removed. [default-media-type]: https://developer.github.com/changes/2014-01-07-upcoming-change-to-default-media-type/ ### Upgrading from 1.x.x Version 2.0 includes a completely rewritten `Client` factory that now memoizes client instances based on unique configuration options. Breaking changes also include: * `:oauth_token` is now `:access_token` * `:auto_traversal` is now `:auto_paginate` * `Hashie::Mash` has been removed. Responses now return a `Sawyer::Resource` object. This new type behaves mostly like a Ruby `Hash`, but does not fully support the `Hashie::Mash` API. * Two new client error types are raised where appropriate: `Octokit::TooManyRequests` and `Octokit::TooManyLoginAttempts` * The `search_*` methods from v1.x are now found at `legacy_search_*` * Support for netrc requires including the [netrc gem][] in your Gemfile or gemspec. * DateTime fields are now proper `DateTime` objects. Previous versions outputted DateTime fields as 'String' objects. [netrc gem]: https://rubygems.org/gems/netrc ## Advanced usage Since Octokit employs [Faraday][faraday] under the hood, some behavior can be extended via middleware. ### Debugging Often, it helps to know what Octokit is doing under the hood. You can add a logger to the middleware that enables you to peek into the underlying HTTP traffic: ```ruby stack = Faraday::RackBuilder.new do |builder| builder.response :logger builder.use Octokit::Response::RaiseError builder.adapter Faraday.default_adapter end Octokit.middleware = stack Octokit.user 'pengwynn' ``` ``` I, [2013-08-22T15:54:38.583300 #88227] INFO -- : get https://api.github.com/users/pengwynn D, [2013-08-22T15:54:38.583401 #88227] DEBUG -- request: Accept: "application/vnd.github.beta+json" User-Agent: "Octokit Ruby Gem 2.0.0.rc4" I, [2013-08-22T15:54:38.843313 #88227] INFO -- Status: 200 D, [2013-08-22T15:54:38.843459 #88227] DEBUG -- response: server: "GitHub.com" date: "Thu, 22 Aug 2013 20:54:40 GMT" content-type: "application/json; charset=utf-8" transfer-encoding: "chunked" connection: "close" status: "200 OK" x-ratelimit-limit: "60" x-ratelimit-remaining: "39" x-ratelimit-reset: "1377205443" ... ``` See the [Faraday README][faraday] for more middleware magic. ### Caching If you want to boost performance, stretch your API rate limit, or avoid paying the hypermedia tax, you can use [Faraday Http Cache][cache]. Add the gem to your Gemfile gem 'faraday-http-cache' Next, construct your own Faraday middleware: ```ruby stack = Faraday::RackBuilder.new do |builder| builder.use Faraday::HttpCache builder.use Octokit::Response::RaiseError builder.adapter Faraday.default_adapter end Octokit.middleware = stack ``` Once configured, the middleware will store responses in cache based on ETag fingerprint and serve those back up for future `304` responses for the same resource. See the [project README][cache] for advanced usage. [cache]: https://github.com/plataformatec/faraday-http-cache [faraday]: https://github.com/lostisland/faraday ## Hacking on Octokit.rb If you want to hack on Octokit locally, we try to make [bootstrapping the project][bootstrapping] as painless as possible. To start hacking, clone and run: script/bootstrap This will install project dependencies and get you up and running. If you want to run a Ruby console to poke on Octokit, you can crank one up with: script/console Using the scripts in `./scripts` instead of `bundle exec rspec`, `bundle console`, etc. ensures your dependencies are up-to-date. ### Running and writing new tests Octokit uses [VCR][] for recording and playing back API fixtures during test runs. These cassettes (fixtures) are part of the Git project in the `spec/cassettes` folder. If you're not recording new cassettes you can run the specs with existing cassettes with: script/test Octokit uses environmental variables for storing credentials used in testing. If you are testing an API endpoint that doesn't require authentication, you can get away without any additional configuration. For the most part, tests use an authenticated client, using a token stored in `ENV['OCTOKIT_TEST_GITHUB_TOKEN']`. There are several different authenticating method's used across the api. Here is the full list of configurable environmental variables for testing Octokit: ENV Variable | Description | :-------------------|:-----------------| `OCTOKIT_TEST_GITHUB_LOGIN`| GitHub login name (preferably one created specifically for testing against). `OCTOKIT_TEST_GITHUB_PASSWORD`| Password for the test GitHub login. `OCTOKIT_TEST_GITHUB_TOKEN` | [Personal Access Token](https://github.com/blog/1509-personal-api-tokens) for the test GitHub login. `OCTOKIT_TEST_GITHUB_CLIENT_ID` | Test OAuth application client id. `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. Since we periodically refresh our cassettes, please keep some points in mind when writing new specs. * **Specs should be idempotent**. The HTTP calls made during a spec should be able to be run over and over. This means deleting a known resource prior to creating it if the name has to be unique. * **Specs should be able to be run in random order.** If a spec depends on another resource as a fixture, make sure that's created in the scope of the spec and not depend on a previous spec to create the data needed. * **Do not depend on authenticated user info.** Instead of asserting actual values in resources, try to assert the existence of a key or that a response is an Array. We're testing the client, not the API. [bootstrapping]: http://wynnnetherland.com/linked/2013012801/bootstrapping-consistency [VCR]: https://github.com/vcr/vcr ## Supported Ruby Versions This library aims to support and is [tested against][travis] the following Ruby implementations: * Ruby 1.9.2 * Ruby 1.9.3 * Ruby 2.0.0 * Ruby 2.1.0 If something doesn't work on one of these Ruby versions, it's a bug. This library may inadvertently work (or seem to work) on other Ruby implementations, but support will only be provided for the versions listed above. If you would like this library to support another Ruby version, you may volunteer to be a maintainer. Being a maintainer entails making sure all tests run and pass on that implementation. When something breaks on your implementation, you will be responsible for providing patches in a timely fashion. If critical issues for a particular implementation exist at the time of a major release, support for that Ruby version may be dropped. [travis]: https://travis-ci.org/octokit/octokit.rb ## Versioning This library aims to adhere to [Semantic Versioning 2.0.0][semver]. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, that version should be immediately yanked and/or a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions. As a result of this policy, you can (and should) specify a dependency on this gem using the [Pessimistic Version Constraint][pvc] with two digits of precision. For example: spec.add_dependency 'octokit', '~> 3.0' [semver]: http://semver.org/ [pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint ## License Copyright (c) 2009-2014 Wynn Netherland, Adam Stacoviak, Erik Michaels-Ober Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. octokit-3.8.0/.document0000644000004100000410000000006512511016543015044 0ustar www-datawww-datalib/**/*.rb bin/* features/**/*.feature - LICENSE.md