Class: Deodorant::Github

Inherits:
Object
  • Object
show all
Defined in:
lib/deodorant/github.rb

Constant Summary collapse

OCTOKIT_CLIENT_NEW =
Octokit::Client.new(access_token: Config.github_token)

Instance Method Summary collapse

Constructor Details

#initialize(octokit: nil, git_client: nil) ⇒ Github

Returns a new instance of Github.



8
9
10
11
# File 'lib/deodorant/github.rb', line 8

def initialize(octokit: nil, git_client: nil)
  @octokit = octokit || OCTOKIT_CLIENT_NEW
  @git_client = git_client || Repo.default_git_client
end

Instance Method Details

#append_change_id_to_pr(pr_number:, change_id:) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/deodorant/github.rb', line 40

def append_change_id_to_pr(pr_number:, change_id:)
  pr = pull_request(number: pr_number)
  unless pr.body.include?(change_id)
    new_body = pr.body << "\n\nChange-Id: #{change_id}"
    @octokit.update_pull_request(github_repo, pr_number, body: new_body)
  end
end

#comments(pr_number:) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/deodorant/github.rb', line 27

def comments(pr_number:)
  review_comments = pull_request(pr_number).rels[:review_comments].get.data
  comms = review_comments.map do |c|
    com = Comment.new
    com.github_id = c.id
    com.path = c.path
    com.line = c.position
    com.message = c.body
    com.author = c.user.
  end
  comms
end

#pull_request(number:) ⇒ Object



23
24
25
# File 'lib/deodorant/github.rb', line 23

def pull_request(number:)
  @octokit.pull_request(github_repo, number)
end

#pull_requests(state: 'open') ⇒ Object



19
20
21
# File 'lib/deodorant/github.rb', line 19

def pull_requests(state: 'open')
  @octokit.pull_requests(github_repo, state: state)
end

#update_githubObject



14
15
16
17
# File 'lib/deodorant/github.rb', line 14

def update_github
  @git_client.fetch('gerrit')
  @git_client.push('github', 'gerrit/master:refs/heads/master')
end