Module: Octokit::Client::Repositories

Included in:
Octokit::Client
Defined in:
lib/octokit/client/repositories.rb

Overview

Methods for the Repositories API

See Also:

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) add_collaborator(repo, collaborator, options = {}) Also known as: add_collab

Add collaborator to repo

Requires authenticated client.

Examples:

@client.add_collaborator('octokit/octokit.rb', 'holman')
@client.add_collab('octokit/octokit.rb', 'holman')

See Also:



301
302
303
# File 'lib/octokit/client/repositories.rb', line 301

def add_collaborator(repo, collaborator, options = {})
  boolean_from_response :put, "#{Repository.path repo}/collaborators/#{collaborator}", options
end

- (Sawyer::Resource) add_deploy_key(repo, title, key, options = {})

Add deploy key to a repo

Requires authenticated client.

Examples:

@client.add_deploy_key('octokit/octokit.rb', 'Staging server', 'ssh-rsa AAA...')

See Also:



233
234
235
# File 'lib/octokit/client/repositories.rb', line 233

def add_deploy_key(repo, title, key, options = {})
  post "#{Repository.path repo}/keys", options.merge(:title => title, :key => key)
end

- (Array<Sawyer::Resource>) all_repositories(options = {})

List all repositories

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

Options Hash (options):

  • :since (Integer)

    The integer ID of the last Repository that you’ve seen.

See Also:



85
86
87
# File 'lib/octokit/client/repositories.rb', line 85

def all_repositories(options = {})
  paginate 'repositories', options
end

- (Sawyer::Resource) branch(repo, branch, options = {}) Also known as: get_branch

Get a single branch from a repository

Examples:

Get branch 'master` from octokit/octokit.rb

Octokit.branch("octokit/octokit.rb", "master")

See Also:



479
480
481
# File 'lib/octokit/client/repositories.rb', line 479

def branch(repo, branch, options = {})
  get "#{Repository.path repo}/branches/#{branch}", options
end

- (Array<Sawyer::Resource>) branches(repo, options = {})

List branches

Requires authenticated client for private repos.

Examples:

Octokit.branches('octokit/octokit.rb')
@client.branches('octokit/octokit.rb')

See Also:



467
468
469
# File 'lib/octokit/client/repositories.rb', line 467

def branches(repo, options = {})
  paginate "#{Repository.path repo}/branches", options
end

- (Boolean) check_assignee(repo, assignee, options = {})

Check to see if a particular user is an assignee for a repository.

Examples:

Octokit.check_assignee('octokit/octokit.rb', 'andrew')

See Also:



644
645
646
# File 'lib/octokit/client/repositories.rb', line 644

def check_assignee(repo, assignee, options = {})
  boolean_from_response :get, "#{Repository.path repo}/assignees/#{assignee}", options
end

- (Boolean) collaborator?(repo, collaborator, options = {})

Checks if a user is a collaborator for a repo.

Requires authenticated client.

Examples:

@client.collaborator?('octokit/octokit.rb', 'holman')

See Also:



333
334
335
# File 'lib/octokit/client/repositories.rb', line 333

def collaborator?(repo, collaborator, options={})
  boolean_from_response :get, "#{Repository.path repo}/collaborators/#{collaborator}", options
end

- (Array<Sawyer::Resource>) collaborators(repo, options = {}) Also known as: collabs

List collaborators

Requires authenticated client for private repos.

Examples:

Octokit.collaborators('octokit/octokit.rb')
Octokit.collabs('octokit/octokit.rb')
@client.collabs('octokit/octokit.rb')

See Also:



284
285
286
# File 'lib/octokit/client/repositories.rb', line 284

def collaborators(repo, options = {})
  paginate "#{Repository.path repo}/collaborators", options
end

- (Array<Sawyer::Resource>) contributors(repo, anon = nil, options = {}) Also known as: contribs

List contributors to a repo

Requires authenticated client for private repos.

Examples:

Octokit.contributors('octokit/octokit.rb', true)
Octokit.contribs('octokit/octokit.rb')
@client.contribs('octokit/octokit.rb')

See Also:



370
371
372
373
# File 'lib/octokit/client/repositories.rb', line 370

def contributors(repo, anon = nil, options = {})
  options[:anon] = 1 if anon.to_s[/1|true/]
  paginate "#{Repository.path repo}/contributors", options
end

- (Sawyer::Resource) create_hook(repo, name, config, options = {})

Create a hook

Requires authenticated client.

Examples:

@client.create_hook(
  'octokit/octokit.rb',
  'web',
  {
    :url => 'http://something.com/webhook',
    :content_type => 'json'
  },
  {
    :events => ['push', 'pull_request'],
    :active => true
  }
)

Options Hash (options):

  • :events (Array<String>) — default: '["push"]'

    Determines what events the hook is triggered for.

  • :active (Boolean)

    Determines whether the hook is actually triggered on pushes.

See Also:



542
543
544
545
# File 'lib/octokit/client/repositories.rb', line 542

def create_hook(repo, name, config, options = {})
  options = {:name => name, :config => config, :events => ["push"], :active => true}.merge(options)
  post "#{Repository.path repo}/hooks", options
end

- (Sawyer::Resource) create_repository(name, options = {}) Also known as: create_repo, create

Create a repository for a user or organization

Options Hash (options):

  • :description (String)

    Description of the repo

  • :homepage (String)

    Home page of the repo

  • :private (String)

    `true` makes the repository private, and `false` makes it public.

  • :has_issues (String)

    `true` enables issues for this repo, `false` disables issues.

  • :has_wiki (String)

    `true` enables wiki for this repo, `false` disables wiki.

  • :has_downloads (String)

    `true` enables downloads for this repo, `false` disables downloads.

  • :organization (String)

    Short name for the org under which to create the repo.

  • :team_id (Integer)

    The id of the team that will be granted access to this repository. This is only valid when creating a repo in an organization.

  • :auto_init (Boolean)

    `true` to create an initial commit with empty README. Default is `false`.

  • :gitignore_template (String)

    Desired language or platform .gitignore template to apply. Ignored if auto_init parameter is not provided.

See Also:



151
152
153
154
155
156
157
158
159
160
# File 'lib/octokit/client/repositories.rb', line 151

def create_repository(name, options = {})
  organization = options.delete :organization
  options.merge! :name => name

  if organization.nil?
    post 'user/repos', options
  else
    post "orgs/#{organization}/repos", options
  end
end

- (Boolean) delete_repository(repo, options = {}) Also known as: delete_repo

Delete repository

Note: If OAuth is used, 'delete_repo' scope is required



171
172
173
# File 'lib/octokit/client/repositories.rb', line 171

def delete_repository(repo, options = {})
  boolean_from_response :delete, Repository.path(repo), options
end

- (Boolean) delete_subscription(repo, options = {})

Delete a repository subscription

Examples:

@client.delete_subscription("octokit/octokit.rb")

See Also:



695
696
697
# File 'lib/octokit/client/repositories.rb', line 695

def delete_subscription(repo, options = {})
  boolean_from_response :delete, "#{Repository.path repo}/subscription", options
end

- (Sawyer::Resource) deploy_key(repo, id, options = {})

Get a single deploy key for a repo

Examples:

@client.deploy_key('octokit/octokit.rb', 8675309)

See Also:



218
219
220
# File 'lib/octokit/client/repositories.rb', line 218

def deploy_key(repo, id, options={})
  get "#{Repository.path repo}/keys/#{id}", options
end

- (Array<Sawyer::Resource>) deploy_keys(repo, options = {}) Also known as: list_deploy_keys

Get deploy keys on a repo

Requires authenticated client.

Examples:

@client.deploy_keys('octokit/octokit.rb')
@client.list_deploy_keys('octokit/octokit.rb')

See Also:



205
206
207
# File 'lib/octokit/client/repositories.rb', line 205

def deploy_keys(repo, options = {})
  paginate "#{Repository.path repo}/keys", options
end

- (Sawyer::Resource) edit_deploy_key(repo, id, options) Also known as: update_deploy_key

Deprecated.

This method is no longer supported in the API

Edit a deploy key

Examples:

Update the key for a deploy key.

@client.edit_deploy_key('octokit/octokit.rb', 8675309, :key => 'ssh-rsa BBB...')
@client.update_deploy_key('octokit/octokit.rb', 8675309, :title => 'Uber', :key => 'ssh-rsa BBB...'))

See Also:



252
253
254
# File 'lib/octokit/client/repositories.rb', line 252

def edit_deploy_key(repo, id, options)
  patch "#{Repository.path repo}/keys/#{id}", options
end

- (Sawyer::Resource) edit_hook(repo, id, name, config, options = {})

Edit a hook

Requires authenticated client.

Examples:

@client.edit_hook(
  'octokit/octokit.rb',
  100000,
  'web',
  {
    :url => 'http://something.com/webhook',
    :content_type => 'json'
  },
  {
    :add_events => ['status'],
    :remove_events => ['pull_request'],
    :active => true
  }
)

Options Hash (options):

  • :events (Array<String>) — default: '["push"]'

    Determines what events the hook is triggered for.

  • :add_events (Array<String>)

    Determines a list of events to be added to the list of events that the Hook triggers for.

  • :remove_events (Array<String>)

    Determines a list of events to be removed from the list of events that the Hook triggers for.

  • :active (Boolean)

    Determines whether the hook is actually triggered on pushes.

See Also:



585
586
587
588
# File 'lib/octokit/client/repositories.rb', line 585

def edit_hook(repo, id, name, config, options = {})
  options = {:name => name, :config => config, :events => ["push"], :active => true}.merge(options)
  patch "#{Repository.path repo}/hooks/#{id}", options
end

- (Sawyer::Resource) edit_repository(repo, options = {}) Also known as: edit, update_repository, update

Edit a repository

Options Hash (options):

  • :name (String)

    Name of the repo

  • :description (String)

    Description of the repo

  • :homepage (String)

    Home page of the repo

  • :private (String)

    `true` makes the repository private, and `false` makes it public.

  • :has_issues (String)

    `true` enables issues for this repo, `false` disables issues.

  • :has_wiki (String)

    `true` enables wiki for this repo, `false` disables wiki.

  • :has_downloads (String)

    `true` enables downloads for this repo, `false` disables downloads.

  • :default_branch (String)

    Update the default branch for this repository.

See Also:



44
45
46
47
48
# File 'lib/octokit/client/repositories.rb', line 44

def edit_repository(repo, options = {})
  repo = Repository.new(repo)
  options[:name] ||= repo.name
  patch "repos/#{repo}", options
end

- (Sawyer::Resource) fork(repo, options = {})

Fork a repository



132
133
134
# File 'lib/octokit/client/repositories.rb', line 132

def fork(repo, options = {})
  post "#{Repository.path repo}/forks", options
end

- (Array<Sawyer::Resource>) forks(repo, options = {}) Also known as: network

List forks

Requires authenticated client for private repos.

Examples:

Octokit.forks('octokit/octokit.rb')
Octokit.network('octokit/octokit.rb')
@client.forks('octokit/octokit.rb')

See Also:



421
422
423
# File 'lib/octokit/client/repositories.rb', line 421

def forks(repo, options = {})
  paginate "#{Repository.path repo}/forks", options
end

- (Sawyer::Resource) hook(repo, id, options = {})

Get single hook

Requires authenticated client.

Examples:

@client.hook('octokit/octokit.rb', 100000)

See Also:



507
508
509
# File 'lib/octokit/client/repositories.rb', line 507

def hook(repo, id, options = {})
  get "#{Repository.path repo}/hooks/#{id}", options
end

- (Array<Sawyer::Resource>) hooks(repo, options = {})

List repo hooks

Requires authenticated client.

Examples:

@client.hooks('octokit/octokit.rb')

See Also:



493
494
495
# File 'lib/octokit/client/repositories.rb', line 493

def hooks(repo, options = {})
  paginate "#{Repository.path repo}/hooks", options
end

- (Array<Sawyer::Resource>) languages(repo, options = {})

List languages of code in the repo.

Requires authenticated client for private repos.

Examples:

Octokit.languages('octokit/octokit.rb')
@client.languages('octokit/octokit.rb')

See Also:



437
438
439
# File 'lib/octokit/client/repositories.rb', line 437

def languages(repo, options = {})
  paginate "#{Repository.path repo}/languages", options
end

- (Boolean) remove_collaborator(repo, collaborator, options = {}) Also known as: remove_collab

Remove collaborator from repo.

Requires authenticated client.

Examples:

@client.remove_collaborator('octokit/octokit.rb', 'holman')
@client.remove_collab('octokit/octokit.rb', 'holman')

See Also:



318
319
320
# File 'lib/octokit/client/repositories.rb', line 318

def remove_collaborator(repo, collaborator, options = {})
  boolean_from_response :delete, "#{Repository.path repo}/collaborators/#{collaborator}", options
end

- (Boolean) remove_deploy_key(repo, id, options = {})

Remove deploy key from a repo

Requires authenticated client.

Examples:

@client.remove_deploy_key('octokit/octokit.rb', 100000)

See Also:



267
268
269
# File 'lib/octokit/client/repositories.rb', line 267

def remove_deploy_key(repo, id, options = {})
  boolean_from_response :delete, "#{Repository.path repo}/keys/#{id}", options
end

- (Boolean) remove_hook(repo, id, options = {})

Delete hook

Requires authenticated client.

Examples:

@client.remove_hook('octokit/octokit.rb', 1000000)

See Also:



600
601
602
# File 'lib/octokit/client/repositories.rb', line 600

def remove_hook(repo, id, options = {})
  boolean_from_response :delete, "#{Repository.path repo}/hooks/#{id}", options
end

- (Array<Sawyer::Resource>) repositories(user = nil, options = {}) Also known as: list_repositories, list_repos, repos

Note:

If the user provided is a GitHub organization, only the organization's public repositories will be listed. For retrieving organization repositories the Organizations#organization_repositories method should be used instead.

List user repositories

If user is not supplied, repositories for the current

authenticated user are returned.


67
68
69
# File 'lib/octokit/client/repositories.rb', line 67

def repositories(user=nil, options = {})
  paginate "#{User.path user}/repos", options
end

- (Sawyer::Resource) repository(repo, options = {}) Also known as: repo

Get a single repository



25
26
27
# File 'lib/octokit/client/repositories.rb', line 25

def repository(repo, options = {})
  get Repository.path(repo), options
end

- (Sawyer::Resource) repository?(repo, options = {})

Check if a repository exists



14
15
16
17
18
# File 'lib/octokit/client/repositories.rb', line 14

def repository?(repo, options = {})
  !!repository(repo, options)
rescue Octokit::NotFound
  false
end

- (Array<Sawyer::Resource>) repository_assignees(repo, options = {}) Also known as: repo_assignees

List users available for assigning to issues.

Requires authenticated client for private repos.

Examples:

Octokit.repository_assignees('octokit/octokit.rb')
Octokit.repo_assignees('octokit/octokit.rb')
@client.repository_assignees('octokit/octokit.rb')

See Also:



631
632
633
# File 'lib/octokit/client/repositories.rb', line 631

def repository_assignees(repo, options = {})
  paginate "#{Repository.path repo}/assignees", options
end

- (Array<Sawyer::Resource>) repository_teams(repo, options = {}) Also known as: repo_teams, teams

List teams for a repo

Requires authenticated client that is an owner or collaborator of the repo.

Examples:

@client.repository_teams('octokit/pengwynn')
@client.repo_teams('octokit/pengwynn')
@client.teams('octokit/pengwynn')

See Also:



350
351
352
# File 'lib/octokit/client/repositories.rb', line 350

def repository_teams(repo, options = {})
  paginate "#{Repository.path repo}/teams", options
end

- (Sawyer::Resource) set_private(repo, options = {})

Hide a public repository



180
181
182
183
# File 'lib/octokit/client/repositories.rb', line 180

def set_private(repo, options = {})
  # GitHub Api for setting private updated to use private attr, rather than public
  update_repository repo, options.merge({ :private => true })
end

- (Sawyer::Resource) set_public(repo, options = {})

Unhide a private repository



189
190
191
192
# File 'lib/octokit/client/repositories.rb', line 189

def set_public(repo, options = {})
  # GitHub Api for setting private updated to use private attr, rather than public
  update_repository repo, options.merge({ :private => false })
end

- (Boolean) star(repo, options = {})

Star a repository



94
95
96
# File 'lib/octokit/client/repositories.rb', line 94

def star(repo, options = {})
  boolean_from_response :put, "user/starred/#{Repository.new(repo)}", options
end

- (Array<Sawyer::Resource>) stargazers(repo, options = {})

List stargazers of a repo

Requires authenticated client for private repos.

Examples:

Octokit.stargazers('octokit/octokit.rb')
@client.stargazers('octokit/octokit.rb')

See Also:



387
388
389
# File 'lib/octokit/client/repositories.rb', line 387

def stargazers(repo, options = {})
  paginate "#{Repository.path repo}/stargazers", options
end

- (Array<Sawyer::Resource>) subscribers(repo, options = {})

List watchers subscribing to notifications for a repo

Examples:

@client.subscribers("octokit/octokit.rb")

See Also:



655
656
657
# File 'lib/octokit/client/repositories.rb', line 655

def subscribers(repo, options = {})
  paginate "#{Repository.path repo}/subscribers", options
end

- (Sawyer::Resource) subscription(repo, options = {})

Get a repository subscription

Examples:

@client.subscription("octokit/octokit.rb")

See Also:



666
667
668
# File 'lib/octokit/client/repositories.rb', line 666

def subscription(repo, options = {})
  get "#{Repository.path repo}/subscription", options
end

- (Array<Sawyer::Resource>) tags(repo, options = {})

List tags

Requires authenticated client for private repos.

Examples:

Octokit.tags('octokit/octokit.rb')
@client.tags('octokit/octokit.rb')

See Also:



452
453
454
# File 'lib/octokit/client/repositories.rb', line 452

def tags(repo, options = {})
  paginate "#{Repository.path repo}/tags", options
end

- (Boolean) test_hook(repo, id, options = {})

Test hook

Requires authenticated client.

Examples:

@client.test_hook('octokit/octokit.rb', 1000000)

See Also:



614
615
616
# File 'lib/octokit/client/repositories.rb', line 614

def test_hook(repo, id, options = {})
  boolean_from_response :post, "#{Repository.path repo}/hooks/#{id}/tests", options
end

- (Boolean) unstar(repo, options = {})

Unstar a repository



103
104
105
# File 'lib/octokit/client/repositories.rb', line 103

def unstar(repo, options = {})
  boolean_from_response :delete, "user/starred/#{Repository.new(repo)}", options
end

- (Boolean) unwatch(repo, options = {})

Deprecated.

Use #unstar instead

Unwatch a repository



123
124
125
# File 'lib/octokit/client/repositories.rb', line 123

def unwatch(repo, options = {})
  boolean_from_response :delete, "user/watched/#{Repository.new(repo)}", options
end

- (Sawyer::Resource) update_subscription(repo, options = {})

Update repository subscription

Examples:

Subscribe to notifications for a repository

@client.update_subscription("octokit/octokit.rb", {subscribed: true})

Options Hash (options):

  • :subscribed (Boolean)

    Determines if notifications should be received from this repository.

  • :ignored (Boolean)

    Deterimines if all notifications should be blocked from this repository.

See Also:



683
684
685
# File 'lib/octokit/client/repositories.rb', line 683

def update_subscription(repo, options = {})
  put "#{Repository.path repo}/subscription", options
end

- (Boolean) watch(repo, options = {})

Deprecated.

Use #star instead

Watch a repository



113
114
115
# File 'lib/octokit/client/repositories.rb', line 113

def watch(repo, options = {})
  boolean_from_response :put, "user/watched/#{Repository.new(repo)}", options
end

- (Array<Sawyer::Resource>) watchers(repo, options = {})

Deprecated.

Use #stargazers instead

List watchers of repo.

Requires authenticated client for private repos.

Examples:

Octokit.watchers('octokit/octokit.rb')
@client.watchers('octokit/octokit.rb')

See Also:



404
405
406
# File 'lib/octokit/client/repositories.rb', line 404

def watchers(repo, options = {})
  paginate "#{Repository.path repo}/watchers", options
end