Module: Octokit::Client::Repositories

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

Instance Method Summary collapse

Instance Method Details

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

Add collaborator to repo

Requires authenticated client.

Examples:

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

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

  • collaborator (String)

    Collaborator GitHub username to add.

Returns:

  • (Boolean)

    True if collaborator added, false otherwise.

See Also:



269
270
271
# File 'lib/octokit/client/repositories.rb', line 269

def add_collaborator(repo, collaborator, options={})
  put "repos/#{Repository.new repo}/collaborators/#{collaborator}", options, 3
end

#add_deploy_key(repo, title, key, options = {}) ⇒ Hashie::Mash

Add deploy key to a repo

Requires authenticated client.

Examples:

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

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

  • title (String)

    Title reference for the deploy key.

  • key (String)

    Public key.

Returns:

  • (Hashie::Mash)

    Hash representing newly added key.

See Also:



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

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

#branch(repo, branch, options = {}) ⇒ Branch Also known as: get_branch

Get a single branch from a repository

Examples:

Get branch ‘master` from pengwynn/octokit

Octokit.issue("pengwynn/octokit", "master")

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

  • branch (String)

    Branch name

Returns:

  • (Branch)

    The branch requested, if it exists

See Also:



442
443
444
# File 'lib/octokit/client/repositories.rb', line 442

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

#branches(repo, options = {}) ⇒ Array<Hashie::Mash>

List branches

Requires authenticated client for private repos.

Examples:

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

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing branches.

See Also:



430
431
432
# File 'lib/octokit/client/repositories.rb', line 430

def branches(repo, options={})
  get "repos/#{Repository.new repo}/branches", options, 3
end

#collaborators(repo, options = {}) ⇒ Array<Hashie::Mash> Also known as: collabs

List collaborators

Requires authenticated client for private repos.

Examples:

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

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing collaborating users.

See Also:



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

def collaborators(repo, options={})
  get "repos/#{Repository.new repo}/collaborators", options, 3
end

#contributors(repo, anon = false, options = {}) ⇒ Array<Hashie::Mash> Also known as: contribs

List contributors to a repo

Requires authenticated client for private repos.

Examples:

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

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

  • anon (Boolean) (defaults to: false)

    Set true to include annonymous contributors.

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing users.

See Also:



327
328
329
# File 'lib/octokit/client/repositories.rb', line 327

def contributors(repo, anon=false, options={})
  get "repos/#{Repository.new repo}/contributors", options.merge(:anon => anon), 3
end

#create_hook(repo, name, config, options = {}) ⇒ Object

Create a hook

Requires authenticated client.

Examples:

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

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

  • name (String)

    The name of the service that is being called. See Hooks for the possible names.

  • config (Hash)

    A Hash containing key/value pairs to provide settings for this hook. These settings vary between the services and are defined in the github-services repo.

  • options (Hash) (defaults to: {})

    a customizable set of options

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:



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

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

#create_repository(name, options = {}) ⇒ Hashie::Mash Also known as: create_repo, create

Create a repository for a user or organization

Parameters:

  • name (String)

    Name of the new repo

  • options (Hash) (defaults to: {})

    a customizable set of options

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.

Returns:

  • (Hashie::Mash)

    Repository info for the new repository

See Also:



141
142
143
144
145
146
147
148
149
150
# File 'lib/octokit/client/repositories.rb', line 141

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

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

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

Delete repository

Note: If OAuth is used, ‘delete_repo’ scope is required

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

Returns:

  • (Boolean)

    ‘true` if repository was deleted

See Also:



161
162
163
164
165
166
167
168
# File 'lib/octokit/client/repositories.rb', line 161

def delete_repository(repo, options={})
  begin
    delete "repos/#{Repository.new repo}", options, 3
    return true
  rescue Octokit::NotFound
    return false
  end
end

#deploy_keys(repo, options = {}) ⇒ Array<Hashie::Mash> Also known as: list_deploy_keys

Get deploy keys on a repo

Requires authenticated client.

Examples:

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

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing deploy keys.

See Also:



201
202
203
# File 'lib/octokit/client/repositories.rb', line 201

def deploy_keys(repo, options={})
  get "repos/#{Repository.new repo}/keys", options, 3
end

#edit_hook(repo, id, name, config, options = {}) ⇒ Object

Edit a hook

Requires authenticated client.

Examples:

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

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

  • id (Integer)

    Id of the hook being updated.

  • name (String)

    The name of the service that is being called. See Hooks for the possible names.

  • config (Hash)

    A Hash containing key/value pairs to provide settings for this hook. These settings vary between the services and are defined in the github-services repo.

  • options (Hash) (defaults to: {})

    a customizable set of options

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:



549
550
551
552
# File 'lib/octokit/client/repositories.rb', line 549

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

#edit_repository(repo, options = {}) ⇒ Hashie::Mash Also known as: edit, update_repository, update

Edit a repository

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

  • options (Hash) (defaults to: {})

    Repository information to update

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.

Returns:

  • (Hashie::Mash)

    Repository information

See Also:



38
39
40
# File 'lib/octokit/client/repositories.rb', line 38

def edit_repository(repo, options={})
  patch "repos/#{Repository.new repo}", options, 3
end

#fork(repo, options = {}) ⇒ Hashie::Mash

Fork a repository

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

Returns:

  • (Hashie::Mash)

    Repository info for the new fork



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

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

#forks(repo, options = {}) ⇒ Array<Hashie::Mash> Also known as: network

List forks

Requires authenticated client for private repos.

Examples:

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

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing repos.

See Also:



381
382
383
# File 'lib/octokit/client/repositories.rb', line 381

def forks(repo, options={})
  get "repos/#{Repository.new repo}/forks", options, 3
end

#hook(repo, id, options = {}) ⇒ Hashie::Mash

Get single hook

Requires authenticated client.

Examples:

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

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

  • id (Integer)

    Id of the hook to get.

Returns:

  • (Hashie::Mash)

    Hash representing hook.

See Also:



472
473
474
# File 'lib/octokit/client/repositories.rb', line 472

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

#hooks(repo, options = {}) ⇒ Array<Hashie::Mash>

List repo hooks

Requires authenticated client.

Examples:

@client.hooks('pengwynn/octokit')

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing hooks.

See Also:



457
458
459
# File 'lib/octokit/client/repositories.rb', line 457

def hooks(repo, options={})
  get "repos/#{Repository.new repo}/hooks", options, 3
end

#languages(repo, options = {}) ⇒ Array<Hashie::Mash>

List languages of code in the repo.

Requires authenticated client for private repos.

Examples:

Octokit.langauges('pengwynn/octokit')
@client.languages('pengwynn/octokit')

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Array<Hashie::Mash>)

    Array of Hashes representing languages.

See Also:



398
399
400
# File 'lib/octokit/client/repositories.rb', line 398

def languages(repo, options={})
  get "repos/#{Repository.new repo}/languages", options, 3
end

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

Remove collaborator from repo.

Requires authenticated client.

Examples:

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

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

  • collaborator (String)

    Collaborator GitHub username to remove.

Returns:

  • (Boolean)

    True if collaborator removed, false otherwise.

See Also:



287
288
289
# File 'lib/octokit/client/repositories.rb', line 287

def remove_collaborator(repo, collaborator, options={})
  delete "repos/#{Repository.new repo}/collaborators/#{collaborator}", options, 3
end

#remove_deploy_key(repo, id, options = {}) ⇒ Boolean

Remove deploy key from a repo

Requires authenticated client.

Examples:

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

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

  • id (Integer)

    Id of the deploy key to remove.

Returns:

  • (Boolean)

    True if key removed, false otherwise.

See Also:



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

def remove_deploy_key(repo, id, options={})
  delete "repos/#{Repository.new repo}/keys/#{id}", options, 3
end

#remove_hook(repo, id, options = {}) ⇒ Boolean

Delete hook

Requires authenticated client.

Examples:

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

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

  • id (Integer)

    Id of the hook to remove.

Returns:

  • (Boolean)

    True if hook removed, false otherwise.

See Also:



565
566
567
# File 'lib/octokit/client/repositories.rb', line 565

def remove_hook(repo, id, options={})
  delete "repos/#{Repository.new repo}/hooks/#{id}", options, 3
end

#repositories(username = nil, options = {}) ⇒ Array<Hashie::Mash> Also known as: list_repositories, list_repos, repos

List repositories

If username is not supplied, repositories for the current authenticated user are returned

Parameters:

  • username (String) (defaults to: nil)

    Optional username for which to list repos

Returns:

  • (Array<Hashie::Mash>)

    List of repositories

See Also:



53
54
55
56
57
58
59
# File 'lib/octokit/client/repositories.rb', line 53

def repositories(username=nil, options={})
  if username.nil?
    get 'user/repos', options, 3
  else
    get "users/#{username}/repos", options, 3
  end
end

#repository(repo, options = {}) ⇒ Hashie::Mash Also known as: repo

Get a single repository

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

Returns:

  • (Hashie::Mash)

    Repository information

See Also:



20
21
22
# File 'lib/octokit/client/repositories.rb', line 20

def repository(repo, options={})
  get "repos/#{Repository.new repo}", options, 3
end

#repository_assignees(repo, options = {}) ⇒ Object Also known as: repo_assignees

List users available for assigning to issues.

Requires authenticated client for private repos.

Examples:

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

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

See Also:



611
612
613
# File 'lib/octokit/client/repositories.rb', line 611

def repository_assignees(repo, options={})
  get "repos/#{Repository.new repo}/assignees", options, 3
end

#repository_issue_events(repo, options = {}) ⇒ Array Also known as: repo_issue_events

Get all Issue Events for a given Repository

Examples:

Get all Issue Events for Octokit

Octokit.repository_issue_events("pengwynn/octokit")

Parameters:

  • repo (String, Repository, Hash)

    A GitHub repository

Returns:

  • (Array)

    Array of all Issue Events for this Repository

See Also:



592
593
594
# File 'lib/octokit/client/repositories.rb', line 592

def repository_issue_events(repo, options={})
  get "repos/#{Repository.new repo}/issues/events", options, 3
end

#repository_teams(repo, options = {}) ⇒ Array<Hashie::Mash> 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')

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing teams.

See Also:



306
307
308
# File 'lib/octokit/client/repositories.rb', line 306

def repository_teams(repo, options={})
  get "repos/#{Repository.new repo}/teams", options, 3
end

#search_repositories(q, options = {}) ⇒ Array<Hashie::Mash> Also known as: search_repos

Legacy repository search

Parameters:

  • q (String)

    Search keyword

Returns:

  • (Array<Hashie::Mash>)

    List of repositories found

See Also:



10
11
12
# File 'lib/octokit/client/repositories.rb', line 10

def search_repositories(q, options={})
  get("legacy/repos/search/#{q}", options, 3)['repositories']
end

#set_private(repo, options = {}) ⇒ Hashie::Mash

Hide a public repository

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

Returns:

  • (Hashie::Mash)

    Updated repository info



175
176
177
178
# File 'lib/octokit/client/repositories.rb', line 175

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

#set_public(repo, options = {}) ⇒ Hashie::Mash

Unhide a private repository

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

Returns:

  • (Hashie::Mash)

    Updated repository info



184
185
186
187
# File 'lib/octokit/client/repositories.rb', line 184

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

#star(repo, options = {}) ⇒ Boolean

Star a repository

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

Returns:

  • (Boolean)

    ‘true` if successfully starred



68
69
70
71
72
73
74
75
# File 'lib/octokit/client/repositories.rb', line 68

def star(repo, options={})
  begin
    put "user/starred/#{Repository.new repo}", options, 3
    return true
  rescue Octokit::NotFound
    return false
  end
end

#stargazers(repo, options = {}) ⇒ Array<Hashie::Mash>

List stargazers of a repo

Requires authenticated client for private repos.

Examples:

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

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing users.

See Also:



344
345
346
# File 'lib/octokit/client/repositories.rb', line 344

def stargazers(repo, options={})
  get "repos/#{Repository.new repo}/stargazers", options, 3
end

#tags(repo, options = {}) ⇒ Array<Hashie::Mash>

List tags

Requires authenticated client for private repos.

Examples:

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

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing tags.

See Also:



414
415
416
# File 'lib/octokit/client/repositories.rb', line 414

def tags(repo, options={})
  get "repos/#{Repository.new repo}/tags", options, 3
end

#test_hook(repo, id, options = {}) ⇒ nil

Test hook

Requires authenticated client.

Examples:

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

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

  • id (Integer)

    Id of the hook to test.

Returns:

  • (nil)

See Also:



580
581
582
# File 'lib/octokit/client/repositories.rb', line 580

def test_hook(repo, id, options={})
  post "repos/#{Repository.new repo}/hooks/#{id}/test", options, 3
end

#unstar(repo, options = {}) ⇒ Boolean

Unstar a repository

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

Returns:

  • (Boolean)

    ‘true` if successfully unstarred



81
82
83
84
85
86
87
88
# File 'lib/octokit/client/repositories.rb', line 81

def unstar(repo, options={})
  begin
    delete "user/starred/#{Repository.new repo}", options, 3
    return true
  rescue Octokit::NotFound
    return false
  end
end

#unwatch(repo, options = {}) ⇒ Boolean

Deprecated.

Use #unstar instead

Unwatch a repository

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

Returns:

  • (Boolean)

    ‘true` if successfully unwatched



109
110
111
112
113
114
115
116
# File 'lib/octokit/client/repositories.rb', line 109

def unwatch(repo, options={})
  begin
    delete "user/watched/#{Repository.new repo}", options, 3
    return true
  rescue Octokit::NotFound
    return false
  end
end

#watch(repo, options = {}) ⇒ Boolean

Deprecated.

Use #star instead

Watch a repository

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

Returns:

  • (Boolean)

    ‘true` if successfully watched



95
96
97
98
99
100
101
102
# File 'lib/octokit/client/repositories.rb', line 95

def watch(repo, options={})
  begin
    put "user/watched/#{Repository.new repo}", options, 3
    return true
  rescue Octokit::NotFound
    return false
  end
end

#watchers(repo, options = {}) ⇒ Array<Hashie::Mash>

Deprecated.

Use #stargazers instead

List watchers of repo.

Requires authenticated client for private repos.

Examples:

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

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing users.

See Also:



363
364
365
# File 'lib/octokit/client/repositories.rb', line 363

def watchers(repo, options={})
  get "repos/#{Repository.new repo}/watchers", options, 3
end