class Pronto::Gitlab
def client
def client @client ||= ::Gitlab.client(endpoint: endpoint, private_token: private_token) end
def commit_comments(sha)
def commit_comments(sha) @comment_cache["#{sha}"] ||= begin client.commit_comments(slug, sha, per_page: 500).map do |comment| Comment.new(sha, comment.note, comment.path, comment.line) end end end
def create_commit_comment(comment)
def create_commit_comment(comment) client.create_commit_comment(slug, comment.sha, comment.note, path: comment.path, line: comment.line, line_type: 'new') end
def endpoint
def endpoint ENV['GITLAB_API_ENDPOINT'] end
def initialize(repo)
def initialize(repo) @repo = repo @comment_cache = {} end
def private_token
def private_token ENV['GITLAB_API_PRIVATE_TOKEN'] end
def slug
def slug @slug ||= begin host = URI.split(endpoint)[2, 2].compact.join(':') slug = @repo.remote_urls.map do |url| match = /.*#{host}(:|\/)(?<slug>.*).git/.match(url) match[:slug] if match end.compact.first URI.escape(slug, '/') if slug end end