Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 1e93b90

Browse files
authored
DEV: Disable the plugin by default (#136)
…and preserve the current setting on existing sites
1 parent 905d92c commit 1e93b90

11 files changed

+47
-3
lines changed

config/settings.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
discourse_github:
2-
enable_discourse_github_plugin: true
2+
enable_discourse_github_plugin:
3+
default: false
34
github_linkback_enabled:
45
default: false
56
github_linkback_projects:
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
class EnableGithubIfAlreadyInstalled < ActiveRecord::Migration[7.2]
4+
def up
5+
installed_at = DB.query_single(<<~SQL)&.first
6+
SELECT created_at FROM schema_migration_details WHERE version='20190617035051'
7+
SQL
8+
9+
if installed_at && installed_at < 1.hour.ago
10+
# The plugin was installed before we changed it to be disabled-by-default
11+
# Therefore, if there is no existing database value, enable the plugin
12+
execute <<~SQL
13+
INSERT INTO site_settings(name, data_type, value, created_at, updated_at)
14+
VALUES('enable_discourse_github_plugin', 5, 't', NOW(), NOW())
15+
ON CONFLICT (name) DO NOTHING
16+
SQL
17+
end
18+
end
19+
20+
def down
21+
raise ActiveRecord::IrreversibleMigration
22+
end
23+
end

spec/jobs/create_github_linkback_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
require "rails_helper"
44

55
describe Jobs::CreateGithubLinkback do
6-
before { SiteSetting.github_linkback_enabled = true }
6+
before do
7+
enable_current_plugin
8+
SiteSetting.github_linkback_enabled = true
9+
end
710

811
it "shouldn't raise error if post not found" do
912
post = Fabricate(:post)

spec/jobs/replace_github_non_permalinks_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
let(:github_response_body2) { { sha: "7e4edcfae8a3c0e664b836ee7c5f28b47853a2f8", commit: {} } }
2222

2323
before do
24+
enable_current_plugin
25+
2426
stub_request(:get, "https://api.github.com/repos/test/onebox/commits/master").to_return(
2527
status: 200,
2628
body: github_response_body.to_json,

spec/lib/commits_populator_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
let!(:site_admin1) { Fabricate(:admin) }
1010
let!(:site_admin2) { Fabricate(:admin) }
1111

12-
before { SiteSetting.github_badges_enabled = true }
12+
before do
13+
enable_current_plugin
14+
SiteSetting.github_badges_enabled = true
15+
end
1316

1417
context "when invalid credentials have been provided for octokit" do
1518
before { Octokit::Client.any_instance.expects(:branches).raises(Octokit::Unauthorized) }

spec/lib/github_badges_repo_setting_validator_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
describe GithubBadgesRepoSettingValidator do
66
subject(:validator) { described_class.new }
77

8+
before { enable_current_plugin }
9+
810
describe "#valid_value?" do
911
context "when a github URL is provided" do
1012
let(:value) { "https://github.com/discourse/discourse/" }

spec/lib/github_badges_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
let(:merge_commit_user) { Fabricate(:user) }
1313
let(:staged_user) { Fabricate(:user, staged: true) }
1414

15+
before { enable_current_plugin }
16+
1517
describe "committer and contributor badges" do
1618
before do
1719
roles = DiscourseGithubPlugin::CommitsPopulator::ROLES

spec/lib/github_linkback_access_token_setting_validator_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
let(:value) { SecureRandom.hex(10) }
99

10+
before { enable_current_plugin }
11+
1012
describe "#valid_value?" do
1113
context "when an Octokit::Unauthorized error is raised, meaning the access token cannot access a repo" do
1214
before do

spec/lib/github_linkback_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
4040
RAW
4141

42+
before { enable_current_plugin }
43+
4244
describe "#should_enqueue?" do
4345
let(:post_without_link) { Fabricate.build(:post, raw: "Hello github!") }
4446
let(:small_action_post) do

spec/lib/github_permalinks_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require "rails_helper"
44

55
describe GithubPermalinks do
6+
before { enable_current_plugin }
7+
68
context "when it doesn't contain github link to the file" do
79
let(:post) { Fabricate(:post, raw: "there is no github link") }
810

0 commit comments

Comments
 (0)