123456789_123456789_123456789_123456789_123456789_

Module: Octokit::Client::Repositories

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: lib/octokit/client/repositories.rb

Overview

Methods for the Repositories API

Instance Method Summary

Instance Method Details

#add_collab(repo, collaborator, options = {})

Alias for #add_collaborator.

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 348

alias add_collab add_collaborator

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

Add collaborator to repo

This can also be used to update the permission of an existing collaborator

Requires authenticated client.

Examples:

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

Add a collaborator with admin permissions

@client.add_collaborator('octokit/octokit.rb', 'holman', permission: 'admin')

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

  • collaborator (String)

    Collaborator GitHub username to add.

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

    a customizable set of options

Options Hash (options):

  • :permission (String)

    The permission to grant the collaborator. Only valid on organization-owned repositories. Can be one of: pull, push, or admin. If not specified, defaults to push

Returns:

  • (Boolean)

    True if collaborator added, false otherwise.

See Also:

[ GitHub ]

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

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

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

Add deploy key to a repo

Requires authenticated client.

Examples:

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

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

  • title (String)

    Title reference for the deploy key.

  • key (String)

    Public key.

Returns:

  • (Sawyer::Resource)

    Hash representing newly added key.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 266

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

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

List all repositories

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

Parameters:

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

    Optional options

Options Hash (options):

Returns:

  • (Array<Sawyer::Resource>)

    List of repositories.

See Also:

[ GitHub ]

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

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

#automated_security_fixes_enabled?(repo, options = {}) ⇒ Boolean

Check to see if automated security fixes are enabled for a repository

The authenticated user must have admin access to the repository.

Examples:

@client.automated_security_fixes_enabled?("octokit/octokit.rb")

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Boolean)

    True if automated security fixes are enabled, false otherwise.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 788

def automated_security_fixes_enabled?(repo, options = {})
  response = get "#{Repository.path repo}/automated-security-fixes", options
  return response[:enabled] if @last_response.status == 200

  false
end

#branch(repo, branch, options = {}) ⇒ Sawyer::Resource 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")

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

  • branch (String)

    Branch name

Returns:

  • (Sawyer::Resource)

    The branch requested, if it exists

See Also:

[ GitHub ]

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

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

#branch_protection(repo, branch, options = {}) ⇒ Sawyer::Resource?

Get branch protection summary

Examples:

@client.branch_protection('octokit/octokit.rb', 'master')

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

  • branch (String)

    Branch name

Returns:

  • (Sawyer::Resource, nil)

    Branch protection summary or nil if the branch is not protected

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 606

def branch_protection(repo, branch, options = {})
  get "#{Repository.path repo}/branches/#{branch}/protection", options
rescue Octokit::BranchNotProtected
  nil
end

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

List branches

Requires authenticated client for private repos.

Examples:

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

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Array<Sawyer::Resource>)

    Array of hashes representing branches.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 554

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

#check_assignee(repo, assignee, options = {}) ⇒ Boolean

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

Examples:

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

Parameters:

Returns:

  • (Boolean)

    True if assignable on project, false otherwise.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 670

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

#collaborator?(repo, collaborator, options = {}) ⇒ Boolean

Checks if a user is a collaborator for a repo.

Requires authenticated client.

Examples:

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

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

  • collaborator (String)

    Collaborator GitHub username to check.

Returns:

  • (Boolean)

    True if user is a collaborator, false otherwise.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 377

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

#collaborators(repo, options = {}) ⇒ Array<Sawyer::Resource> 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')

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

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

    a customizable set of options

Options Hash (options):

  • :affiliation (String)

    Filters the return array by affiliation. Can be one of: outside, direct, or all. If not specified, defaults to all

Returns:

  • (Array<Sawyer::Resource>)

    Array of hashes representing collaborating users.

See Also:

[ GitHub ]

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

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

#collabs(repo, options = {})

Alias for #collaborators.

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 323

alias collabs collaborators

#contribs(repo, anon = nil, options = {})

Alias for #contributors.

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 461

alias contribs contributors

#contributors(repo, anon = nil, options = {}) ⇒ Array<Sawyer::Resource> 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')

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

  • anon (Boolean) (defaults to: nil)

    Set true to include anonymous contributors.

Returns:

  • (Array<Sawyer::Resource>)

    Array of hashes representing users.

See Also:

[ GitHub ]

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

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

#create(name, options = {})

Alias for #create_repository.

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 166

alias create create_repository

#create_repo(name, options = {})

Alias for #create_repository.

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 165

alias create_repo create_repository

#create_repo_from_template(repo, name, options = {})

[ GitHub ]

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

alias create_repo_from_template create_repository_from_template

#create_repository(name, options = {}) ⇒ Sawyer::Resource 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.

  • :is_template (Boolean)

    true makes this repo available as a template repository, false to prevent it.

  • :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. ::Octokit::Default is false.

  • :gitignore_template (String)

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

Returns:

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 154

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

  if organization.nil?
    post 'user/repos', opts
  else
    post "#{Organization.path organization}/repos", opts
  end
end

#create_repository_from_template(repo, name, options = {}) ⇒ Sawyer::Resource Also known as: #create_repo_from_template

Create a repository for a user or organization generated from a template repository

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub template repository

  • name (String)

    Name of the new repo

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

    a customizable set of options

Options Hash (options):

  • :owner (String)

    ::Octokit::Organization or user who the new repository will belong to.

  • :description (String)

    Description of the repo

  • :private (String)

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

  • :include_all_branches (Boolean)

    true copies all branches from the template repository, false (default) makes it only copy the master branch.

Returns:

[ GitHub ]

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

def create_repository_from_template(repo, name, options = {})
  options.merge! name: name
  post "#{Repository.path repo}/generate", options
end

#delete_repo(repo, options = {})

Alias for #delete_repository.

[ GitHub ]

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

alias delete_repo delete_repository

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

Delete repository

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

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository

Returns:

  • (Boolean)

    true if repository was deleted

See Also:

[ GitHub ]

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

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

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

Delete a repository subscription

Examples:

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

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Boolean)

    True if subscription deleted, false otherwise.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 721

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

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

Get a single deploy key for a repo

Examples:

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

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

  • id (Integer)

    Deploy key ID.

Returns:

  • (Sawyer::Resource)

    Deploy key.

See Also:

[ GitHub ]

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

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

#deploy_keys(repo, options = {}) ⇒ Array<Sawyer::Resource> 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')

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository

Returns:

  • (Array<Sawyer::Resource>)

    Array of hashes representing deploy keys.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 238

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

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

Disable automated security fixes for a repository

Examples:

Disable automated security fixes for a repository

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

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

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

Returns:

  • (Boolean)

    True if vulnerability alerts disabled, false otherwise.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 817

def disable_automated_security_fixes(repo, options = {})
  boolean_from_response(:delete, "#{Repository.path repo}/automated-security-fixes", options)
end

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

Disable vulnerability alerts for a repository

Examples:

Disable vulnerability alerts for a repository

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

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

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

Returns:

  • (Boolean)

    True if vulnerability alerts disabled, false otherwise.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 774

def disable_vulnerability_alerts(repo, options = {})
  boolean_from_response(:delete, "#{Repository.path repo}/vulnerability-alerts", options)
end

#dispatch_event(repo, event_type, options = {}) ⇒ Boolean

Create a repository dispatch event

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

  • event_type (String)

    A custom webhook event name.

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

    a customizable set of options

Options Hash (options):

  • :client_payload (Hash)

    payload with extra information about the webhook event that your action or worklow may use.

Returns:

  • (Boolean)

    True if event was dispatched, false otherwise.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 734

def dispatch_event(repo, event_type, options = {})
  boolean_from_response :post, "#{Repository.path repo}/dispatches", options.merge({ event_type: event_type })
end

#edit(repo, options = {})

Alias for #edit_repository.

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 51

alias edit edit_repository

#edit_deploy_key(repo, id, options) ⇒ Sawyer::Resource 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...'))

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

  • id (Integer)

    Deploy key ID.

  • options (Hash)

    Attributes to edit.

  • title (Hash)

    a customizable set of options

  • key (Hash)

    a customizable set of options

Returns:

  • (Sawyer::Resource)

    Updated deploy key.

See Also:

[ GitHub ]

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

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

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

Edit a repository

Parameters:

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.

  • :is_template (Boolean)

    true makes the repository a template, false makes it not a template.

  • :has_downloads (String)

    true enables downloads for this repo, false disables downloads.

  • :default_branch (String)

    Update the default branch for this repository.

Returns:

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 46

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

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

Enable automated security fixes for a repository

Examples:

Enable automated security fixes for a repository

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

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

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

Returns:

  • (Boolean)

    True if vulnerability alerts enabled, false otherwise.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 804

def enable_automated_security_fixes(repo, options = {})
  boolean_from_response(:put, "#{Repository.path repo}/automated-security-fixes", options)
end

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

Enable vulnerability alerts for a repository

Examples:

Enable vulnerability alerts for a repository

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

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

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

Returns:

  • (Boolean)

    True if vulnerability alerts enabled, false otherwise.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 761

def enable_vulnerability_alerts(repo, options = {})
  boolean_from_response(:put, "#{Repository.path repo}/vulnerability-alerts", options)
end

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

Fork a repository

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository

Returns:

See Also:

[ GitHub ]

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

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

#forks(repo, options = {}) ⇒ Array<Sawyer::Resource> 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')

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Array<Sawyer::Resource>)

    Array of hashes representing repos.

See Also:

[ GitHub ]

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

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

#get_branch(repo, branch, options = {})

Alias for #branch.

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 569

alias get_branch branch

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

List languages of code in the repo.

Requires authenticated client for private repos.

Examples:

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

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Array<Sawyer::Resource>)

    Array of Hashes representing languages.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 524

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

#list_deploy_keys(repo, options = {})

Alias for #deploy_keys.

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 241

alias list_deploy_keys deploy_keys

#list_repos(user = nil, options = {})

Alias for #repositories.

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 73

alias list_repos repositories

#list_repositories(user = nil, options = {})

Alias for #repositories.

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 72

alias list_repositories repositories

#network(repo, options = {})

Alias for #forks.

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 511

alias network forks

#permission_level(repo, collaborator, options = {}) ⇒ Sawyer::Resource

Get a user's permission level for a repo.

Requires authenticated client

Examples:

@client.permission_level('octokit/octokit.rb', 'lizzhale')

Returns:

  • (Sawyer::Resource)

    Hash representing the user's permission level for the given repository

See Also:

[ GitHub ]

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

def permission_level(repo, collaborator, options = {})
  get "#{Repository.path repo}/collaborators/#{collaborator}/permission", options
end

#protect_branch(repo, branch, options = {}) ⇒ Sawyer::Resource

Lock a single branch from a repository

Requires authenticated client

Examples:

@client.protect_branch('octokit/octokit.rb', 'master', foo)

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

  • branch (String)

    Branch name

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

    a customizable set of options

Options Hash (options):

  • :required_status_checks (Hash)

    If not null, the following keys are required: :enforce_admins [boolean] Enforce required status checks for repository administrators. :strict [boolean] Require branches to be up to date before merging. :contexts [Array] The list of status checks to require in order to merge into this branch

  • :restrictions (Hash)

    If not null, the following keys are required: :users [Array] The list of user logins with push access :teams [Array] The list of team slugs with push access.

    Teams and users restrictions are only available for organization-owned repositories.

Returns:

  • (Sawyer::Resource)

    The protected branch

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 591

def protect_branch(repo, branch, options = {})
  options[:restrictions] ||= nil
  options[:required_status_checks] ||= nil
  put "#{Repository.path repo}/branches/#{branch}/protection", options
end

#remove_collab(repo, collaborator, options = {})

[ GitHub ]

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

alias remove_collab remove_collaborator

#remove_collaborator(repo, collaborator, options = {}) ⇒ Boolean 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')

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

  • collaborator (String)

    Collaborator GitHub username to remove.

Returns:

  • (Boolean)

    True if collaborator removed, false otherwise.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 362

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

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

Remove deploy key from a repo

Requires authenticated client.

Examples:

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

Parameters:

  • repo (Integer, 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:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 300

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

#rename_branch(repo, branch, new_name, options = {}) ⇒ Sawyer::Resource

Rename a single branch from a repository

Requires authenticated client

Examples:

@client.rename_branch('octokit/octokit.rb', 'master', 'main')

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

  • branch (String)

    Current branch name

  • new_name (String)

    New branch name

Returns:

  • (Sawyer::Resource)

    The renamed branch

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 637

def rename_branch(repo, branch, new_name, options = {})
  params = {
    new_name: new_name
  }
  post "#{Repository.path repo}/branches/#{branch}/rename", params.merge(options)
end

#replace_all_topics(repo, names, options = {}) ⇒ Sawyer::Resource

Replace all topics for a repository

Requires authenticated client.

Examples:

Replace topics for octokit/octokit.rb

client.replace_all_topics('octokit/octokit.rb', ['octocat', 'atom', 'electron', 'API'])

Clear all topics for octokit/octokit.rb

client.replace_all_topics('octokit/octokit.rb', [])

Parameters:

  • repo (Integer, String, Repository, Hash)

    A Github repository

  • names (Array)

    An array of topics to add to the repository.

Returns:

  • (Sawyer::Resource)

    representing the replaced topics for given repo

See Also:

[ GitHub ]

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

def replace_all_topics(repo, names, options = {})
  put "#{Repository.path repo}/topics", options.merge(names: names)
end

#repo(repo, options = {})

Alias for #repository.

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 29

alias repo repository

#repo_assignees(repo, options = {})

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 660

alias repo_assignees repository_assignees

#repo_teams(repo, options = {})

Alias for #repository_teams.

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 409

alias repo_teams repository_teams

#repos(user = nil, options = {})

Alias for #repositories.

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 74

alias repos repositories

#repositories(user = nil, options = {}) ⇒ Array<Sawyer::Resource> 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.

Parameters:

  • user (Integer, String) (defaults to: nil)

    Optional GitHub user login or id for which to list repos.

Returns:

  • (Array<Sawyer::Resource>)

    List of repositories

See Also:

[ GitHub ]

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

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

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

Get a single repository

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository

Returns:

See Also:

[ GitHub ]

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

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

#repository?(repo, options = {}) ⇒ Boolean

Check if a repository exists

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 14

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

#repository_assignees(repo, options = {}) ⇒ Array<Sawyer::Resource> 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')

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Array<Sawyer::Resource>)

    Array of hashes representing users.

See Also:

[ GitHub ]

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

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

#repository_teams(repo, options = {}) ⇒ Array<Sawyer::Resource> 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 (Integer, String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Array<Sawyer::Resource>)

    Array of hashes representing teams.

See Also:

[ GitHub ]

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

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

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

Hide a public repository

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository

Returns:

  • (Sawyer::Resource)

    Updated repository info

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 213

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 = {}) ⇒ Sawyer::Resource

Unhide a private repository

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository

Returns:

  • (Sawyer::Resource)

    Updated repository info

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 222

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

See Also:

[ GitHub ]

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

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

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

List stargazers of a repo

Requires authenticated client for private repos.

Examples:

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

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Array<Sawyer::Resource>)

    Array of hashes representing users.

See Also:

[ GitHub ]

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

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

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

List watchers subscribing to notifications for a repo

Examples:

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

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Array<Sawyer::Resource>)

    Array of users watching.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 681

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

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

Get a repository subscription

Examples:

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

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

Returns:

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 692

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

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

List tags

Requires authenticated client for private repos.

Examples:

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

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Array<Sawyer::Resource>)

    Array of hashes representing tags.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 539

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

#teams(repo, options = {})

Alias for #repository_teams.

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 410

alias teams repository_teams

#topics(repo, options = {}) ⇒ Sawyer::Resource

List all topics for a repository

Requires authenticated client for private repos.

Examples:

List topics for octokit/octokit.rb

Octokit.topics('octokit/octokit.rb')

List topics for octokit/octokit.rb

client.topics('octokit/octokit.rb')

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Sawyer::Resource)

    representing the topics for given repo

See Also:

[ GitHub ]

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

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

#transfer_repo(repo, new_owner, options = {})

[ GitHub ]

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

alias transfer_repo transfer_repository

#transfer_repository(repo, new_owner, options = {}) ⇒ Sawyer::Resource Also known as: #transfer_repo

Transfer repository

Transfer a repository owned by your organization

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository

  • new_owner (String)

    The username or organization name the repository will be transferred to.

  • options (Array<Integer>) (defaults to: {})

    :team_ids ID of the team or teams to add to the repository. Teams can only be added to organization-owned repositories.

Returns:

See Also:

[ GitHub ]

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

def transfer_repository(repo, new_owner, options = {})
  post "#{Repository.path repo}/transfer", options.merge({ new_owner: new_owner })
end

#unprotect_branch(repo, branch, options = {}) ⇒ Sawyer::Resource

Unlock a single branch from a repository

Requires authenticated client

Examples:

@client.unprotect_branch('octokit/octokit.rb', 'master')

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

  • branch (String)

    Branch name

Returns:

  • (Sawyer::Resource)

    The unprotected branch

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 622

def unprotect_branch(repo, branch, options = {})
  boolean_from_response :delete, "#{Repository.path repo}/branches/#{branch}/protection", options
end

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

Unstar a repository

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

Returns:

  • (Boolean)

    true if successfully unstarred

See Also:

[ GitHub ]

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

def unstar(repo, options = {})
  boolean_from_response :delete, "user/starred/#{Repository.new(repo)}", options
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

See Also:

[ GitHub ]

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

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

#update(repo, options = {})

Alias for #edit_repository.

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 53

alias update edit_repository

#update_deploy_key(repo, id, options)

Alias for #edit_deploy_key.

[ GitHub ]

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

alias update_deploy_key edit_deploy_key

#update_repository(repo, options = {})

Alias for #edit_repository.

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 52

alias update_repository edit_repository

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

Update repository subscription

Examples:

Subscribe to notifications for a repository

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

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

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

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.

Returns:

  • (Sawyer::Resource)

    Updated repository subscription.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 709

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

#vulnerability_alerts_enabled?(repo, options = {}) ⇒ Boolean

Check to see if vulnerability alerts are enabled for a repository

The authenticated user must have admin access to the repository.

Examples:

@client.vulnerability_alerts_enabled?("octokit/octokit.rb")

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Boolean)

    True if vulnerability alerts are enabled, false otherwise.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 748

def vulnerability_alerts_enabled?(repo, options = {})
  boolean_from_response(:get, "#{Repository.path repo}/vulnerability-alerts", options)
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

See Also:

[ GitHub ]

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

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

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

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

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Array<Sawyer::Resource>)

    Array of hashes representing users.

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/repositories.rb', line 491

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