Class: Pronto::Gitlab

Inherits:
Client
  • Object
show all
Defined in:
lib/pronto/gitlab.rb

Instance Method Summary collapse

Methods inherited from Client

#initialize

Constructor Details

This class inherits a constructor from Pronto::Client

Instance Method Details

#commit_comments(sha) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/pronto/gitlab.rb', line 3

def commit_comments(sha)
  @comment_cache[sha.to_s] ||= begin
    client.commit_comments(slug, sha).auto_paginate.map do |comment|
      Comment.new(sha, comment.note, comment.path, comment.line)
    end
  end
end

#create_commit_comment(comment) ⇒ Object



48
49
50
51
52
53
# File 'lib/pronto/gitlab.rb', line 48

def create_commit_comment(comment)
  @config.logger.log("Creating commit comment on #{comment.sha}")
  client.create_commit_comment(slug, comment.sha, comment.body,
                               path: comment.path, line: comment.position,
                               line_type: 'new')
end

#create_pull_request_review(comments) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pronto/gitlab.rb', line 30

def create_pull_request_review(comments)
  return if comments.empty?

  comments.each do |comment|
    options = {
      body: comment.body,
      position: position_sha.dup.merge(
        new_path: comment.path,
        position_type: 'text',
        new_line: comment.position,
        old_line: nil,
      )
    }

    client.create_merge_request_discussion(slug, pull_id, options)
  end
end

#pull_comments(sha) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pronto/gitlab.rb', line 11

def pull_comments(sha)
  @comment_cache["#{slug}/#{pull_id}"] ||= begin
    arr = []
    client.merge_request_discussions(slug, pull_id).auto_paginate.each do |comment|
      comment.notes.each do |note|
        next unless note['position']

        arr << Comment.new(
          sha,
          note['body'],
          note['position']['new_path'],
          note['position']['new_line']
        )
      end
    end
    arr
  end
end