FEATURE: Support repos where the default branch isn't master (#51)

FEATURE: Support repos where the default branch isn’t master (#51)

diff --git a/lib/discourse_code_review/source/github_pr_querier.rb b/lib/discourse_code_review/source/github_pr_querier.rb
index 998341a..88bcc73 100644
--- a/lib/discourse_code_review/source/github_pr_querier.rb
+++ b/lib/discourse_code_review/source/github_pr_querier.rb
@@ -234,7 +234,7 @@ module DiscourseCodeReview
       end
     end
 
-    def is_merged_into_master?(pr)
+    def is_merged_into_default?(pr)
       response =
         graphql_client.execute("
           query {
@@ -242,14 +242,18 @@ module DiscourseCodeReview
               pullRequest(number: #{pr.issue_number.to_json}) {
                 baseRefName,
                 merged,
-              }
+              },
+              defaultBranchRef {
+                name,
+              },
             }
           }
         ")
 
+      default_branch = response[:repository][:defaultBranchRef][:name]
       pr_response = response[:repository][:pullRequest]
 
-      pr_response[:baseRefName] == 'master' && pr_response[:merged]
+      pr_response[:baseRefName] == default_branch && pr_response[:merged]
     end
 
     def merged_by(pr)
diff --git a/lib/discourse_code_review/source/github_pr_service.rb b/lib/discourse_code_review/source/github_pr_service.rb
index 2c32fad..29a5ca5 100644
--- a/lib/discourse_code_review/source/github_pr_service.rb
+++ b/lib/discourse_code_review/source/github_pr_service.rb
@@ -183,7 +183,7 @@ module DiscourseCodeReview
 
     def merge_info(pr)
       approvers =
-        if pr_querier.is_merged_into_master?(pr)
+        if pr_querier.is_merged_into_default?(pr)
           pr_querier.approvers(pr)
         else
           []

GitHub sha: d9bd02ee

This commit appears in #51 which was merged by danielwaterworth.

See how the merge info doesn’t say that the pr was approved, but it was. That’s what this fixes.

2 Likes