Class: Github::Repos
Defined Under Namespace
Classes: Collaborators, Comments, Commits, Contents, Downloads, Forks, Hooks, Keys, Merging, Pages, PubSubHubbub, Releases, Statistics, Statuses
Constant Summary collapse
- DEFAULT_REPO_OPTIONS =
{ "homepage" => "https://github.com", "private" => false, "has_issues" => true, "has_wiki" => true, "has_downloads" => true }.freeze
- REQUIRED_REPO_OPTIONS =
%w[ name ]
- VALID_REPO_OPTIONS =
%w[ name description homepage private has_issues has_wiki has_downloads team_id auto_init gitignore_template default_branch ].freeze
- VALID_REPO_TYPES =
%w[ all public private member ].freeze
Constants included from Request
Github::Request::METHODS, Github::Request::METHODS_WITH_BODIES
Constants included from Connection
Constants included from Constants
Constants::ACCEPT, Constants::ACCEPTED_OAUTH_SCOPES, Constants::ACCEPT_CHARSET, Constants::CACHE_CONTROL, Constants::CONTENT_LENGTH, Constants::CONTENT_TYPE, Constants::DATE, Constants::ETAG, Constants::HEADER_LAST, Constants::HEADER_LINK, Constants::HEADER_NEXT, Constants::LOCATION, Constants::META_FIRST, Constants::META_LAST, Constants::META_NEXT, Constants::META_PREV, Constants::META_REL, Constants::OAUTH_SCOPES, Constants::PARAM_PAGE, Constants::PARAM_PER_PAGE, Constants::PARAM_START_PAGE, Constants::RATELIMIT_LIMIT, Constants::RATELIMIT_REMAINING, Constants::SERVER, Constants::USER_AGENT
Constants included from MimeType
Instance Attribute Summary
Attributes inherited from API
Attributes included from Authorization
Instance Method Summary collapse
-
#branch(*args) ⇒ Object
Get branch.
-
#branches(*args) ⇒ Object
(also: #list_branches)
List branches.
-
#collaborators(options = {}, &block) ⇒ Object
Access to Repos::Collaborators API.
-
#comments(options = {}, &block) ⇒ Object
Access to Repos::Comments API.
-
#commits(options = {}, &block) ⇒ Object
Access to Repos::Commits API.
-
#contents(options = {}, &block) ⇒ Object
Access to Repos::Contents API.
-
#contributors(*args) ⇒ Object
(also: #list_contributors, #contribs)
List contributors.
-
#create(*args) ⇒ Object
Create a new repository for the autheticated user.
-
#delete(*args) ⇒ Object
(also: #remove)
Delete a repository.
-
#downloads(options = {}, &block) ⇒ Object
Access to Repos::Downloads API.
-
#edit(*args) ⇒ Object
Edit a repository.
-
#forks(options = {}, &block) ⇒ Object
Access to Repos::Forks API.
-
#get(*args) ⇒ Object
(also: #find)
Get a repository.
-
#hooks(options = {}, &block) ⇒ Object
Access to Repos::Hooks API.
-
#keys(options = {}, &block) ⇒ Object
Access to Repos::Keys API.
-
#languages(*args) ⇒ Object
(also: #list_languages)
List languages.
-
#list(*args) ⇒ Object
(also: #all)
List repositories for the authenticated user.
-
#merging(options = {}, &block) ⇒ Object
Access to Repos::Merging API.
-
#pages(options = {}, &block) ⇒ Object
Access to Repos::Pages API.
-
#pubsubhubbub(options = {}, &block) ⇒ Object
Access to Repos::PubSubHubbub API.
-
#releases(options = {}, &block) ⇒ Object
Access to Repos::Releases API.
-
#stats(options = {}, &block) ⇒ Object
Access to Repos::Statistics API.
-
#statuses(options = {}, &block) ⇒ Object
Access to Repos::Statuses API.
-
#tags(*args) ⇒ Object
(also: #list_tags, #repo_tags, #repository_tags)
List tags.
-
#teams(*args) ⇒ Object
(also: #list_teams, #repo_teams, #repository_teams)
List teams.
Methods inherited from API
#api_methods_in, #append_arguments, #arguments, inherited, #initialize, #method_missing, #process_basic_auth, #set, #setup, #with, #yield_or_eval
Methods included from RateLimit
#ratelimit, #ratelimit_remaining
Methods included from Request
#delete_request, #get_request, #patch_request, #post_request, #put_request, #request
Methods included from Connection
#caching?, #clear_cache, #connection, #default_middleware, #default_options, #stack
Methods included from MimeType
Methods included from Authorization
#auth_code, #authenticated?, #authentication, #authorize_url, #basic_authed?, #client, #get_token
Constructor Details
This class inherits a constructor from Github::API
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Github::API
Instance Method Details
#branch(*args) ⇒ Object
360 361 362 363 364 365 |
# File 'lib/github_api/repos.rb', line 360 def branch(*args) arguments(args, :required => [:user, :repo, :branch]) params = arguments.params get_request("/repos/#{user}/#{repo}/branches/#{branch}", params) end |
#branches(*args) ⇒ Object Also known as: list_branches
342 343 344 345 346 347 348 |
# File 'lib/github_api/repos.rb', line 342 def branches(*args) arguments(args, :required => [:user, :repo]) response = get_request("/repos/#{user}/#{repo}/branches", arguments.params) return response unless block_given? response.each { |el| yield el } end |
#collaborators(options = {}, &block) ⇒ Object
Access to Repos::Collaborators API
50 51 52 |
# File 'lib/github_api/repos.rb', line 50 def collaborators(={}, &block) @collaborators ||= ApiFactory.new('Repos::Collaborators', .merge(), &block) end |
#comments(options = {}, &block) ⇒ Object
Access to Repos::Comments API
55 56 57 |
# File 'lib/github_api/repos.rb', line 55 def comments(={}, &block) @comments ||= ApiFactory.new('Repos::Comments', .merge(), &block) end |
#commits(options = {}, &block) ⇒ Object
Access to Repos::Commits API
60 61 62 |
# File 'lib/github_api/repos.rb', line 60 def commits(={}, &block) @commits ||= ApiFactory.new('Repos::Commits', .merge(), &block) end |
#contents(options = {}, &block) ⇒ Object
Access to Repos::Contents API
65 66 67 |
# File 'lib/github_api/repos.rb', line 65 def contents(={}, &block) @contents ||= ApiFactory.new('Repos::Contents', .merge(), &block) end |
#contributors(*args) ⇒ Object Also known as: list_contributors, contribs
List contributors
Parameters
<tt>:anon</tt> - Optional flag. Set to 1 or true to include anonymous contributors.
Examples
github = Github.new
github.repos.contributors 'user-name','repo-name'
github.repos.contributors 'user-name','repo-name' { |cont| ... }
269 270 271 272 273 274 275 276 277 278 |
# File 'lib/github_api/repos.rb', line 269 def contributors(*args) arguments(args, :required => [:user, :repo]) do sift %w[ anon ] end params = arguments.params response = get_request("/repos/#{user}/#{repo}/contributors", params) return response unless block_given? response.each { |el| yield el } end |
#create(*args) ⇒ Object
Create a new repository for the autheticated user.
Parameters
<tt>:name</tt> - Required string
<tt>:description</tt> - Optional string
<tt>:homepage</tt> - Optional string
<tt>:private</tt> - Optional boolean - <tt>true</tt> to create a private
repository, <tt>false</tt> to create a public one.
<tt>:has_issues</tt> - Optional boolean - <tt>true</tt> to enable issues
for this repository, <tt>false</tt> to disable them
<tt>:has_wiki</tt> - Optional boolean - <tt>true</tt> to enable the wiki
for this repository, <tt>false</tt> to disable it.
Default is <tt>true</tt>
<tt>:has_downloads</tt> - Optional boolean - <tt>true</tt> to enable
downloads for this repository
<tt>:org</tt> Optional string - The organisation in which this repository
will be created
<tt>:team_id</tt> Optional number - The id of the team that will be granted access to this repository. This is only valid when creating a repo in an organization
<tt>:auto_init</tt> Optional boolean - true to create an initial commit with empty README. Default is false.
<tt>:gitignore_template</tt> Optional string - Desired language or platform .gitignore template to apply. Use the name of the template without the extension. For example, “Haskell” Ignored if auto_init parameter is not provided.
Examples
github = Github.new
github.repos.create "name": 'repo-name'
"description": "This is your first repo",
"homepage": "https://github.com",
"private": false,
"has_issues": true,
"has_wiki": true,
"has_downloads": true
Create a new repository in this organisation. The authenticated user must be a member of this organisation
Examples:
github = Github.new :oauth_token => '...'
github.repos.create :name => 'repo-name', :org => 'organisation-name'
226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/github_api/repos.rb', line 226 def create(*args) arguments(args) do sift VALID_REPO_OPTIONS + %w[ org ] assert_required %w[ name ] end params = arguments.params # Requires authenticated user if (org = params.delete('org') || org) post_request("/orgs/#{org}/repos", params.merge_default(DEFAULT_REPO_OPTIONS)) else post_request('/user/repos', params.merge_default(DEFAULT_REPO_OPTIONS)) end end |
#delete(*args) ⇒ Object Also known as: remove
250 251 252 253 254 255 |
# File 'lib/github_api/repos.rb', line 250 def delete(*args) arguments(args, :required => [:user, :repo]) params = arguments.params delete_request("/repos/#{user}/#{repo}", params) end |
#downloads(options = {}, &block) ⇒ Object
Access to Repos::Downloads API
70 71 72 |
# File 'lib/github_api/repos.rb', line 70 def downloads(={}, &block) @downloads ||= ApiFactory.new('Repos::Downloads', .merge(), &block) end |
#edit(*args) ⇒ Object
Edit a repository
Parameters
-
:name
Required string -
:description
Optional string -
:homepage
Optional string
<tt>:private</tt> - Optional boolean - <tt>false</tt> to create public reps, <tt>false</tt> to create a private one
-
:has_issues
Optional boolean -true
to enable issues for this repository,false
to disable them -
:has_wiki
Optional boolean -true
to enable the wiki for this repository,false
to disable it. Default istrue
-
:has_downloads
Optional boolean -true
to enable downloads for this repository -
:default_branch
Optional string - Update the default branch for this repository.
Examples
github = Github.new
github.repos.edit 'user-name', 'repo-name',
:name => 'hello-world',
:description => 'This is your first repo',
:homepage => "https://github.com",
:public => true, :has_issues => true
303 304 305 306 307 308 309 310 311 |
# File 'lib/github_api/repos.rb', line 303 def edit(*args) arguments(args, :required => [:user, :repo]) do sift VALID_REPO_OPTIONS assert_required %w[ name ] end params = arguments.params patch_request("/repos/#{user}/#{repo}", params.merge_default(DEFAULT_REPO_OPTIONS)) end |
#forks(options = {}, &block) ⇒ Object
Access to Repos::Forks API
75 76 77 |
# File 'lib/github_api/repos.rb', line 75 def forks(={}, &block) @forks ||= ApiFactory.new('Repos::Forks', .merge(), &block) end |
#get(*args) ⇒ Object Also known as: find
180 181 182 183 184 185 |
# File 'lib/github_api/repos.rb', line 180 def get(*args) arguments(args, :required => [:user, :repo]) params = arguments.params get_request("/repos/#{user}/#{repo}", params) end |
#hooks(options = {}, &block) ⇒ Object
Access to Repos::Hooks API
80 81 82 |
# File 'lib/github_api/repos.rb', line 80 def hooks(={}, &block) @hooks ||= ApiFactory.new('Repos::Hooks', .merge(), &block) end |
#keys(options = {}, &block) ⇒ Object
Access to Repos::Keys API
85 86 87 |
# File 'lib/github_api/repos.rb', line 85 def keys(={}, &block) @keys ||= ApiFactory.new('Repos::Keys', .merge(), &block) end |
#languages(*args) ⇒ Object Also known as: list_languages
List languages
Examples
github = Github.new
github.repos.languages 'user-name', 'repo-name'
github.repos.languages 'user-name', 'repo-name' { |lang| ... }
398 399 400 401 402 403 404 405 |
# File 'lib/github_api/repos.rb', line 398 def languages(*args) arguments(args, :required => [:user, :repo]) params = arguments.params response = get_request("/repos/#{user}/#{repo}/languages", params) return response unless block_given? response.each { |el| yield el } end |
#list(*args) ⇒ Object Also known as: all
List repositories for the authenticated user
Examples
github = Github.new :oauth_token => '...'
github.repos.list
github.repos.list { |repo| ... }
List all repositories
This provides a dump of every repository, in the order that they were created.
Parameters
-
:since
- the integer ID of the last Repository that you’ve seen.
Examples
github = Github.new
github.repos.list :every
github.repos.list :every { |repo| ... }
List public repositories for the specified user.
Examples
github = Github.new
github.repos.list user: 'user-name'
github.repos.list user: 'user-name', { |repo| ... }
List repositories for the specified organisation.
Examples
github = Github.new
github.repos.list org: 'org-name'
github.repos.list org: 'org-name', { |repo| ... }
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/github_api/repos.rb', line 151 def list(*args) arguments(args) do sift %w[ user org type sort direction since ] end params = arguments.params response = if (user_name = params.delete('user') || user) get_request("/users/#{user_name}/repos", params) elsif (org_name = params.delete('org') || org) get_request("/orgs/#{org_name}/repos", params) elsif args.map(&:to_s).include?('every') get_request('/repositories', params) else # For authenticated user get_request('/user/repos', params) end return response unless block_given? response.each { |el| yield el } end |
#merging(options = {}, &block) ⇒ Object
Access to Repos::Merging API
90 91 92 |
# File 'lib/github_api/repos.rb', line 90 def merging(={}, &block) @merging ||= ApiFactory.new('Repos::Merging', .merge(), &block) end |
#pages(options = {}, &block) ⇒ Object
Access to Repos::Pages API
95 96 97 |
# File 'lib/github_api/repos.rb', line 95 def pages(={}, &block) @pages ||= ApiFactory.new('Repos::Pages', .merge(), &block) end |
#pubsubhubbub(options = {}, &block) ⇒ Object
Access to Repos::PubSubHubbub API
100 101 102 |
# File 'lib/github_api/repos.rb', line 100 def pubsubhubbub(={}, &block) @pubsubhubbub ||= ApiFactory.new('Repos::PubSubHubbub', .merge(), &block) end |
#releases(options = {}, &block) ⇒ Object
Access to Repos::Releases API
105 106 107 |
# File 'lib/github_api/repos.rb', line 105 def releases(={}, &block) @releases ||= ApiFactory.new('Repos::Releases', .merge(), &block) end |
#stats(options = {}, &block) ⇒ Object
Access to Repos::Statistics API
110 111 112 |
# File 'lib/github_api/repos.rb', line 110 def stats(={}, &block) @stats ||= ApiFactory.new('Repos::Statistics', .merge(), &block) end |
#statuses(options = {}, &block) ⇒ Object
Access to Repos::Statuses API
115 116 117 |
# File 'lib/github_api/repos.rb', line 115 def statuses(={}, &block) @statuses ||= ApiFactory.new('Repos::Statuses', .merge(), &block) end |
#tags(*args) ⇒ Object Also known as: , ,
List tags
Examples
github = Github.new
github.repos.tags 'user-name', 'repo-name'
github.repos.tags 'user-name', 'repo-name' { |tag| ... }
415 416 417 418 419 420 421 422 |
# File 'lib/github_api/repos.rb', line 415 def (*args) arguments(args, :required => [:user, :repo]) params = arguments.params response = get_request("/repos/#{user}/#{repo}/tags", params) return response unless block_given? response.each { |el| yield el } end |
#teams(*args) ⇒ Object Also known as: list_teams, repo_teams, repository_teams
List teams
Examples
github = Github.new
github.repos.teams 'user-name', 'repo-name'
github.repos.teams 'user-name', 'repo-name' { |team| ... }
github.repos(user: 'user-name, repo: 'repo-name').teams
436 437 438 439 440 441 442 443 |
# File 'lib/github_api/repos.rb', line 436 def teams(*args) arguments(args, :required => [:user, :repo]) params = arguments.params response = get_request("/repos/#{user}/#{repo}/teams", params) return response unless block_given? response.each { |el| yield el } end |