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
22
|
# File 'lib/dependabot/clients/bitbucket.rb', line 19
def initialize(credentials:)
@credentials = credentials
= (credentials&.fetch("token", nil))
end
|
Instance Method Details
#compare(repo, previous_tag, new_tag) ⇒ Object
63
64
65
66
67
68
|
# File 'lib/dependabot/clients/bitbucket.rb', line 63
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
24
25
26
27
28
29
|
# File 'lib/dependabot/clients/bitbucket.rb', line 24
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
31
32
33
34
35
|
# File 'lib/dependabot/clients/bitbucket.rb', line 31
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
49
50
51
52
53
54
|
# File 'lib/dependabot/clients/bitbucket.rb', line 49
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
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/dependabot/clients/bitbucket.rb', line 37
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/dependabot/clients/bitbucket.rb', line 70
def get(url)
response = Excon.get(
url,
user: credentials&.fetch("username", nil),
password: credentials&.fetch("password", nil),
idempotent: true,
**Dependabot::SharedHelpers.excon_defaults(
headers:
)
)
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
|
56
57
58
59
60
61
|
# File 'lib/dependabot/clients/bitbucket.rb', line 56
def tags(repo)
path = "#{repo}/refs/tags?pagelen=100"
response = get(base_url + path)
JSON.parse(response.body).fetch("values")
end
|