class Dependabot::Clients::Gitea
Attributes
credentials[R]
source[R]
Public Class Methods
for_source(source:, credentials:)
click to toggle source
Constructor methods #
# File lib/hack/dependabot-core/common/lib/dependabot/clients/gitea.rb, line 16 def self.for_source(source:, credentials:) credential = credentials. select { |cred| cred["type"] == "git_source" }. find { |cred| cred["host"] == source.hostname } new(source, credential) end
new(source, credentials)
click to toggle source
Client #
# File lib/hack/dependabot-core/common/lib/dependabot/clients/gitea.rb, line 29 def initialize(source, credentials) @source = source @credentials = credentials end
Public Instance Methods
branch(branch_name)
click to toggle source
# File lib/hack/dependabot-core/common/lib/dependabot/clients/gitea.rb, line 77 def branch(branch_name) raise end
commits(branch_name = nil)
click to toggle source
# File lib/hack/dependabot-core/common/lib/dependabot/clients/gitea.rb, line 70 def commits(branch_name = nil) response = get(source.api_endpoint + "repos/" + "#{source.repo}/" + "commits") JSON.parse(response.body, object_class: OpenStruct) end
create_commit(branch_name, base_commit, commit_message, files, author_details)
click to toggle source
# File lib/hack/dependabot-core/common/lib/dependabot/clients/gitea.rb, line 85 def create_commit(branch_name, base_commit, commit_message, files, author_details) head_file = files.first tail_files = files.drop(1) res = fetch_repo_contents(base_commit, head_file.path) content = { new_branch: branch_name, content: Base64.encode64(head_file.content), message: commit_message, sha: res.fetch('sha'), branch: 'master' } response = put(source.api_endpoint + "repos/" + "#{source.repo}/" + "contents" + head_file.path, content.to_json) end
create_pull_request(pr_name, source_branch, target_branch, pr_description, labels)
click to toggle source
# File lib/hack/dependabot-core/common/lib/dependabot/clients/gitea.rb, line 104 def create_pull_request(pr_name, source_branch, target_branch, pr_description, labels) content = { base: target_branch, head: source_branch, title: pr_name, body: pr_description, } response = post(source.api_endpoint + "repos/" + "#{source.repo}/" + "pulls", content.to_json) end
fetch_commit(_repo, branch)
click to toggle source
# File lib/hack/dependabot-core/common/lib/dependabot/clients/gitea.rb, line 34 def fetch_commit(_repo, branch) response = get(source.api_endpoint + "repos/" + "#{source.repo}/" + "branches/" + branch) JSON.parse(response.body).fetch("commit").fetch("id") end
fetch_default_branch(_repo)
click to toggle source
# File lib/hack/dependabot-core/common/lib/dependabot/clients/gitea.rb, line 48 def fetch_default_branch(_repo) response = get(source.api_endpoint + "repos/" + source.repo) JSON.parse(response.body).fetch("default_branch") end
fetch_file_contents(commit, path)
click to toggle source
# File lib/hack/dependabot-core/common/lib/dependabot/clients/gitea.rb, line 66 def fetch_file_contents(commit, path) fetch_repo_contents(commit, path) end
fetch_repo_contents(commit = nil, path = nil)
click to toggle source
# File lib/hack/dependabot-core/common/lib/dependabot/clients/gitea.rb, line 55 def fetch_repo_contents(commit = nil, path = nil) response = get(source.api_endpoint + "repos/" + "#{source.repo}/" + "contents/" + path, {ref: commit}) JSON.parse(response.body) end
fetch_repo_contents_treeroot(commit = nil, path = nil)
click to toggle source
# File lib/hack/dependabot-core/common/lib/dependabot/clients/gitea.rb, line 62 def fetch_repo_contents_treeroot(commit = nil, path = nil) raise # not-implemented end
get(url, extra_query = {})
click to toggle source
# File lib/hack/dependabot-core/common/lib/dependabot/clients/gitea.rb, line 117 def get(url, extra_query = {}) response = Excon.get( url, query: {access_token: credentials&.fetch("password")}.merge(extra_query), idempotent: true, **SharedHelpers.excon_defaults ) raise NotFound if response.status == 404 response end
labels(_repo)
click to toggle source
# File lib/hack/dependabot-core/common/lib/dependabot/clients/gitea.rb, line 41 def labels(_repo) response = get(source.api_endpoint + "repos/" + "#{source.repo}/" + "labels") JSON.parse(response.body, object_class: OpenStruct) end
post(url, json)
click to toggle source
# File lib/hack/dependabot-core/common/lib/dependabot/clients/gitea.rb, line 129 def post(url, json) response = Excon.post( url, headers: { "Content-Type" => "application/json" }, body: json, query: {access_token: credentials&.fetch("password")}, idempotent: true, **SharedHelpers.excon_defaults ) raise NotFound if response.status == 404 response end
pull_requests(source_branch, target_branch)
click to toggle source
# File lib/hack/dependabot-core/common/lib/dependabot/clients/gitea.rb, line 81 def pull_requests(source_branch, target_branch) raise end
put(url, json)
click to toggle source
# File lib/hack/dependabot-core/common/lib/dependabot/clients/gitea.rb, line 145 def put(url, json) response = Excon.put( url, headers: { "Content-Type" => "application/json" }, body: json, query: {access_token: credentials&.fetch("password")}, idempotent: true, **SharedHelpers.excon_defaults ) raise NotFound if response.status == 404 response end