Class: Saddler::Reporter::Github::Client
- Inherits:
-
Object
- Object
- Saddler::Reporter::Github::Client
- Defined in:
- lib/saddler/reporter/github/client.rb
Overview
GitHub client wrapper
Instance Method Summary collapse
-
#access_token ⇒ String?
Github access token.
- #client ⇒ Octokit::Client
-
#commit_comments(sha) ⇒ Array<Comment>
Parse commit comments into Comment.
-
#commit_patches(sha) ⇒ Patches<Patch>
Patches.
-
#create_commit_comment(comment) ⇒ Sawyer::Resource
Commit comment.
-
#create_issue_comment(comment) ⇒ Sawyer::Resource
Comment.
-
#create_pull_request_review_comment(comment) ⇒ Sawyer::Resource
Hash representing the new comment.
-
#env_pull_id ⇒ Integer?
Pull request id from environment variables.
-
#initialize(repo) ⇒ Client
constructor
A new instance of Client.
-
#issue_comments ⇒ Array<Comment>
Parse issue comments into Comment.
-
#pull_id ⇒ Integer?
Pull request id.
-
#pull_request_patches ⇒ Patches<Patch>
Patches.
-
#pull_request_review_comments ⇒ Array<Comment>
Parse pull request comments into Comment.
-
#pull_requests ⇒ Array<Sawyer::Resource>
Array of pulls.
-
#slug ⇒ String?
Repository’s slug.
Constructor Details
#initialize(repo) ⇒ Client
Returns a new instance of Client.
7 8 9 |
# File 'lib/saddler/reporter/github/client.rb', line 7 def initialize(repo) @repo = repo end |
Instance Method Details
#access_token ⇒ String?
Returns github access token.
120 121 122 |
# File 'lib/saddler/reporter/github/client.rb', line 120 def access_token ENV['GITHUB_ACCESS_TOKEN'] end |
#client ⇒ Octokit::Client
115 116 117 |
# File 'lib/saddler/reporter/github/client.rb', line 115 def client @client ||= Octokit::Client.new(access_token: access_token) end |
#commit_comments(sha) ⇒ Array<Comment>
Returns parse commit comments into Comment.
14 15 16 17 18 |
# File 'lib/saddler/reporter/github/client.rb', line 14 def commit_comments(sha) client.commit_comments(slug, sha).map do |comment| Comment.new(sha, comment.body, comment.path, comment.position) end end |
#commit_patches(sha) ⇒ Patches<Patch>
Returns patches.
33 34 35 36 37 38 39 |
# File 'lib/saddler/reporter/github/client.rb', line 33 def commit_patches(sha) patches = Patches.new client.commit(slug, sha).files.each do |file| patches << Patch.new(file.patch, file: file.filename, secure_hash: sha) end patches end |
#create_commit_comment(comment) ⇒ Sawyer::Resource
Returns Commit comment.
25 26 27 28 |
# File 'lib/saddler/reporter/github/client.rb', line 25 def create_commit_comment(comment) client.create_commit_comment(slug, comment.sha, comment.body, comment.path, nil, comment.position) end |
#create_issue_comment(comment) ⇒ Sawyer::Resource
Returns Comment.
54 55 56 |
# File 'lib/saddler/reporter/github/client.rb', line 54 def create_issue_comment(comment) client.add_comment(slug, pull_id, comment.body) end |
#create_pull_request_review_comment(comment) ⇒ Sawyer::Resource
Returns Hash representing the new comment.
79 80 81 82 |
# File 'lib/saddler/reporter/github/client.rb', line 79 def create_pull_request_review_comment(comment) client.create_pull_request_comment(slug, pull_id, comment.body, comment.sha, comment.path, comment.position) end |
#env_pull_id ⇒ Integer?
Returns pull request id from environment variables.
125 126 127 |
# File 'lib/saddler/reporter/github/client.rb', line 125 def env_pull_id @env_pull_id ||= EnvPullRequest.new.pull_request_id end |
#issue_comments ⇒ Array<Comment>
Returns parse issue comments into Comment.
42 43 44 45 46 47 |
# File 'lib/saddler/reporter/github/client.rb', line 42 def issue_comments client.issue_comments(slug, pull_id).map do |comment| sha = nil Comment.new(sha, comment.body, comment.path, comment.position) end end |
#pull_id ⇒ Integer?
Returns pull request id.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/saddler/reporter/github/client.rb', line 85 def pull_id return @pull_id unless @pull_id.nil? if env_pull_id @pull_id = env_pull_id return @pull_id end if @repo.current_branch pull = pull_requests.find { |pr| pr[:head][:ref] == @repo.current_branch } if pull @pull_id = pull[:number].to_i return @pull_id end end end |
#pull_request_patches ⇒ Patches<Patch>
Returns patches.
66 67 68 69 70 71 72 |
# File 'lib/saddler/reporter/github/client.rb', line 66 def pull_request_patches patches = Patches.new client.pull_request_files(slug, pull_id).each do |file| patches << Patch.new(file.patch, file: file.filename, secure_hash: @repo.merging_sha) end patches end |
#pull_request_review_comments ⇒ Array<Comment>
Returns parse pull request comments into Comment.
59 60 61 62 63 |
# File 'lib/saddler/reporter/github/client.rb', line 59 def pull_request_review_comments client.pull_request_comments(slug, pull_id).map do |comment| Comment.new(comment.commit_id, comment.body, comment.path, comment.position) end end |
#pull_requests ⇒ Array<Sawyer::Resource>
Returns Array of pulls.
105 106 107 |
# File 'lib/saddler/reporter/github/client.rb', line 105 def pull_requests @pull_requests ||= client.pull_requests(slug) end |
#slug ⇒ String?
Returns repository’s slug.
110 111 112 |
# File 'lib/saddler/reporter/github/client.rb', line 110 def slug @slug ||= @repo.slug end |