Class: BitBucket::Repos
- Extended by:
- AutoloadHelper
- Defined in:
- lib/bitbucket_rest_api/repos.rb
Defined Under Namespace
Classes: Changesets, Following, Keys, Services, Sources
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
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
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
-
#branches(user_name, repo_name, params = { }) ⇒ Object
(also: #list_branches)
List branches.
-
#changesets ⇒ Object
Access to Repos::Commits API.
-
#create(*args) ⇒ Object
Create a new repository for the authenticated user.
-
#edit(user_name, repo_name, params = { }) ⇒ Object
Edit a repository.
-
#following ⇒ Object
Access to Repos::Watchin API.
-
#get(user_name, repo_name, params = { }) ⇒ Object
(also: #find)
Get a repository.
-
#initialize(options = { }) ⇒ Repos
constructor
Creates new Repositories API.
-
#keys ⇒ Object
Access to Repos::Keys API.
-
#list(*args) ⇒ Object
(also: #all)
List repositories for the authenticated user.
-
#services ⇒ Object
Access to Repos::Services API.
-
#sources ⇒ Object
Access to Repos::Commits API.
-
#tags(user_name, repo_name, params = { }) ⇒ Object
(also: #list_tags, #repo_tags, #repository_tags)
List tags.
Methods included from AutoloadHelper
autoload_all, lookup_constant, register_constant
Methods inherited from API
#_hash_traverse, #_merge_mime_type, #_merge_user_into_params!, #_merge_user_repo_into_params!, #_update_user_repo_params, #api_methods_in, #append_arguments, inherited, #method_missing, #process_basic_auth, #set_api_client, #setup
Methods included from Normalizer
Methods included from ParameterFilter
Methods included from Validations::Required
Methods included from Validations::Token
Methods included from Validations::Format
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
38 39 40 |
# File 'lib/bitbucket_rest_api/repos.rb', line 38 def initialize( = { }) super() 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
77 78 79 80 81 82 83 84 85 |
# File 'lib/bitbucket_rest_api/repos.rb', line 77 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("/repositories/#{user}/#{repo.downcase}/branches/", params) return response unless block_given? response.each { |el| yield el } end |
#changesets ⇒ Object
Access to Repos::Commits API
43 44 45 |
# File 'lib/bitbucket_rest_api/repos.rb', line 43 def changesets @changesets ||= ApiFactory.new 'Repos::Changesets' end |
#create(*args) ⇒ Object
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'
116 117 118 119 120 121 122 123 124 |
# File 'lib/bitbucket_rest_api/repos.rb', line 116 def create(*args) params = args. normalize! params filter! VALID_REPO_OPTIONS + %w[ org ], params assert_required_keys(%w[ name ], params) # Requires authenticated user post_request("/repositories/", DEFAULT_REPO_OPTIONS.merge(params)) 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 istrue
-
: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
146 147 148 149 150 151 152 153 154 |
# File 'lib/bitbucket_rest_api/repos.rb', line 146 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("/repositories/#{user}/#{repo.downcase}/", DEFAULT_REPO_OPTIONS.merge(params)) end |
#following ⇒ Object
Access to Repos::Watchin API
53 54 55 |
# File 'lib/bitbucket_rest_api/repos.rb', line 53 def following @following ||= ApiFactory.new 'Repos::Following' end |
#get(user_name, repo_name, params = { }) ⇒ Object Also known as: find
162 163 164 165 166 167 168 |
# File 'lib/bitbucket_rest_api/repos.rb', line 162 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("/repositories/#{user}/#{repo.downcase}", params) end |
#keys ⇒ Object
Access to Repos::Keys API
48 49 50 |
# File 'lib/bitbucket_rest_api/repos.rb', line 48 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'
bitbucket.repos.list :user => 'user-name', { |repo| ... }
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/bitbucket_rest_api/repos.rb', line 185 def list(*args) params = args. normalize! params _merge_user_into_params!(params) unless params.has_key?('user') filter! %w[ user type ], params response = #if (user_name = params.delete("user")) # get_request("/users/#{user_name}", params) #else # For authenticated user get_request("/user/repositories", params) #end return response unless block_given? response.each { |el| yield el } end |
#services ⇒ Object
Access to Repos::Services API
63 64 65 |
# File 'lib/bitbucket_rest_api/repos.rb', line 63 def services @services ||= ApiFactory.new 'Repos::Services' end |
#sources ⇒ Object
Access to Repos::Commits API
58 59 60 |
# File 'lib/bitbucket_rest_api/repos.rb', line 58 def sources @sources ||= ApiFactory.new 'Repos::Sources' end |
#tags(user_name, repo_name, params = { }) ⇒ Object Also known as: , ,
List tags
Examples
bitbucket = BitBucket.new
bitbucket.repos.tags 'user-name', 'repo-name'
bitbucket.repos.tags 'user-name', 'repo-name' { |tag| ... }
210 211 212 213 214 215 216 217 218 |
# File 'lib/bitbucket_rest_api/repos.rb', line 210 def (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("/repositories/#{user}/#{repo.downcase}/tags/", params) return response unless block_given? response.each { |el| yield el } end |