diff --git a/.qlty/.gitignore b/.qlty/.gitignore new file mode 100644 index 0000000..3036618 --- /dev/null +++ b/.qlty/.gitignore @@ -0,0 +1,7 @@ +* +!configs +!configs/** +!hooks +!hooks/** +!qlty.toml +!.gitignore diff --git a/.qlty/configs/.shellcheckrc b/.qlty/configs/.shellcheckrc new file mode 100644 index 0000000..6a38d92 --- /dev/null +++ b/.qlty/configs/.shellcheckrc @@ -0,0 +1 @@ +source-path=SCRIPTDIR \ No newline at end of file diff --git a/.qlty/configs/.yamllint.yaml b/.qlty/configs/.yamllint.yaml new file mode 100644 index 0000000..d22fa77 --- /dev/null +++ b/.qlty/configs/.yamllint.yaml @@ -0,0 +1,8 @@ +rules: + document-start: disable + quoted-strings: + required: only-when-needed + extra-allowed: ["{|}"] + key-duplicates: {} + octal-values: + forbid-implicit-octal: true diff --git a/.qlty/qlty.toml b/.qlty/qlty.toml new file mode 100644 index 0000000..ce1d938 --- /dev/null +++ b/.qlty/qlty.toml @@ -0,0 +1,82 @@ +# This file was automatically generated by `qlty init`. +# You can modify it to suit your needs. +# We recommend you to commit this file to your repository. +# +# This configuration is used by both Qlty CLI and Qlty Cloud. +# +# Qlty CLI -- Code quality toolkit for developers +# Qlty Cloud -- Fully automated Code Health Platform +# +# Try Qlty Cloud: https://qlty.sh +# +# For a guide to configuration, visit https://qlty.sh/d/config +# Or for a full reference, visit https://qlty.sh/d/qlty-toml +config_version = "0" + +exclude_patterns = [ + "*_min.*", + "*-min.*", + "*.min.*", + "**/.yarn/**", + "**/*.d.ts", + "**/assets/**", + "**/bower_components/**", + "**/build/**", + "**/cache/**", + "**/config/**", + "**/db/**", + "**/deps/**", + "**/dist/**", + "**/extern/**", + "**/external/**", + "**/generated/**", + "**/Godeps/**", + "**/gradlew/**", + "**/mvnw/**", + "**/node_modules/**", + "**/protos/**", + "**/seed/**", + "**/target/**", + "**/templates/**", + "**/testdata/**", + "**/vendor/**", +] + +test_patterns = [ + "**/test/**", + "**/spec/**", + "**/*.test.*", + "**/*.spec.*", + "**/*_test.*", + "**/*_spec.*", + "**/test_*.*", + "**/spec_*.*", +] + +[smells] +mode = "comment" + +[smells.boolean_logic] +threshold = 4 + +[smells.file_complexity] +threshold = 55 + +[smells.return_statements] +threshold = 4 + +[smells.nested_control_flow] +threshold = 4 + +[smells.function_parameters] +threshold = 4 + +[smells.function_complexity] +threshold = 5 + +[smells.duplication] +threshold = 22 + +[[source]] +name = "default" +default = true diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..a4023dc --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +ruby 2.7.5 diff --git a/lib/cc/pull_requests.rb b/lib/cc/pull_requests.rb index 9d26cb8..bcae0e3 100644 --- a/lib/cc/pull_requests.rb +++ b/lib/cc/pull_requests.rb @@ -79,6 +79,10 @@ def test_status_code raise NotImplementedError end + def create_migration_notice_commit_status_enabled? + false + end + def receive_test_status url = base_status_url("0" * 40) params = { state: "success" } @@ -103,6 +107,7 @@ def receive_request(*permitted_statuses, call_method) if permitted_statuses.flatten.include?(state) && report_status? send(call_method.to_s + "_#{state}") + create_migration_notice_commit_status(commit_sha) else @response = simple_failure("Unknown state") end @@ -110,6 +115,23 @@ def receive_request(*permitted_statuses, call_method) response end + def create_migration_notice_commit_status(commit_sha) + return unless create_migration_notice_commit_status_enabled? + + # Temporarily store the original target_url and replace it + original_target_url = @payload["details_url"] + @payload["details_url"] = "https://docs.qlty.sh/migration/guide" + + update_status( + "error", + "Code Climate has been replaced by Qlty and will be EOL imminently.", + "codeclimate/upgrade" + ) + + # Restore the original target_url + @payload["details_url"] = original_target_url + end + def presenter CC::Service::PullRequestsPresenter.new(@payload) end diff --git a/lib/cc/services/github_pull_requests.rb b/lib/cc/services/github_pull_requests.rb index 605d3f0..8f66443 100644 --- a/lib/cc/services/github_pull_requests.rb +++ b/lib/cc/services/github_pull_requests.rb @@ -19,6 +19,10 @@ class Config < CC::Service::Config attribute :rollout_percentage, Axiom::Types::Integer, label: "Author Rollout Percentage", description: "The percentage of users to report status for" + attribute :create_migration_notice_commit_status, Axiom::Types::Boolean, + label: "Create Migration Notice", + description: "Post a notice about the migration to Qlty.sh as a failing commit status", + default: false validates :oauth_token, presence: true end @@ -135,4 +139,8 @@ def response_includes_repo_scope?(response) def test_status_code 422 end + + def create_migration_notice_commit_status_enabled? + config.create_migration_notice_commit_status + end end diff --git a/spec/cc/pull_requests_spec.rb b/spec/cc/pull_requests_spec.rb index 8c5760b..24fedde 100644 --- a/spec/cc/pull_requests_spec.rb +++ b/spec/cc/pull_requests_spec.rb @@ -8,7 +8,7 @@ end context "when the status is valid" do - let(:instance) { CC::PullRequests.new({}, name: "test", state: payload_status) } + let(:instance) { CC::PullRequests.new({}, commit_sha: "abcd", name: "test", state: payload_status) } let(:response) do { ok: true,