Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/settings.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
23 changes: 23 additions & 0 deletions db/migrate/20250721192553_enable_github_if_already_installed.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion spec/jobs/create_github_linkback_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions spec/jobs/replace_github_non_permalinks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion spec/lib/commits_populator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
2 changes: 2 additions & 0 deletions spec/lib/github_badges_repo_setting_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/" }
Expand Down
2 changes: 2 additions & 0 deletions spec/lib/github_badges_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions spec/lib/github_linkback_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions spec/lib/github_permalinks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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") }

Expand Down
2 changes: 2 additions & 0 deletions spec/models/github_repo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down