Class: Linterbot::GitHubPullRequestCommenter

Inherits:
Object
  • Object
show all
Defined in:
lib/linterbot/github_pull_request_commenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, pull_request_number, github_client) ⇒ GitHubPullRequestCommenter

Returns a new instance of GitHubPullRequestCommenter.



11
12
13
14
15
# File 'lib/linterbot/github_pull_request_commenter.rb', line 11

def initialize(repository, pull_request_number, github_client)
  @repository = repository
  @pull_request_number = pull_request_number
  @github_client = github_client
end

Instance Attribute Details

#github_clientObject

Returns the value of attribute github_client.



9
10
11
# File 'lib/linterbot/github_pull_request_commenter.rb', line 9

def github_client
  @github_client
end

#pull_request_numberObject

Returns the value of attribute pull_request_number.



8
9
10
# File 'lib/linterbot/github_pull_request_commenter.rb', line 8

def pull_request_number
  @pull_request_number
end

#repositoryObject

Returns the value of attribute repository.



7
8
9
# File 'lib/linterbot/github_pull_request_commenter.rb', line 7

def repository
  @repository
end

Instance Method Details

#publish_comment(comment) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/linterbot/github_pull_request_commenter.rb', line 17

def publish_comment(comment)
  message = "#{comment.severity.upcase} - #{comment.message}\n"
  if comment_exist?(message)
    puts "Comment was not published because it already exists: #{message}"
  else
    create_pull_request_comment(message, comment.sha, comment.file, comment.patch_line_number)
  end
end

#publish_summary(summary) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/linterbot/github_pull_request_commenter.rb', line 26

def publish_summary(summary)
  if same_as_last_summary?(summary)
    puts "Summary was not published because it's the same as the last result summary:\n #{summary}"
  else
    github_client.add_comment(repository, pull_request_number, summary)
  end
end