Class: DiffSuggester::Suggester

Inherits:
Object
  • Object
show all
Defined in:
lib/diff-suggester/suggester.rb

Instance Method Summary collapse

Constructor Details

#initialize(repo:, pr_number:, access_token:, base_url: nil) ⇒ Suggester

Returns a new instance of Suggester.



7
8
9
# File 'lib/diff-suggester/suggester.rb', line 7

def initialize(repo:, pr_number:, access_token:, base_url: nil)
  @pull_request = GitHubRequester::PullRequest.new(repo: repo, pr_number: pr_number, access_token: access_token, base_url: base_url)
end

Instance Method Details

#suggestObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/diff-suggester/suggester.rb', line 11

def suggest
  diffs = GitHubDiff.parse_from_string
  diffs.each do |diff|
    diff.hunks.each do |hunk|
      @pull_request.create_comment(
        path: diff.file_path,
        body: suggestion(hunk.body),
        line: hunk.end_line,
        start_line: hunk.start_line,
        side: 'RIGHT',
        start_side: 'RIGHT'
      )
    end
  end
end

#suggestion(body) ⇒ Object



27
28
29
# File 'lib/diff-suggester/suggester.rb', line 27

def suggestion(body)
    return "```suggestion\n#{body}\n```"
end