Skip to content

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
vinothkannans committed Jan 10, 2019
1 parent a1fda01 commit 2912e9c
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions plugin.rb
Expand Up @@ -115,18 +115,15 @@ def self.octokit_client
if !post.custom_fields[DiscourseCodeReview::GithubId] && post.user
if token = post.user.custom_fields[DiscourseCodeReview::UserToken]
client = Octokit::Client.new(access_token: token)
path, position = begin
fields = post.reply_to_post&.custom_fields
if fields.present? && fields[DiscourseCodeReview::CommentPath].present? && fields[DiscourseCodeReview::CommentPosition].present?
[fields[DiscourseCodeReview::CommentPath], fields[DiscourseCodeReview::CommentPosition]]
else
[nil, nil]
end
end
fields = post.reply_to_post&.custom_fields || {}
path = fields[DiscourseCodeReview::CommentPath]
position = fields[DiscourseCodeReview::CommentPosition]

if repo = post.topic.category.custom_fields[DiscourseCodeReview::Importer::GithubRepoName]
comment = client.create_commit_comment(repo, hash, post.raw, path, nil, position)
post.custom_fields[DiscourseCodeReview::GithubId] = comment.id
post.custom_fields[DiscourseCodeReview::CommentPath] = path if path.present?
post.custom_fields[DiscourseCodeReview::CommentPosition] = position if position.present?
post.save_custom_fields
end
end
Expand Down

0 comments on commit 2912e9c

Please sign in to comment.