FEATURE: Better interoperability with assign plugin. (#4)

FEATURE: Better interoperability with assign plugin. (#4)

diff --git a/app/controllers/discourse_code_review/code_review_controller.rb b/app/controllers/discourse_code_review/code_review_controller.rb
index 0400aaa..9fa4bdd 100644
--- a/app/controllers/discourse_code_review/code_review_controller.rb
+++ b/app/controllers/discourse_code_review/code_review_controller.rb
@@ -71,6 +71,10 @@ module DiscourseCodeReview
         action_code: "followup"
       )
 
+      if SiteSetting.code_review_auto_assign_on_followup && topic.user.staff?
+        DiscourseEvent.trigger(:assign_topic, topic, topic.user, current_user)
+      end
+
       render_next_topic(topic.category_id)
 
     end
@@ -102,6 +106,10 @@ module DiscourseCodeReview
         action_code: "approved"
       )
 
+      if SiteSetting.code_review_auto_unassign_on_approve && topic.user.staff?
+        DiscourseEvent.trigger(:unassign_topic, topic, current_user)
+      end
+
       render_next_topic(topic.category_id)
 
     end
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 97eadf8..dcabec4 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -9,3 +9,5 @@ en:
     code_review_approved_tag: 'Tag to apply to approved 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'
+    code_review_auto_unassign_on_approve: 'Automatically unassign topic on approve'
diff --git a/config/settings.yml b/config/settings.yml
index 795cc89..e740a72 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -16,3 +16,5 @@ plugins:
   code_review_allow_self_approval:
     client: true
     default: false
+  code_review_auto_assign_on_followup: true
+  code_review_auto_unassign_on_approve: true
diff --git a/spec/requests/discourse_code_review/code_review_controller_spec.rb b/spec/requests/discourse_code_review/code_review_controller_spec.rb
index aee3368..f43a633 100644
--- a/spec/requests/discourse_code_review/code_review_controller_spec.rb
+++ b/spec/requests/discourse_code_review/code_review_controller_spec.rb
@@ -80,4 +80,27 @@ describe DiscourseCodeReview::CodeReviewController do
       expect(json["next_topic_url"]).to eq(unread_commit.topic.relative_url)
     end
   end
+
+  it 'assigns and unassigns topic on followup and approve' do
+    skip if !defined?(TopicAssigner)
+
+    SiteSetting.assign_enabled = true
+    SiteSetting.code_review_auto_assign_on_followup = true
+    SiteSetting.code_review_auto_unassign_on_approve = true
+    SiteSetting.code_review_allow_self_approval = true
+
+    user = Fabricate(:admin)
+    commit = create_post(raw: "this is a fake commit", user: user, tags: ["hi", SiteSetting.code_review_pending_tag])
+
+    sign_in user
+
+    post '/code-review/followup.json', params: { topic_id: commit.topic_id }
+    expect(response.status).to eq(200)
+    expect(TopicQuery.new(user, assigned: user.username).list_latest.topics).to eq([commit.topic])
+
+    post '/code-review/approve.json', params: { topic_id: commit.topic_id }
+    expect(response.status).to eq(200)
+    expect(TopicQuery.new(user, assigned: user.username).list_latest.topics).to eq([])
+  end
+
 end

GitHub sha: 91986a33

1 Like