Class: Github::Client::Repos

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

Defined Under Namespace

Classes: Branches, Collaborators, Comments, Commits, Contents, Deployments, Downloads, Forks, Hooks, Invitations, Keys, Merging, Pages, Projects, PubSubHubbub, Releases, Statistics, Statuses

Constant Summary collapse

REQUIRED_REPO_OPTIONS =
%w[ name ]
VALID_REPO_OPTIONS =
%w[
  name
  description
  homepage
  private
  has_issues
  has_projects
  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!, #disable_redirects, #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, require_all, #respond_to?, root!, #run_callbacks, #set, #yield_or_eval

Methods included from Request::Verbs

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

Methods included from RateLimit

#ratelimit, #ratelimit_remaining, #ratelimit_reset

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

#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| ... }

Parameters:



288
289
290
291
292
293
294
295
296
# File 'lib/github_api/client/repos.rb', line 288

def contributors(*args)
  arguments(args, required: [:user, :repo]) do
    permit %w[ anon ]
  end

  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 authenticated 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'

Parameters:



245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/github_api/client/repos.rb', line 245

def create(*args)
  arguments(args) do
    assert_required %w[ name ]
  end
  params = arguments.params

  # Requires authenticated user
  if (org = params.delete('org') || org)
    post_request("/orgs/#{org}/repos", params)
  else
    post_request("/user/repos", params)
  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'


269
270
271
272
273
# File 'lib/github_api/client/repos.rb', line 269

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

Parameters:



330
331
332
333
334
335
336
337
# File 'lib/github_api/client/repos.rb', line 330

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)
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


169
170
171
172
173
# File 'lib/github_api/client/repos.rb', line 169

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

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

#get_by_id(*args) ⇒ Object Also known as: find_by_id

Get a repository

Examples:

github = Github.new
github.repos.get_by_id 'repo-id'
github.repos.get_by_id id: 'repo-id'
github.repos(id: 'repo-id').get_by_id


184
185
186
187
188
# File 'lib/github_api/client/repos.rb', line 184

def get_by_id(*args)
  arguments(args, required: [:id])

  get_request("/repositories/#{arguments.id}", arguments.params)
end

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

List languages



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

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| ... }

Parameters:



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/github_api/client/repos.rb', line 137

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| ... }


440
441
442
443
444
445
446
# File 'lib/github_api/client/repos.rb', line 440

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


462
463
464
465
466
467
468
# File 'lib/github_api/client/repos.rb', line 462

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