FEATURE: Add skip commit feature

FEATURE: Add skip commit feature

Allow users to skip commits by default when clicking skip they are skipped for code_review_skip_duration_minutes minutes which is set to 2 days.

Long term we may consider making this a per user option. Not sure.

diff --git a/app/controllers/discourse_code_review/code_review_controller.rb b/app/controllers/discourse_code_review/code_review_controller.rb
index 4f7e289..ae81434 100644
--- a/app/controllers/discourse_code_review/code_review_controller.rb
+++ b/app/controllers/discourse_code_review/code_review_controller.rb
@@ -69,6 +69,17 @@ module DiscourseCodeReview
       render plain: '"ok"'
     end
 
+    def skip
+      topic = Topic.find_by(id: params[:topic_id])
+
+      State::CommitApproval.skip(
+        topic,
+        current_user
+      )
+
+      render_next_topic(topic.category_id)
+    end
+
     def followup
       topic = Topic.find_by(id: params[:topic_id])
 
@@ -108,9 +119,20 @@ module DiscourseCodeReview
         )
       SQL
 
+      sanitized_join =
+        ActiveRecord::Base.send(
+          :sanitize_sql_array,
+          [
+            "LEFT OUTER JOIN skipped_code_reviews cr ON cr.topic_id = topics.id AND cr.user_id = ? and cr.expires_at > ?",
+            current_user.id,
+            Time.zone.now
+          ]
+        )
+
       next_topic = Topic
         .joins(:tags)
         .joins("LEFT OUTER JOIN topic_users ON (topics.id = topic_users.topic_id AND topic_users.user_id = #{current_user.id})")
+        .joins(sanitized_join)
         .where('tags.name = ?', SiteSetting.code_review_pending_tag)
         .where('topics.user_id <> ?', current_user.id)
         .where(
@@ -118,7 +140,12 @@ module DiscourseCodeReview
           user_id: current_user.id,
           notification_level: CategoryUser.notification_levels[:muted]
         )
-        .order('case when last_read_post_number IS NULL then 0 else 1 end asc', "case when category_id = #{category_id.to_i} then 0 else 1 end asc", 'bumped_at desc')
+        .order(
+          'case when cr.expires_at IS NULL then 0 else 1 end asc',
+          'case when last_read_post_number IS NULL then 0 else 1 end asc',
+          "case when category_id = #{category_id.to_i} then 0 else 1 end asc",
+          'bumped_at desc'
+        )
         .first
 
       url = next_topic&.relative_url
diff --git a/app/models/skipped_code_review.rb b/app/models/skipped_code_review.rb
new file mode 100644
index 0000000..626d60a
--- /dev/null
+++ b/app/models/skipped_code_review.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class DiscourseCodeReview::SkippedCodeReview < ActiveRecord::Base
+  self.table_name = 'skipped_code_reviews'
+  belongs_to :user
+  belongs_to :topic
+end
diff --git a/assets/javascripts/discourse/initializers/init-code-review.js.es6 b/assets/javascripts/discourse/initializers/init-code-review.js.es6
index 7669c09..67169a3 100644
--- a/assets/javascripts/discourse/initializers/init-code-review.js.es6
+++ b/assets/javascripts/discourse/initializers/init-code-review.js.es6
@@ -39,6 +39,10 @@ function initialize(api) {
     }),
   });
 
+  function allowSkip(currentUser, topic, siteSettings) {
+    return allowApprove(currentUser, topic, siteSettings);
+  }
+
   function allowApprove(currentUser, topic, siteSettings) {
     if (!currentUser) {
       return false;
@@ -73,7 +77,7 @@ function initialize(api) {
   api.registerTopicFooterButton({
     id: "approve",
     icon: "thumbs-up",
-    priority: 250,
+    priority: 260,
     label: "code_review.approve.label",
     title: "code_review.approve.title",
     action() {
@@ -93,9 +97,31 @@ function initialize(api) {
   });
 
   api.registerTopicFooterButton({
+    id: "skip",
+    icon: "angle-double-right",
+    priority: 250,
+    label: "code_review.skip.label",
+    title: "code_review.skip.title",
+    action() {
+      actOnCommit(this.topic, "skip");
+    },
+    dropdown() {
+      return this.site.mobileView;
+    },
+    classNames: ["skip"],
+    dependentKeys: ["topic.tags"],
+    displayed() {
+      return (
+        this.get("currentUser.staff") &&
+        allowSkip(this.currentUser, this.topic, this.siteSettings)
+      );
+    },
+  });
+
+  api.registerTopicFooterButton({
     id: "followup",
     icon: "far-clock",
-    priority: 250,
+    priority: 240,
     label: "code_review.followup.label",
     title: "code_review.followup.title",
     action() {
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index b1b9c3d..4a880e2 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -10,17 +10,20 @@ en:
     notifications:
       code_review:
         commit_approved:
-          single: "\"%{topicTitle}\" approved"
+          single: '"%{topicTitle}" approved'
           multiple: "%{numApprovedCommits} commits were approved"
           title: "commit approved"
     code_review:
-      title: 'Code Review'
+      title: "Code Review"
       approve:
         title: "Approve commit"
         label: "Approve"
       followup:
         title: "Follow up commit"
         label: "Follow Up"
+      skip:
+        title: "Skip commit"
+        label: "Skip"
       approval_given: "Approval Given"
       approval_pending: "Approval Pending"
       github_webhooks: "Github Webhooks"
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index d80d142..a6d4a16 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -1,25 +1,26 @@
 en:
   site_settings:
-    code_review_enabled: 'enable Discourse code review'
+    code_review_enabled: "enable Discourse code review"
     code_review_github_token: "Token to use for github API, this can be generated via https://github.com/settings/tokens/new . 'repo' permission is required if sync_to_github or code_review_allow_private_clone is enabled"
-    code_review_sync_to_github: 'REQUIRES: code_review_github_token, should comments here be sent to github?'
-    code_review_catch_up_commits: 'When a new repo is added create this number of topics for old commits'
-    code_review_allow_private_clone: 'REQUIRES: code_review_github_token, will clone the repos as the associated user, this safeguard is in place to disable cloning of private repos on public sites.'
-    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_commit_tag: 'Tag to apply to commit topics'
-    code_review_pull_request_tag: 'Tag to apply to pull request topics'
-    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'
-    code_review_github_organizations: 'Github organizations (comma separated) containing repos that should be synced here'
-    code_review_approve_approved_prs: 'Auto approve commits that exist in approved pull requests'
-    code_review_default_mute_new_categories: 'Mute for all users categories created by the plugin'
-    code_review_default_parent_category: 'Default parent category for categories created by the plugin'
-    code_review_theme: 'Enable custom code review theme'
+    code_review_sync_to_github: "REQUIRES: code_review_github_token, should comments here be sent to github?"
+    code_review_catch_up_commits: "When a new repo is added create this number of topics for old commits"
+    code_review_allow_private_clone: "REQUIRES: code_review_github_token, will clone the repos as the associated user, this safeguard is in place to disable cloning of private repos on public sites."
+    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"

[... diff too long, it was truncated ...]

GitHub sha: 7c03f0d3

1 Like

That’s super cool :tada:

1 Like