From 21ce67c4ce3a47947d0e303087e0da8de5669868 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Mon, 21 Jul 2025 23:19:54 +0200 Subject: [PATCH] DEV: Disable the plugin by default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …and preserve the current setting on existing sites --- config/settings.yml | 3 ++- ...2553_enable_github_if_already_installed.rb | 23 +++++++++++++++++++ spec/jobs/create_github_linkback_spec.rb | 5 +++- .../replace_github_non_permalinks_spec.rb | 2 ++ spec/lib/commits_populator_spec.rb | 5 +++- ...thub_badges_repo_setting_validator_spec.rb | 2 ++ spec/lib/github_badges_spec.rb | 2 ++ ...ack_access_token_setting_validator_spec.rb | 2 ++ spec/lib/github_linkback_spec.rb | 2 ++ spec/lib/github_permalinks_spec.rb | 2 ++ spec/models/github_repo_spec.rb | 2 ++ 11 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20250721192553_enable_github_if_already_installed.rb diff --git a/config/settings.yml b/config/settings.yml index fae65e7..d3dbee6 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -1,5 +1,6 @@ discourse_github: - enable_discourse_github_plugin: true + enable_discourse_github_plugin: + default: false github_linkback_enabled: default: false github_linkback_projects: diff --git a/db/migrate/20250721192553_enable_github_if_already_installed.rb b/db/migrate/20250721192553_enable_github_if_already_installed.rb new file mode 100644 index 0000000..d9e91ac --- /dev/null +++ b/db/migrate/20250721192553_enable_github_if_already_installed.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class EnableGithubIfAlreadyInstalled < ActiveRecord::Migration[7.2] + def up + installed_at = DB.query_single(<<~SQL)&.first + SELECT created_at FROM schema_migration_details WHERE version='20190617035051' + SQL + + if installed_at && installed_at < 1.hour.ago + # The plugin was installed before we changed it to be disabled-by-default + # Therefore, if there is no existing database value, enable the plugin + execute <<~SQL + INSERT INTO site_settings(name, data_type, value, created_at, updated_at) + VALUES('enable_discourse_github_plugin', 5, 't', NOW(), NOW()) + ON CONFLICT (name) DO NOTHING + SQL + end + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/spec/jobs/create_github_linkback_spec.rb b/spec/jobs/create_github_linkback_spec.rb index 897a2b0..63aa8cd 100644 --- a/spec/jobs/create_github_linkback_spec.rb +++ b/spec/jobs/create_github_linkback_spec.rb @@ -3,7 +3,10 @@ require "rails_helper" describe Jobs::CreateGithubLinkback do - before { SiteSetting.github_linkback_enabled = true } + before do + enable_current_plugin + SiteSetting.github_linkback_enabled = true + end it "shouldn't raise error if post not found" do post = Fabricate(:post) diff --git a/spec/jobs/replace_github_non_permalinks_spec.rb b/spec/jobs/replace_github_non_permalinks_spec.rb index b800f6e..61a9498 100644 --- a/spec/jobs/replace_github_non_permalinks_spec.rb +++ b/spec/jobs/replace_github_non_permalinks_spec.rb @@ -21,6 +21,8 @@ let(:github_response_body2) { { sha: "7e4edcfae8a3c0e664b836ee7c5f28b47853a2f8", commit: {} } } before do + enable_current_plugin + stub_request(:get, "https://api.github.com/repos/test/onebox/commits/master").to_return( status: 200, body: github_response_body.to_json, diff --git a/spec/lib/commits_populator_spec.rb b/spec/lib/commits_populator_spec.rb index 84d8f9b..b89da0a 100644 --- a/spec/lib/commits_populator_spec.rb +++ b/spec/lib/commits_populator_spec.rb @@ -9,7 +9,10 @@ let!(:site_admin1) { Fabricate(:admin) } let!(:site_admin2) { Fabricate(:admin) } - before { SiteSetting.github_badges_enabled = true } + before do + enable_current_plugin + SiteSetting.github_badges_enabled = true + end context "when invalid credentials have been provided for octokit" do before { Octokit::Client.any_instance.expects(:branches).raises(Octokit::Unauthorized) } diff --git a/spec/lib/github_badges_repo_setting_validator_spec.rb b/spec/lib/github_badges_repo_setting_validator_spec.rb index 9857278..10f4f8b 100644 --- a/spec/lib/github_badges_repo_setting_validator_spec.rb +++ b/spec/lib/github_badges_repo_setting_validator_spec.rb @@ -5,6 +5,8 @@ describe GithubBadgesRepoSettingValidator do subject(:validator) { described_class.new } + before { enable_current_plugin } + describe "#valid_value?" do context "when a github URL is provided" do let(:value) { "https://github.com/discourse/discourse/" } diff --git a/spec/lib/github_badges_spec.rb b/spec/lib/github_badges_spec.rb index ba8fe3d..34aa130 100644 --- a/spec/lib/github_badges_spec.rb +++ b/spec/lib/github_badges_spec.rb @@ -12,6 +12,8 @@ let(:merge_commit_user) { Fabricate(:user) } let(:staged_user) { Fabricate(:user, staged: true) } + before { enable_current_plugin } + describe "committer and contributor badges" do before do roles = DiscourseGithubPlugin::CommitsPopulator::ROLES diff --git a/spec/lib/github_linkback_access_token_setting_validator_spec.rb b/spec/lib/github_linkback_access_token_setting_validator_spec.rb index 62eb2bd..0910b70 100644 --- a/spec/lib/github_linkback_access_token_setting_validator_spec.rb +++ b/spec/lib/github_linkback_access_token_setting_validator_spec.rb @@ -7,6 +7,8 @@ let(:value) { SecureRandom.hex(10) } + before { enable_current_plugin } + describe "#valid_value?" do context "when an Octokit::Unauthorized error is raised, meaning the access token cannot access a repo" do before do diff --git a/spec/lib/github_linkback_spec.rb b/spec/lib/github_linkback_spec.rb index 45660ae..5670ed8 100644 --- a/spec/lib/github_linkback_spec.rb +++ b/spec/lib/github_linkback_spec.rb @@ -39,6 +39,8 @@ RAW + before { enable_current_plugin } + describe "#should_enqueue?" do let(:post_without_link) { Fabricate.build(:post, raw: "Hello github!") } let(:small_action_post) do diff --git a/spec/lib/github_permalinks_spec.rb b/spec/lib/github_permalinks_spec.rb index ae17348..9d0af6b 100644 --- a/spec/lib/github_permalinks_spec.rb +++ b/spec/lib/github_permalinks_spec.rb @@ -3,6 +3,8 @@ require "rails_helper" describe GithubPermalinks do + before { enable_current_plugin } + context "when it doesn't contain github link to the file" do let(:post) { Fabricate(:post, raw: "there is no github link") } diff --git a/spec/models/github_repo_spec.rb b/spec/models/github_repo_spec.rb index 5b65824..ee1c503 100644 --- a/spec/models/github_repo_spec.rb +++ b/spec/models/github_repo_spec.rb @@ -3,6 +3,8 @@ require "rails_helper" describe DiscourseGithubPlugin::GithubRepo do + before { enable_current_plugin } + it "strips .git from url" do SiteSetting.github_badges_repos = "https://github.com/discourse/discourse.git" repo = DiscourseGithubPlugin::GithubRepo.repos.first