Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ $ saddler report \

like this. See [Saddler](https://github.com/packsaddle/ruby-saddler).

## Debugging

You can use `reporter-github-log_octokit` option to log octokit's requests and responses.

```
$ saddler report \
--require saddler/reporter/github \
--reporter Saddler::Reporter::Github::PullRequestReviewComment \
--options 'reporter-github-log_octokit:true'
```

## Requirement

Expand Down
20 changes: 18 additions & 2 deletions lib/saddler/reporter/github/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ module Github
# GitHub client wrapper
class Client
# @param repo [Repository] git repository
def initialize(repo)
# @param log_octokit [Boolean] if true, enable octokit logging
def initialize(repo, log_octokit: false)
@repo = repo
@log_octokit = log_octokit
end

# @param sha [String] target commit sha
Expand Down Expand Up @@ -113,7 +115,21 @@ def slug

# @return [Octokit::Client]
def client
@client ||= Octokit::Client.new(access_token: access_token)
@client ||= if @log_octokit
# see: https://github.com/octokit/octokit.rb/tree/v5.6.1#debugging
middleware = Faraday::RackBuilder.new do |builder|
builder.use Octokit::Middleware::FollowRedirects
builder.use Octokit::Response::RaiseError
builder.use Octokit::Response::FeedParser
builder.response :logger, nil, { headers: true, bodies: { request: true, response: true } } do |logger|
logger.filter(/(Authorization: "(token|Bearer) )(\w+)/, '\1[REMOVED]')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of my concerns is leaking credentials to public ci log.

end
builder.adapter Faraday.default_adapter
end
Octokit::Client.new(access_token: access_token, middleware: middleware)
else
Octokit::Client.new(access_token: access_token)
end
end

# @return [String, nil] github access token
Expand Down
2 changes: 1 addition & 1 deletion lib/saddler/reporter/github/commit_comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def report(messages, options)
sha = options['sha'] || repo.head.sha
data = parse(messages)

client = Client.new(repo)
client = Client.new(repo, log_octokit: options['reporter-github-log_octokit'])
# fetch commit_comments
commit_comments = client.commit_comments(sha)

Expand Down
2 changes: 1 addition & 1 deletion lib/saddler/reporter/github/commit_review_comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def report(messages, options)
sha = options['sha'] || repo.head.sha
data = parse(messages)

client = Client.new(repo)
client = Client.new(repo, log_octokit: options['reporter-github-log_octokit'])
# fetch commit_comments
commit_comments = client.commit_comments(sha)

Expand Down
6 changes: 3 additions & 3 deletions lib/saddler/reporter/github/pull_request_comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ class PullRequestComment
include Helper

# @param messages [String] checkstyle string
# @param _options [Hash]
# @param options [Hash]
#
# @return [void]
#
# @see https://developer.github.com/v3/issues/comments/#create-a-comment
def report(messages, _options)
def report(messages, options)
repo_path = '.'
repo = Repository.new(repo_path)

data = parse(messages)

client = Client.new(repo)
client = Client.new(repo, log_octokit: options['reporter-github-log_octokit'])
# fetch pull_request_comments(issue)
pull_request_comments = client.issue_comments

Expand Down
6 changes: 3 additions & 3 deletions lib/saddler/reporter/github/pull_request_review_comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ class PullRequestReviewComment
include Helper

# @param messages [String] checkstyle string
# @param _options [Hash]
# @param options [Hash]
#
# @return [void]
#
# @see https://developer.github.com/v3/pulls/comments/#create-a-comment
def report(messages, _options)
def report(messages, options)
repo_path = '.'
repo = Repository.new(repo_path)

data = parse(messages)
client = Client.new(repo)
client = Client.new(repo, log_octokit: options['reporter-github-log_octokit'])
# fetch pull_request_review_comments
pull_request_review_comments = client.pull_request_review_comments

Expand Down