support configuration of github repo

support configuration of github repo

From e6411ce8a098962cc02b04a52f051c728d5c6ef2 Mon Sep 17 00:00:00 2001
From: Sam <sam.saffron@gmail.com>
Date: Tue, 6 Nov 2018 17:33:14 +1100
Subject: [PATCH] support configuration of github repo


diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
new file mode 100644
index 0000000..9e4b857
--- /dev/null
+++ b/config/locales/server.en.yml
@@ -0,0 +1,3 @@
+en:
+  site_settings:
+    code_review_github_repo: 'name of github repo you wish to track eg: discourse/discourse'
diff --git a/config/settings.yml b/config/settings.yml
index 979d438..4aa341b 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -1,4 +1,5 @@
 plugins:
+  code_review_github_repo: ""
   code_review_pending_category_id:
     hidden: true
     default: -1
diff --git a/jobs/import_commits.rb b/jobs/import_commits.rb
index cb21762..d688e63 100644
--- a/jobs/import_commits.rb
+++ b/jobs/import_commits.rb
@@ -1,7 +1,7 @@
 module Jobs
 
   class ::DiscourseCodeReview::ImportCommits < Jobs::Scheduled
-    #every 1.minute
+    every 1.minute
 
     def execute(args = nil)
 
diff --git a/plugin.rb b/plugin.rb
index f42bad1..e671b63 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -34,6 +34,8 @@ after_initialize do
 
     def self.commits_since(hash = nil)
 
+      git("pull")
+
       hash ||= last_commit
 
       # hash name email subject body
@@ -68,7 +70,14 @@ after_initialize do
     end
 
     def self.git(command)
-      Dir.chdir('/home/sam/Source/discourse') do
+      raise "No repo configured" if SiteSetting.code_review_github_repo.blank?
+      path = (Rails.root + "tmp/code-review-repo").to_s
+
+      if !File.exist?(path)
+        `git clone https://github.com/#{SiteSetting.code_review_github_repo}.git '#{path}'`
+      end
+
+      Dir.chdir(path) do
         `git #{command}`.strip
       end
     end

GitHub

1 Like