class Github::Client::Repos
Constants
- DEFAULT_REPO_OPTIONS
- REQUIRED_REPO_OPTIONS
- VALID_REPO_OPTIONS
- VALID_REPO_TYPES
Public Instance Methods
Get branch
@example
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
@api public
# File lib/github_api/client/repos.rb, line 365 def branch(*args) arguments(args, required: [:user, :repo, :branch]) get_request("/repos/#{arguments.user}/#{arguments.repo}/branches/#{arguments.branch}", arguments.params) end
List branches
@example
github = Github.new github.repos.branches 'user-name', 'repo-name' github.repos(user: 'user-name', repo: 'repo-name').branches
@example
repos = Github::Repos.new repos.branches 'user-name', 'repo-name'
@api public
# File lib/github_api/client/repos.rb, line 348 def branches(*args) arguments(args, required: [:user, :repo]) response = get_request("/repos/#{arguments.user}/#{arguments.repo}/branches", arguments.params) return response unless block_given? response.each { |el| yield el } end
List contributors
@param [Hash] params @option params [Boolean] :anon
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| ... }
@api public
# File lib/github_api/client/repos.rb, line 266 def contributors(*args) arguments(args, required: [:user, :repo]) do permit %w[ anon ] end params = arguments.params response = get_request("/repos/#{arguments.user}/#{arguments.repo}/contributors", arguments.params) return response unless block_given? response.each { |el| yield el } end
Create a new repository for the autheticated user.
@param [Hash] params @option params [String] :name
Required string
@option params [String] :description
Optional string
@option params [String] :homepage
Optional string
@option params [Boolean] :private
Optional boolean - true to create a private repository, false to create a public one.
@option params [Boolean] :has_issues
Optional boolean - true to enable issues for this repository, false to disable them
@option params [Boolean] :has_wiki
Optional boolean - true to enable the wiki for this repository, false to disable it. Default is true
@option params [Boolean] :has_downloads
Optional boolean - true to enable downloads for this repository
@option params [String] :org
Optional string - The organisation in which this repository will be created
@option params [Numeric] :team_id
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
@option params [Boolean] :auto_init
Optional boolean - true to create an initial commit with empty README. Default is false.
@option params [String] :gitignore_template
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.
@example
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
@example
github = Github.new oauth_token: '...' github.repos.create name: 'repo-name', org: 'organisation-name'
@example
# File lib/github_api/client/repos.rb, line 222 def create(*args) arguments(args) do permit 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 a repository
Deleting a repository requires admin access. If OAuth is used, the delete_repo scope is required.
@example
github = Github.new oauth_token: '...' github.repos.delete 'user-name', 'repo-name'
@api public
# File lib/github_api/client/repos.rb, line 247 def delete(*args) arguments(args, required: [:user, :repo]) delete_request("/repos/#{arguments.user}/#{arguments.repo}", arguments.params) end
Edit a repository
@param [Hash] params @option params [String] :name
Required string
@option params [String] :description
Optional string
@option params [String] :homepage
Optional string
@option params [Boolean] :private
Optional boolean, true to make this a private repository, false to make it a public one
@option params [Boolean] :has_issues
Optional boolean - true to enable issues for this repository, false to disable them
@option params [Boolean] :has_wiki
Optional boolean - true to enable the wiki for this repository, false to disable it. Default is true
@option params [Boolean] :has_downloads
Optional boolean - true to enable downloads for this repository
@option params [String] :default_branch
Optional string - Update the default branch for this repository.
@example
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
# File lib/github_api/client/repos.rb, line 309 def edit(*args) arguments(args, required: [:user, :repo]) do permit VALID_REPO_OPTIONS assert_required %w[ name ] end patch_request("/repos/#{arguments.user}/#{arguments.repo}", arguments.params.merge_default(DEFAULT_REPO_OPTIONS)) end
Get a repository
@example
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
# File lib/github_api/client/repos.rb, line 161 def get(*args) arguments(args, required: [:user, :repo]) get_request("/repos/#{arguments.user}/#{arguments.repo}", arguments.params) end
List languages
@examples
github = Github.new github.repos.languages 'user-name', 'repo-name' github.repos.languages 'user-name', 'repo-name' { |lang| ... }
@api public
# File lib/github_api/client/repos.rb, line 403 def languages(*args) arguments(args, required: [:user, :repo]) response = get_request("/repos/#{arguments.user}/#{arguments.repo}/languages", arguments.params) return response unless block_given? response.each { |el| yield el } end
List repositories for the authenticated user
@example
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.
@param [Hash] params @option params [Integer] :since
the integer ID of the last Repository that you've seen.
@example
github = Github.new github.repos.list :every github.repos.list :every { |repo| ... }
List public repositories for the specified user.
@example
github = Github.new github.repos.list user: 'user-name' github.repos.list user: 'user-name', { |repo| ... }
List repositories for the specified organisation.
@example
github = Github.new github.repos.list org: 'org-name' github.repos.list org: 'org-name', { |repo| ... }
@api public
# File lib/github_api/client/repos.rb, line 129 def list(*args) arguments(args) do permit %w[ user org type sort direction since ] end params = arguments.params unless params.symbolize_keys[:per_page] params.merge!(Pagination.per_page_as_param(current_options[:per_page])) end 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
List teams
@example
github = Github.new github.repos.teams 'user-name', 'repo-name' github.repos.teams 'user-name', 'repo-name' { |team| ... }
@example
github.repos(user: 'user-name, repo: 'repo-name').teams
@api public
# File lib/github_api/client/repos.rb, line 442 def teams(*args) arguments(args, required: [:user, :repo]) response = get_request("/repos/#{arguments.user}/#{arguments.repo}/teams", arguments.params) return response unless block_given? response.each { |el| yield el } end