Skip to content

Enable sending additional commit status notifying users of the impending migration when sending a commit status #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .qlty/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*
!configs
!configs/**
!hooks
!hooks/**
!qlty.toml
!.gitignore
1 change: 1 addition & 0 deletions .qlty/configs/.shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source-path=SCRIPTDIR
8 changes: 8 additions & 0 deletions .qlty/configs/.yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
rules:
document-start: disable
quoted-strings:
required: only-when-needed
extra-allowed: ["{|}"]
key-duplicates: {}
octal-values:
forbid-implicit-octal: true
82 changes: 82 additions & 0 deletions .qlty/qlty.toml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby 2.7.5
22 changes: 22 additions & 0 deletions lib/cc/pull_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -103,13 +107,31 @@ 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

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
Expand Down
8 changes: 8 additions & 0 deletions lib/cc/services/github_pull_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/cc/pull_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down