Class: Repository
- Inherits:
-
Object
show all
- Includes:
- API
- Defined in:
- lib/bitbucket/repository.rb
Constant Summary
collapse
- LIMIT =
1000.to_s
Instance Attribute Summary collapse
Attributes included from API
#api
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from API
#create_api, #parsed_response, #request
Constructor Details
#initialize(server, data) ⇒ Repository
Returns a new instance of Repository.
12
13
14
15
16
|
# File 'lib/bitbucket/repository.rb', line 12
def initialize(server,data)
@bb = server
@name = data['slug']
@project = data['project']['key']
end
|
Instance Attribute Details
#bb ⇒ Object
Returns the value of attribute bb.
10
11
12
|
# File 'lib/bitbucket/repository.rb', line 10
def bb
@bb
end
|
#name ⇒ Object
Returns the value of attribute name.
10
11
12
|
# File 'lib/bitbucket/repository.rb', line 10
def name
@name
end
|
#project ⇒ Object
Returns the value of attribute project.
10
11
12
|
# File 'lib/bitbucket/repository.rb', line 10
def project
@project
end
|
Class Method Details
.get_all(bb, project) ⇒ Object
5
6
7
8
|
# File 'lib/bitbucket/repository.rb', line 5
def self.get_all(bb,project)
data = bb.request(:get, "rest/api/1.0/projects/#{project}/repos/?limit=#{LIMIT}")
data['values'].map {|p| new(bb,p) }
end
|
Instance Method Details
#branch_permissions ⇒ Object
18
19
20
|
# File 'lib/bitbucket/repository.rb', line 18
def branch_permissions
bb.request(:get, "rest/branch-permissions/2.0/projects/#{project}/repos/#{name}/restrictions")['values']
end
|
#hook_settings(key) ⇒ Object
59
60
61
|
# File 'lib/bitbucket/repository.rb', line 59
def hook_settings(key)
bb.request(:get, "rest/api/1.0/projects/#{project}/repos/#{name}/settings/hooks/#{key}/settings")
end
|
#hooks ⇒ Object
47
48
49
|
# File 'lib/bitbucket/repository.rb', line 47
def hooks
bb.request(:get, "rest/api/1.0/projects/#{project}/repos/#{name}/settings/hooks")
end
|
#master_branch_protected? ⇒ Boolean
22
23
24
25
26
|
# File 'lib/bitbucket/repository.rb', line 22
def master_branch_protected?
!! branch_permissions.detect do |c|
c["type"] == 'fast-forward-only' && c["matcher"]["id"] == 'refs/heads/master'
end
end
|
#move_repo_to_project(new_project) ⇒ Object
42
43
44
45
|
# File 'lib/bitbucket/repository.rb', line 42
def move_repo_to_project(new_project)
bb.request(:post, "/rest/api/1.0/projects/#{project}/repos/#{name}",{project: {key: new_project}}.to_json)
bb.request(:delete, "/rest/api/1.0/projects/#{project}/repos/#{name}")
end
|
#set_hook_settings(key, settings) ⇒ Object
63
64
65
|
# File 'lib/bitbucket/repository.rb', line 63
def set_hook_settings(key, settings)
bb.request(:put, "rest/api/1.0/projects/#{project}/repos/#{name}/settings/hooks/#{key}/settings", settings)
end
|
#set_hook_status(key, status) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/bitbucket/repository.rb', line 51
def set_hook_status(key, status)
if status
bb.request(:put, "rest/api/1.0/projects/#{project}/repos/#{name}/settings/hooks/#{key}/enabled")
else
bb.request(:delete, "rest/api/1.0/projects/#{project}/repos/#{name}/settings/hooks/#{key}/enabled")
end
end
|
#set_master_branch_protected ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/bitbucket/repository.rb', line 28
def set_master_branch_protected
perm = {
"type"=>"fast-forward-only",
"matcher"=>
{"id"=>"refs/heads/master",
"displayId"=>"master",
"type"=>{"id"=>"BRANCH", "name"=>"Branch"},
"active"=>true},
"users"=>[],
"groups"=>[]
}.to_json
bb.request(:post, "rest/branch-permissions/2.0/projects/#{project}/repos/#{name}/restrictions", perm)
end
|