Class: BitBucket::Repos

Inherits:
API
  • Object
show all
Extended by:
AutoloadHelper
Defined in:
lib/bitbucket_rest_api/repos.rb

Defined Under Namespace

Classes: Changesets, Commits, Components, DefaultReviewers, Download, Following, Forks, Keys, PullRequest, Services, Sources, Webhooks

Constant Summary collapse

DEFAULT_REPO_OPTIONS =
{
    "website"         => "",
    "is_private"      => false,
    "has_issues"      => false,
    "has_wiki"        => false,
    "scm"             => "git",
    "no_public_forks" => false
}.freeze
VALID_REPO_OPTIONS =
%w[
  owner
  name
  description
  website
  is_private
  has_issues
  has_wiki
  no_public_forks
  language
  scm
].freeze

Constants included from Validations

Validations::VALID_API_KEYS

Constants included from Validations::Token

Validations::Token::TOKEN_REQUIRED, Validations::Token::TOKEN_REQUIRED_REGEXP

Constants included from Request

BitBucket::Request::METHODS, BitBucket::Request::METHODS_WITH_BODIES

Constants included from Connection

Connection::ALLOWED_OPTIONS

Constants included from Constants

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

Instance Method Summary collapse

Methods included from AutoloadHelper

autoload_all, lookup_constant, register_constant

Methods inherited from API

#_merge_mime_type, #_merge_user_into_params!, #_merge_user_repo_into_params!, #_update_user_repo_params, #api_methods_in, inherited, #method_missing, #process_basic_auth, #set_api_client, #setup, #update_and_validate_user_repo_params

Methods included from Normalizer

#normalize!

Methods included from ParameterFilter

#filter!

Methods included from Validations::Required

#assert_required_keys, #assert_required_values_present, #parse_values

Methods included from Validations::Token

#validates_token_for

Methods included from Validations::Format

#assert_valid_values

Methods included from Validations::Presence

#_validate_presence_of, #_validate_user_repo_params

Methods included from Request

#delete_request, #get_request, #patch_request, #post_request, #put_request, #request

Methods included from Connection

#caching?, #clear_cache, #connection, #default_middleware, #default_options, #stack

Methods included from Authorization

#authenticated?, #authentication, #basic_authed?

Constructor Details

#initialize(options = { }) ⇒ Repos

Creates new Repositories API



45
46
47
# File 'lib/bitbucket_rest_api/repos.rb', line 45

def initialize(options = { })
  super(options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class BitBucket::API

Instance Method Details

#branches(user_name, repo_name, params = {}) ⇒ Object Also known as: list_branches

List branches

Examples

bitbucket = BitBucket.new
bibucket.repos.branches 'user-name', 'repo-name'

repos = BitBucket::Repos.new
repos.branches 'user-name', 'repo-name'


110
111
112
113
114
115
116
117
118
# File 'lib/bitbucket_rest_api/repos.rb', line 110

def branches(user_name, repo_name, params={})
  _update_user_repo_params(user_name, repo_name)
  _validate_user_repo_params(user, repo) unless (user? && repo?)
  normalize! params

  response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/branches/", params)
  return response unless block_given?
  response.each { |el| yield el }
end

#changesetsObject

Access to Repos::Commits API



50
51
52
# File 'lib/bitbucket_rest_api/repos.rb', line 50

def changesets
  @changesets ||= ApiFactory.new 'Repos::Changesets'
end

#commitsObject



76
77
78
# File 'lib/bitbucket_rest_api/repos.rb', line 76

def commits
  @commits ||=ApiFactory.new 'Repos::Commits'
end

#componentsObject



92
93
94
# File 'lib/bitbucket_rest_api/repos.rb', line 92

def components
  @components ||= ApiFactory.new 'Repos::Components'
end

#create(*args) ⇒ Object

FIXME: ‘POST a new repository’ is a deprecated feature of the API Create a new repository for the authenticated user.

Parameters

<tt>:name</tt> - Required string
<tt>:description</tt> - Optional string
<tt>:website</tt> - Optional string
<tt>:is_private</tt> - Optional boolean - <tt>true</tt> to create a private repository, <tt>false</tt> to create a public one.
<tt>:has_issues</tt> - Optional boolean - <tt>true</tt> to enable issues for this repository, <tt>false</tt> to disable them
<tt>:has_wiki</tt> - Optional boolean - <tt>true</tt> to enable the wiki for this repository, <tt>false</tt> to disable it. Default is <tt>true</tt>
<tt>:owner</tt> Optional string - The team in which this repository will be created

Examples

bitbucket = BitBucket.new
bitbucket.repos.create "name" => 'repo-name'
  "description": "This is your first repo",
  "website": "https://bitbucket.com",
  "is_private": false,
  "has_issues": true,
  "has_wiki": true

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

Examples:

bitbucket = BitBucket.new :oauth_token => '...', :oauth_secret => '...'
bitbucket.repos.create :name => 'repo-name', :owner => 'team-name'


150
151
152
153
154
155
156
157
158
# File 'lib/bitbucket_rest_api/repos.rb', line 150

def create(*args)
  params = args.extract_options!
  normalize! params
  filter! VALID_REPO_OPTIONS + %w[ org ], params
  assert_required_keys(%w[ name ], params)

  # Requires authenticated user
  post_request("/1.0/repositories/", DEFAULT_REPO_OPTIONS.merge(params))
end

#default_reviewersObject



88
89
90
# File 'lib/bitbucket_rest_api/repos.rb', line 88

def default_reviewers
  @default_reviewers ||= ApiFactory.new 'Repos::DefaultReviewers'
end

#delete(user_name, repo_name) ⇒ Object

FIXME: ‘DELETE an existing repository’ is a deprecated feature of the API Delete a repository

Examples

@bitbucket = BitBucket.new
@bitbucket.repos.delete 'user-name', 'repo-name'


213
214
215
216
217
218
# File 'lib/bitbucket_rest_api/repos.rb', line 213

def delete(user_name, repo_name)
  _update_user_repo_params(user_name, repo_name)
  _validate_user_repo_params(user, repo) unless user? && repo?

  delete_request("/1.0/repositories/#{user}/#{repo.downcase}")
end

#downloadObject



79
80
81
# File 'lib/bitbucket_rest_api/repos.rb', line 79

def download
  @download ||=ApiFactory.new "Repos::Download"
end

#edit(user_name, repo_name, params = { }) ⇒ Object

Edit a repository

Parameters

  • :name Required string

  • :description Optional string

  • :website Optional string

  • :private - Optional boolean - false to create public reps, false to create a private one

  • :has_issues Optional boolean - true to enable issues for this repository, false to disable them

  • :has_wiki Optional boolean - true to enable the wiki for this repository, false to disable it. Default is true

  • :has_downloads Optional boolean - true to enable downloads for this repository

Examples

bitbucket = BitBucket.new
bitbucket.repos.edit 'user-name', 'repo-name',
  :name => 'hello-world',
  :description => 'This is your first repo',
  :website => "https://bitbucket.com",
  :public => true, :has_issues => true


180
181
182
183
184
185
186
187
188
# File 'lib/bitbucket_rest_api/repos.rb', line 180

def edit(user_name, repo_name, params={ })
  _update_user_repo_params(user_name, repo_name)
  _validate_user_repo_params(user, repo) unless user? && repo?

  normalize! params
  filter! VALID_REPO_OPTIONS, params

  put_request("/1.0/repositories/#{user}/#{repo.downcase}/", DEFAULT_REPO_OPTIONS.merge(params))
end

#followingObject

Access to Repos::Watchin API



60
61
62
# File 'lib/bitbucket_rest_api/repos.rb', line 60

def following
  @following ||= ApiFactory.new 'Repos::Following'
end

#forksObject



73
74
75
# File 'lib/bitbucket_rest_api/repos.rb', line 73

def forks
  @forks ||= ApiFactory.new 'Repos::Forks'
end

#get(user_name, repo_name, params = { }) ⇒ Object Also known as: find

Get a repository

Examples

bitbucket = BitBucket.new
bitbucket.repos.get 'user-name', 'repo-name'


196
197
198
199
200
201
202
# File 'lib/bitbucket_rest_api/repos.rb', line 196

def get(user_name, repo_name, params={ })
  _update_user_repo_params(user_name, repo_name)
  _validate_user_repo_params(user, repo) unless user? && repo?
  normalize! params

  get_request("/1.0/repositories/#{user}/#{repo.downcase}", params)
end

#keysObject

Access to Repos::Keys API



55
56
57
# File 'lib/bitbucket_rest_api/repos.rb', line 55

def keys
  @keys ||= ApiFactory.new 'Repos::Keys'
end

#list(*args) ⇒ Object Also known as: all

List repositories for the authenticated user

Examples

bitbucket = BitBucket.new :oauth_token => '...', :oauth_secret => '...'
bitbucket.repos.list
bitbucket.repos.list { |repo| ... }

List public repositories for the specified user.

Examples

bitbucket = BitBucket.new
bitbucket.repos.list :user => 'user-name', :role => 'owner'
bitbucket.repos.list :user => 'user-name', { |repo| ... }


233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/bitbucket_rest_api/repos.rb', line 233

def list(*args)
  params = args.extract_options!
  normalize! params
  _merge_user_into_params!(params) unless params.has_key?('user')
  params.merge!('pagelen' => 100) unless params.has_key?('pagelen')
  
  filter! %w[ user role pagelen ], params

  response = get_request("/2.0/repositories", params)

  response = response[:values]
  return response unless block_given?
  response.each { |el| yield el }
end

#pull_requestObject

Access to Repos::PullRequests API



84
85
86
# File 'lib/bitbucket_rest_api/repos.rb', line 84

def pull_request
  @pull_request ||= ApiFactory.new 'Repos::PullRequest'
end

#servicesObject

Access to Repos::Services API



70
71
72
# File 'lib/bitbucket_rest_api/repos.rb', line 70

def services
  @services ||= ApiFactory.new 'Repos::Services'
end

#sourcesObject

Access to Repos::Commits API



65
66
67
# File 'lib/bitbucket_rest_api/repos.rb', line 65

def sources
  @sources ||= ApiFactory.new 'Repos::Sources'
end

#tags(user_name, repo_name, params = { }) ⇒ Object Also known as: list_tags, repo_tags, repository_tags

List tags

Examples

bitbucket = BitBucket.new
bitbucket.repos.tags 'user-name', 'repo-name'
bitbucket.repos.tags 'user-name', 'repo-name' { |tag| ... }


257
258
259
260
261
262
263
264
265
# File 'lib/bitbucket_rest_api/repos.rb', line 257

def tags(user_name, repo_name, params={ })
  _update_user_repo_params(user_name, repo_name)
  _validate_user_repo_params(user, repo) unless user? && repo?
  normalize! params

  response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/tags/", params)
  return response unless block_given?
  response.each { |el| yield el }
end

#webhooksObject



96
97
98
# File 'lib/bitbucket_rest_api/repos.rb', line 96

def webhooks
  @webhooks ||= ApiFactory.new 'Repos::Webhooks'
end