Class: Github::Repos
- Inherits:
-
API
- Object
- API
- Github::Repos
- Extended by:
- AutoloadHelper
- Defined in:
- lib/github_api/repos.rb
Defined Under Namespace
Classes: Collaborators, Comments, Commits, Contents, Downloads, Forks, Hooks, Keys, Merging, PubSubHubbub, Statistics, Statuses
Constant Summary
- 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)
-
- (Object) branch(*args)
Get branch.
-
- (Object) branches(*args)
(also: #list_branches)
List branches.
-
- (Object) collaborators(options = {}, &block)
Access to Repos::Collaborators API.
-
- (Object) comments(options = {}, &block)
Access to Repos::Comments API.
-
- (Object) commits(options = {}, &block)
Access to Repos::Commits API.
-
- (Object) contents(options = {}, &block)
Access to Repos::Contents API.
-
- (Object) contributors(*args)
(also: #list_contributors, #contribs)
List contributors.
-
- (Object) create(*args)
Create a new repository for the autheticated user.
-
- (Object) delete(*args)
(also: #remove)
Delete a repository.
-
- (Object) downloads(options = {}, &block)
Access to Repos::Downloads API.
-
- (Object) edit(*args)
Edit a repository.
-
- (Object) forks(options = {}, &block)
Access to Repos::Forks API.
-
- (Object) get(*args)
(also: #find)
Get a repository.
-
- (Object) hooks(options = {}, &block)
Access to Repos::Hooks API.
-
- (Object) keys(options = {}, &block)
Access to Repos::Keys API.
-
- (Object) languages(*args)
(also: #list_languages)
List languages.
-
- (Object) list(*args)
(also: #all)
List repositories for the authenticated user.
-
- (Object) merging(options = {}, &block)
Access to Repos::Merging API.
-
- (Object) pubsubhubbub(options = {}, &block)
Access to Repos::PubSubHubbub API.
-
- (Object) stats(options = {}, &block)
Access to Repos::Statistics API.
-
- (Object) statuses(options = {}, &block)
Access to Repos::Statuses API.
-
- (Object) tags(*args)
(also: #list_tags, #repo_tags, #repository_tags)
List tags.
-
- (Object) teams(*args)
(also: #list_teams, #repo_teams, #repository_teams)
List teams.
Methods included from AutoloadHelper
autoload_all, lookup_constant, register_constant
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
- (Object) branch(*args)
Get branch
Examples
github = Github.new
github.repos.branch 'user-name', 'repo-name', 'branch-name'
github.repos.branch user: 'user-name', repo: 'repo-name', branch: 'branch-name'
github.repos(user: 'user-name', repo: 'repo-name', branch: 'branch-name').branch
344 345 346 347 348 349 |
# File 'lib/github_api/repos.rb', line 344 def branch(*args) arguments(args, :required => [:user, :repo, :branch]) params = arguments.params get_request("/repos/#{user}/#{repo}/branches/#{branch}", params) end |
- (Object) branches(*args) Also known as: list_branches
List branches
Examples
github = Github.new
github.repos.branches 'user-name', 'repo-name'
github.repos(user: 'user-name', repo: 'repo-name').branches
repos = Github::Repos.new
repos.branches 'user-name', 'repo-name'
def branches(user_name, repo_name, params={})
325 326 327 328 329 330 331 332 |
# File 'lib/github_api/repos.rb', line 325 def branches(*args) arguments(args, :required => [:user, :repo]) params = arguments.params response = get_request("/repos/#{user}/#{repo}/branches", arguments.params) return response unless block_given? response.each { |el| yield el } end |
- (Object) collaborators(options = {}, &block)
Access to Repos::Collaborators API
49 50 51 |
# File 'lib/github_api/repos.rb', line 49 def collaborators(={}, &block) @collaborators ||= ApiFactory.new('Repos::Collaborators', .merge(), &block) end |
- (Object) comments(options = {}, &block)
Access to Repos::Comments API
54 55 56 |
# File 'lib/github_api/repos.rb', line 54 def comments(={}, &block) @commits ||= ApiFactory.new('Repos::Comments', .merge(), &block) end |
- (Object) commits(options = {}, &block)
Access to Repos::Commits API
59 60 61 |
# File 'lib/github_api/repos.rb', line 59 def commits(={}, &block) @commits ||= ApiFactory.new('Repos::Commits', .merge(), &block) end |
- (Object) contents(options = {}, &block)
Access to Repos::Contents API
64 65 66 |
# File 'lib/github_api/repos.rb', line 64 def contents(={}, &block) @contents ||= ApiFactory.new('Repos::Contents', .merge(), &block) end |
- (Object) contributors(*args) 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| ... }
252 253 254 255 256 257 258 259 260 261 |
# File 'lib/github_api/repos.rb', line 252 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 |
- (Object) create(*args)
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'
209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/github_api/repos.rb', line 209 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")) post_request("/orgs/#{org}/repos", params.merge_default(DEFAULT_REPO_OPTIONS)) else post_request("/user/repos", params.merge_default(DEFAULT_REPO_OPTIONS)) end end |
- (Object) delete(*args) Also known as: remove
Delete a repository
Deleting a repository requires admin access. If OAuth is used, the delete_repo scope is required.
Examples
github = Github.new :oauth_token => '...'
github.repos.delete 'user-name', 'repo-name'
233 234 235 236 237 238 |
# File 'lib/github_api/repos.rb', line 233 def delete(*args) arguments(args, :required => [:user, :repo]) params = arguments.params delete_request("/repos/#{user}/#{repo}", params) end |
- (Object) downloads(options = {}, &block)
Access to Repos::Downloads API
69 70 71 |
# File 'lib/github_api/repos.rb', line 69 def downloads(={}, &block) @downloads ||= ApiFactory.new('Repos::Downloads', .merge(), &block) end |
- (Object) edit(*args)
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 is true
-
: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
286 287 288 289 290 291 292 293 294 |
# File 'lib/github_api/repos.rb', line 286 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 |
- (Object) forks(options = {}, &block)
Access to Repos::Forks API
74 75 76 |
# File 'lib/github_api/repos.rb', line 74 def forks(={}, &block) @forks ||= ApiFactory.new('Repos::Forks', .merge(), &block) end |
- (Object) get(*args) Also known as: find
Get a repository
Examples
github = Github.new
github.repos.get 'user-name', 'repo-name'
github.repos.get user: 'user-name', repo: 'repo-name'
github.repos(user: 'user-name', repo: 'repo-name').get
169 170 171 172 173 174 |
# File 'lib/github_api/repos.rb', line 169 def get(*args) arguments(args, :required => [:user, :repo]) params = arguments.params get_request("/repos/#{user}/#{repo}", params) end |
- (Object) hooks(options = {}, &block)
Access to Repos::Hooks API
79 80 81 |
# File 'lib/github_api/repos.rb', line 79 def hooks(={}, &block) @hooks ||= ApiFactory.new('Repos::Hooks', .merge(), &block) end |
- (Object) keys(options = {}, &block)
Access to Repos::Keys API
84 85 86 |
# File 'lib/github_api/repos.rb', line 84 def keys(={}, &block) @keys ||= ApiFactory.new('Repos::Keys', .merge(), &block) end |
- (Object) languages(*args) 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| ... }
382 383 384 385 386 387 388 389 |
# File 'lib/github_api/repos.rb', line 382 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 |
- (Object) list(*args) 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: true
github.repos.list every: true { |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| ... }
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/github_api/repos.rb', line 140 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"))) get_request("/users/#{user_name}/repos", params) elsif (org_name = (params.delete("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 |
- (Object) merging(options = {}, &block)
Access to Repos::Merging API
89 90 91 |
# File 'lib/github_api/repos.rb', line 89 def merging(={}, &block) @mergin ||= ApiFactory.new('Repos::Merging', .merge(), &block) end |
- (Object) pubsubhubbub(options = {}, &block)
Access to Repos::PubSubHubbub API
94 95 96 |
# File 'lib/github_api/repos.rb', line 94 def pubsubhubbub(={}, &block) @pubsubhubbub ||= ApiFactory.new('Repos::PubSubHubbub', .merge(), &block) end |
- (Object) stats(options = {}, &block)
Access to Repos::Statistics API
99 100 101 |
# File 'lib/github_api/repos.rb', line 99 def stats(={}, &block) @stats ||= ApiFactory.new('Repos::Statistics', .merge(), &block) end |
- (Object) statuses(options = {}, &block)
Access to Repos::Statuses API
104 105 106 |
# File 'lib/github_api/repos.rb', line 104 def statuses(={}, &block) @statuses ||= ApiFactory.new('Repos::Statuses', .merge(), &block) end |
- (Object) tags(*args) Also known as: , ,
List tags
Examples
github = Github.new
github.repos.tags 'user-name', 'repo-name'
github.repos.tags 'user-name', 'repo-name' { |tag| ... }
399 400 401 402 403 404 405 406 |
# File 'lib/github_api/repos.rb', line 399 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 |
- (Object) teams(*args) 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
420 421 422 423 424 425 426 427 |
# File 'lib/github_api/repos.rb', line 420 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 |