Class: Dependabot::Clients::Bitbucket
- Inherits:
-
Object
- Object
- Dependabot::Clients::Bitbucket
- Defined in:
- lib/dependabot/clients/bitbucket.rb
Defined Under Namespace
Classes: NotFound
Class Method Summary collapse
-
.for_bitbucket_dot_org(credentials:) ⇒ Object
Constructor methods #.
Instance Method Summary collapse
- #compare(repo, previous_tag, new_tag) ⇒ Object
- #fetch_commit(repo, branch) ⇒ Object
- #fetch_default_branch(repo) ⇒ Object
- #fetch_file_contents(repo, commit, path) ⇒ Object
- #fetch_repo_contents(repo, commit = nil, path = nil) ⇒ Object
- #get(url) ⇒ Object
-
#initialize(credentials) ⇒ Bitbucket
constructor
Client #.
- #tags(repo) ⇒ Object
Constructor Details
#initialize(credentials) ⇒ Bitbucket
Client #
28 29 30 |
# File 'lib/dependabot/clients/bitbucket.rb', line 28 def initialize(credentials) @credentials = credentials end |
Class Method Details
.for_bitbucket_dot_org(credentials:) ⇒ Object
Constructor methods #
15 16 17 18 19 20 21 22 |
# File 'lib/dependabot/clients/bitbucket.rb', line 15 def self.for_bitbucket_dot_org(credentials:) credential = credentials. select { |cred| cred["type"] == "git_source" }. find { |cred| cred["host"] == "bitbucket.org" } new(credential) end |
Instance Method Details
#compare(repo, previous_tag, new_tag) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/dependabot/clients/bitbucket.rb', line 71 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
32 33 34 35 36 37 |
# File 'lib/dependabot/clients/bitbucket.rb', line 32 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
39 40 41 42 43 |
# File 'lib/dependabot/clients/bitbucket.rb', line 39 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
57 58 59 60 61 62 |
# File 'lib/dependabot/clients/bitbucket.rb', line 57 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
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dependabot/clients/bitbucket.rb', line 45 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
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/dependabot/clients/bitbucket.rb', line 78 def get(url) response = Excon.get( url, user: credentials&.fetch("username"), password: credentials&.fetch("password"), idempotent: true, **SharedHelpers.excon_defaults ) raise NotFound if response.status == 404 response end |
#tags(repo) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/dependabot/clients/bitbucket.rb', line 64 def (repo) path = "#{repo}/refs/tags?pagelen=100" response = get(base_url + path) JSON.parse(response.body).fetch("values") end |