lib/reviewlette/github_connection.rb in reviewlette-0.0.9 vs lib/reviewlette/github_connection.rb in reviewlette-1.0.0

- old
+ new

@@ -1,42 +1,46 @@ -require 'yaml' require 'octokit' -class GithubConnection +class Reviewlette + class GithubConnection + attr_accessor :client, :repo - attr_accessor :client, :repo + def initialize(repo, token) + @client = Octokit::Client.new(access_token: token) + @repo = repo + end - def initialize(repo, token) - @client = Octokit::Client.new(access_token: token) - @repo = repo - end + def pull_requests + @client.pull_requests(@repo) + end - def list_pulls - @client.pull_requests(@repo) - end + def labels(issue) + @client.labels_for_issue(@repo, issue).map(&:name) + end - def add_assignee(number, assignee) - @client.update_issue(@repo, number, assignee: assignee) - end + def add_assignees(number, assignees) + @client.update_issue(@repo, number, assignees: assignees) + end - def reviewer_comment(number, assignee, trello_card) - comment = "@#{assignee} is your reviewer :dancers: check #{trello_card.url} \n" \ - "@#{assignee}: Please review this pull request using our guidelines: \n" \ - "* test for acceptance criteria / functionality \n" \ - "* check if the new code is covered with tests \n" \ - "* check for unintended consequences \n" \ - "* encourage usage of the boyscout rule \n" \ - "* make sure the code is architected in the best way \n" \ - "* check that no unnecessary technical debt got introduced \n" \ - "* make sure that no unnecessary FIXMEs or TODOs got added \n" - @client.add_comment(@repo, number, comment) - end + def comment_reviewers(number, reviewers, trello_card) + assignees = reviewers.map { |r| "@#{r.github_handle}" }.join(' and ') - def unassigned_pull_requests - list_pulls.select { |issue| !issue[:assignee] } - end + comment = <<-eos + #{assignees} will review your pull request :dancers: check #{trello_card.url} + #{assignees}: Please review this pull request using our guidelines: + * test for acceptance criteria / functionality + * check if the new code is covered with tests + * check for unintended consequences + * encourage usage of the boyscout rule + * make sure the code is architected in the best way + * check that no unnecessary technical debt got introduced + * make sure that no unnecessary FIXMEs or TODOs got added + eos - def repo_exists? - @client.repository?(@repo) - end + @client.add_comment(@repo, number, comment) + end + def repo_exists? + @client.repository?(@repo) + end + end end