FEATURE: Sync unmerged commits

FEATURE: Sync unmerged commits

Commits now get synced if they are merged or have discussions on them. Unmerged commits get an unmerged tag.

diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 293101e..1f896ee 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -8,6 +8,7 @@ en:
     code_review_pending_tag: 'Tag to apply to pending commits'
     code_review_followup_tag: 'Tag to apply to follow up commits'
     code_review_approved_tag: 'Tag to apply to approved commits'
+    code_review_unmerged_tag: 'Tag to apply to unmerged commits'
     code_review_github_webhook_secret: 'web hook secret string to use use for https://sitename/code-review/webhook'
     code_review_allow_self_approval: 'Allow self approval of commits'
     code_review_auto_assign_on_followup: 'Automatically assign topic to author on followup'
diff --git a/config/settings.yml b/config/settings.yml
index 3737ad6..1c39cd1 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -13,6 +13,7 @@ plugins:
   code_review_followup_tag:
     client: true
     default: "follow-up"
+  code_review_unmerged_tag: "unmerged"
   code_review_github_webhook_secret: ""
   code_review_allow_self_approval:
     client: true
diff --git a/lib/discourse_code_review/importer.rb b/lib/discourse_code_review/importer.rb
index 9cca305..9111195 100644
--- a/lib/discourse_code_review/importer.rb
+++ b/lib/discourse_code_review/importer.rb
@@ -99,7 +99,7 @@ module DiscourseCodeReview
     end
 
     def import_commit(commit)
-      return unless github_repo.master_contains?(commit[:hash])
+      merged = github_repo.master_contains?(commit[:hash])
 
       link = <<~LINK
         [<small>GitHub</small>](https://github.com/#{github_repo.name}/commit/#{commit[:hash]})
@@ -138,14 +138,43 @@ module DiscourseCodeReview
           .pluck(:topic_id)
           .first
 
-      if topic_id.nil?
+      if topic_id.present?
+        if merged
+          topic = Topic.find(topic_id)
+          tags = topic.tags.pluck(:name)
+
+          merged_tags = [
+            SiteSetting.code_review_pending_tag,
+            SiteSetting.code_review_approved_tag,
+            SiteSetting.code_review_followup_tag
+          ]
+
+          if (tags & merged_tags).empty?
+            tags << SiteSetting.code_review_pending_tag
+            tags -= [SiteSetting.code_review_unmerged_tag]
+
+            DiscourseTagging.tag_topic_by_names(
+              topic,
+              Discourse.system_user.guardian,
+              tags
+            )
+          end
+        end
+      else
+        tags =
+          if merged
+            [SiteSetting.code_review_pending_tag]
+          else
+            [SiteSetting.code_review_unmerged_tag]
+          end
+
         post = PostCreator.create!(
           user,
           raw: raw,
           title: title,
           created_at: commit[:date],
           category: category_id,
-          tags: [SiteSetting.code_review_pending_tag],
+          tags: tags,
           skip_validations: true,
         )

GitHub sha: 27b1b139