Allow Danger commit_messages rule to work locally

parent bdded17d
Pipeline #82323124 passed with stages
in 92 minutes and 42 seconds
...@@ -37,6 +37,10 @@ class EmojiChecker ...@@ -37,6 +37,10 @@ class EmojiChecker
end end
end end
def gitlab_danger
@gitlab_danger ||= GitlabDanger.new(helper.gitlab_helper)
end
def fail_commit(commit, message) def fail_commit(commit, message)
fail("#{commit.sha}: #{message}") fail("#{commit.sha}: #{message}")
end end
...@@ -56,6 +60,8 @@ def subject_starts_with_capital?(subject) ...@@ -56,6 +60,8 @@ def subject_starts_with_capital?(subject)
end end
def ce_upstream? def ce_upstream?
return unless gitlab_danger.ci?
gitlab.mr_labels.any? { |label| label == 'CE upstream' } gitlab.mr_labels.any? { |label| label == 'CE upstream' }
end end
...@@ -88,8 +94,8 @@ def lint_commit(commit) # rubocop:disable Metrics/AbcSize ...@@ -88,8 +94,8 @@ def lint_commit(commit) # rubocop:disable Metrics/AbcSize
# We ignore revert commits as they are well structured by Git already # We ignore revert commits as they are well structured by Git already
return false if commit.message.start_with?('Revert "') return false if commit.message.start_with?('Revert "')
is_squash = gitlab.mr_json['squash'] is_squash = gitlab_danger.ci? ? gitlab.mr_json['squash'] : false
is_wip = gitlab.mr_json['work_in_progress'] is_wip = gitlab_danger.ci? ? gitlab.mr_json['work_in_progress'] : false
is_fixup = commit.message.start_with?('fixup!', 'squash!') is_fixup = commit.message.start_with?('fixup!', 'squash!')
if is_fixup if is_fixup
......
...@@ -10,13 +10,13 @@ class GitlabDanger ...@@ -10,13 +10,13 @@ class GitlabDanger
prettier prettier
eslint eslint
database database
commit_messages
].freeze ].freeze
CI_ONLY_RULES ||= %w[ CI_ONLY_RULES ||= %w[
metadata metadata
changelog changelog
specs specs
commit_messages
roulette roulette
single_codebase single_codebase
gitlab_ui_wg gitlab_ui_wg
......
...@@ -9,7 +9,7 @@ describe GitlabDanger do ...@@ -9,7 +9,7 @@ describe GitlabDanger do
describe '.local_warning_message' do describe '.local_warning_message' do
it 'returns an informational message with rules that can run' do it 'returns an informational message with rules that can run' do
expect(described_class.local_warning_message).to eq('==> Only the following Danger rules can be run locally: changes_size, gemfile, documentation, frozen_string, duplicate_yarn_dependencies, prettier, eslint, database') expect(described_class.local_warning_message).to eq('==> Only the following Danger rules can be run locally: changes_size, gemfile, documentation, frozen_string, duplicate_yarn_dependencies, prettier, eslint, database, commit_messages')
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment