Class: Bucket::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/bucket/client.rb

Constant Summary collapse

GIT_URL =
"[email protected]"

Instance Method Summary collapse

Constructor Details

#initialize(credentials) ⇒ Client

Returns a new instance of Client.



5
6
7
8
# File 'lib/bucket/client.rb', line 5

def initialize(credentials)
  @connection = BitBucket.new(basic_auth: "#{credentials["username"]}:#{credentials["password"]}")
  @user = credentials["username"]
end

Instance Method Details

#create_repo(name, options = {}) ⇒ Object

Returns the created repository scm url



38
39
40
41
42
# File 'lib/bucket/client.rb', line 38

def create_repo(name, options={})
  options = options.merge(is_private: !options[:public])

  @connection.repos.create(options.merge(name: name))
end

#repo_full_name(repo) ⇒ Object

A repository full name is of the style of [USER]/



33
34
35
# File 'lib/bucket/client.rb', line 33

def repo_full_name(repo)
  "#{repo[:owner]}/#{repo[:slug]}"
end

#repo_url(name) ⇒ Object

Full url for the given repository The repository name must be of the style [USER]/ or

REPOSITORY

in which case the name of the current user

will be used as owner



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bucket/client.rb', line 18

def repo_url(name)
  split_name = name.split "/"

  if split_name.size == 1
    user = @user
    slug = split_name[0]
  else
    user = split_name[0]
    slug = split_name[1]
  end

  "#{GIT_URL}:#{user}/#{slug}.git"
end

#repos_listObject



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

def repos_list
  @connection.repos.list
end