Class: Github::Client::Repos

Inherits:
API
  • Object
show all
Defined in:
lib/github_api/client/repos.rb

Defined Under Namespace

Classes: Collaborators, Comments, Commits, Contents, Deployments, 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 MimeType

MimeType::MEDIA_LOOKUP

Constants included from Github::Constants

Github::Constants::ACCEPT, Github::Constants::ACCEPTED_OAUTH_SCOPES, Github::Constants::ACCEPT_CHARSET, Github::Constants::CACHE_CONTROL, Github::Constants::CONTENT_LENGTH, Github::Constants::CONTENT_TYPE, Github::Constants::DATE, Github::Constants::ETAG, Github::Constants::HEADER_LAST, Github::Constants::HEADER_LINK, Github::Constants::HEADER_NEXT, Github::Constants::LOCATION, Github::Constants::META_FIRST, Github::Constants::META_LAST, Github::Constants::META_NEXT, Github::Constants::META_PREV, Github::Constants::META_REL, Github::Constants::OAUTH_SCOPES, Github::Constants::PARAM_PAGE, Github::Constants::PARAM_PER_PAGE, Github::Constants::PARAM_START_PAGE, Github::Constants::RATELIMIT_LIMIT, Github::Constants::RATELIMIT_REMAINING, Github::Constants::RATELIMIT_RESET, Github::Constants::SERVER, Github::Constants::USER_AGENT

Instance Attribute Summary

Attributes inherited from API

#current_options

Instance Method Summary collapse

Methods inherited from API

after_callbacks, after_request, #api_methods_in, #arguments, before_callbacks, before_request, clear_request_methods!, #execute, extend_with_actions, extra_methods, #extract_basic_auth, extract_class_name, #filter_callbacks, inherited, #initialize, internal_methods, method_added, #method_missing, #module_methods_in, namespace, request_methods, root!, #run_callbacks, #set, #yield_or_eval

Methods included from Github::ClassMethods

#configuration, #configure, #require_all

Methods included from RateLimit

#ratelimit, #ratelimit_remaining, #ratelimit_reset

Methods included from Request::Verbs

#delete_request, #get_request, #head_request, #options_request, #patch_request, #post_request, #put_request

Methods included from MimeType

#lookup_media, #parse

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

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

366
367
368
369
370
# File 'lib/github_api/client/repos.rb', line 366

def branch(*args)
  arguments(args, required: [:user, :repo, :branch])

  get_request("/repos/#{arguments.user}/#{arguments.repo}/branches/#{arguments.branch}", arguments.params)
end

#branches(*args) ⇒ Object 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'

349
350
351
352
353
354
355
# File 'lib/github_api/client/repos.rb', line 349

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

#contributors(*args) ⇒ Object Also known as: list_contributors, contribs

List contributors

Examples:

github = Github.new
github.repos.contributors 'user-name','repo-name'
github.repos.contributors 'user-name','repo-name' { |cont| ... }

267
268
269
270
271
272
273
274
275
276
# File 'lib/github_api/client/repos.rb', line 267

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(*args) ⇒ Object

Create a new repository for the autheticated user.

Create a new repository in this organisation. The authenticated user must be a member of this organisation

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
github = Github.new oauth_token: '...'
github.repos.create name: 'repo-name', org: 'organisation-name'

223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/github_api/client/repos.rb', line 223

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(*args) ⇒ Object 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'

248
249
250
251
252
# File 'lib/github_api/client/repos.rb', line 248

def delete(*args)
  arguments(args, required: [:user, :repo])

  delete_request("/repos/#{arguments.user}/#{arguments.repo}", arguments.params)
end

#edit(*args) ⇒ Object

Edit a 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

310
311
312
313
314
315
316
317
# File 'lib/github_api/client/repos.rb', line 310

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(*args) ⇒ Object 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

162
163
164
165
166
# File 'lib/github_api/client/repos.rb', line 162

def get(*args)
  arguments(args, required: [:user, :repo])

  get_request("/repos/#{arguments.user}/#{arguments.repo}", arguments.params)
end

#languages(*args) ⇒ Object Also known as: list_languages

List languages


404
405
406
407
408
409
410
# File 'lib/github_api/client/repos.rb', line 404

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(*args) ⇒ Object Also known as: all

List repositories for the authenticated user

List all repositories

This provides a dump of every repository, in the order that they were created.

List public repositories for the specified user.

List repositories for the specified organisation.

Examples:

github = Github.new oauth_token: '...'
github.repos.list
github.repos.list { |repo| ... }
github = Github.new
github.repos.list :every
github.repos.list :every { |repo| ... }
github = Github.new
github.repos.list user: 'user-name'
github.repos.list user: 'user-name', { |repo| ... }
github = Github.new
github.repos.list org: 'org-name'
github.repos.list org: 'org-name', { |repo| ... }

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/github_api/client/repos.rb', line 130

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

#tags(*args) ⇒ Object Also known as: list_tags, repo_tags, repository_tags

List tags

Examples:

github = Github.new
github.repos.tags 'user-name', 'repo-name'
github.repos.tags 'user-name', 'repo-name' { |tag| ... }

421
422
423
424
425
426
427
# File 'lib/github_api/client/repos.rb', line 421

def tags(*args)
  arguments(args, required: [:user, :repo])

  response = get_request("/repos/#{arguments.user}/#{arguments.repo}/tags", arguments.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

443
444
445
446
447
448
449
# File 'lib/github_api/client/repos.rb', line 443

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