From a1fda0192e6773f5ea05839d0f5fa4ff7698062f Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Wed, 9 Jan 2019 20:57:15 +0530 Subject: [PATCH] FIX: Add the comment in the correct line of the commit --- lib/discourse_code_review/importer.rb | 6 +++++- plugin.rb | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/discourse_code_review/importer.rb b/lib/discourse_code_review/importer.rb index 6cea87f..4bffdc2 100644 --- a/lib/discourse_code_review/importer.rb +++ b/lib/discourse_code_review/importer.rb @@ -235,13 +235,17 @@ def import_comment(comment) MD end + custom_fields = { DiscourseCodeReview::GithubId => comment[:id] } + custom_fields[DiscourseCodeReview::CommentPath] = comment[:path] if comment[:path].present? + custom_fields[DiscourseCodeReview::CommentPosition] = comment[:position] if comment[:position].present? + PostCreator.create!( user, raw: context + comment[:body], skip_validations: true, created_at: comment[:created_at], topic_id: topic_id, - custom_fields: { DiscourseCodeReview::GithubId => comment[:id] } + custom_fields: custom_fields ) end end diff --git a/plugin.rb b/plugin.rb index 57d1a08..8b8f25b 100644 --- a/plugin.rb +++ b/plugin.rb @@ -77,6 +77,8 @@ class Engine < ::Rails::Engine CommitHash = 'commit hash' GithubId = 'github id' GithubLogin = 'github login' + CommentPath = 'comment path' + CommentPosition = 'comment position' def self.octokit_client client = Octokit::Client.new @@ -113,9 +115,17 @@ 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 if repo = post.topic.category.custom_fields[DiscourseCodeReview::Importer::GithubRepoName] - comment = client.create_commit_comment(repo, hash, post.raw) + comment = client.create_commit_comment(repo, hash, post.raw, path, nil, position) post.custom_fields[DiscourseCodeReview::GithubId] = comment.id post.save_custom_fields end