Class: Dependabot::Clients::Bitbucket
- Inherits:
-
Object
- Object
- Dependabot::Clients::Bitbucket
show all
- Defined in:
- lib/dependabot/clients/bitbucket.rb
Defined Under Namespace
Classes: Forbidden, NotFound, Unauthorized
Instance Method Summary
collapse
Constructor Details
#initialize(credentials:) ⇒ Bitbucket
19
20
21
|
# File 'lib/dependabot/clients/bitbucket.rb', line 19
def initialize(credentials:)
@credentials = credentials
end
|
Instance Method Details
#compare(repo, previous_tag, new_tag) ⇒ Object
62
63
64
65
66
67
|
# File 'lib/dependabot/clients/bitbucket.rb', line 62
def compare(repo, previous_tag, new_tag)
path = "#{repo}/commits/?include=#{new_tag}&exclude=#{previous_tag}"
response = get(base_url + path)
JSON.parse(response.body).fetch("values")
end
|
#fetch_commit(repo, branch) ⇒ Object
23
24
25
26
27
28
|
# File 'lib/dependabot/clients/bitbucket.rb', line 23
def fetch_commit(repo, branch)
path = "#{repo}/refs/branches/#{branch}"
response = get(base_url + path)
JSON.parse(response.body).fetch("target").fetch("hash")
end
|
#fetch_default_branch(repo) ⇒ Object
30
31
32
33
34
|
# File 'lib/dependabot/clients/bitbucket.rb', line 30
def fetch_default_branch(repo)
response = get(base_url + repo)
JSON.parse(response.body).fetch("mainbranch").fetch("name")
end
|
#fetch_file_contents(repo, commit, path) ⇒ Object
48
49
50
51
52
53
|
# File 'lib/dependabot/clients/bitbucket.rb', line 48
def fetch_file_contents(repo, commit, path)
path = "#{repo}/src/#{commit}/#{path.gsub(%r{/+$}, '')}"
response = get(base_url + path)
response.body
end
|
#fetch_repo_contents(repo, commit = nil, path = nil) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/dependabot/clients/bitbucket.rb', line 36
def fetch_repo_contents(repo, commit = nil, path = nil)
raise "Commit is required if path provided!" if commit.nil? && path
api_path = "#{repo}/src"
api_path += "/#{commit}" if commit
api_path += "/#{path.gsub(%r{/+$}, '')}" if path
api_path += "?pagelen=100"
response = get(base_url + api_path)
JSON.parse(response.body).fetch("values")
end
|
#get(url) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/dependabot/clients/bitbucket.rb', line 69
def get(url)
response = Excon.get(
url,
user: credentials&.fetch("username", nil),
password: credentials&.fetch("password", nil),
idempotent: true,
**Dependabot::SharedHelpers.excon_defaults
)
raise Unauthorized if response.status == 401
raise Forbidden if response.status == 403
raise NotFound if response.status == 404
if response.status >= 400
raise "Unhandled Bitbucket error!\n"\
"Status: #{response.status}\n"\
"Body: #{response.body}"
end
response
end
|
55
56
57
58
59
60
|
# File 'lib/dependabot/clients/bitbucket.rb', line 55
def tags(repo)
path = "#{repo}/refs/tags?pagelen=100"
response = get(base_url + path)
JSON.parse(response.body).fetch("values")
end
|