Commit 5955f420 authored by Stan Hu's avatar Stan Hu

Merge branch '202299-migrate-the-gemfile-danger-check-to-static-analysis-instead' into 'master'

Migrate the Gemfile Danger check to static-analysis instead

Closes #202299

See merge request gitlab-org/gitlab!25986
parents d8e1cfcf 4a3cf430
GEMFILE_LOCK_NOT_UPDATED_MESSAGE_SHORT = <<~MSG.freeze
%<gemfile>s was updated but %<gemfile_lock>s wasn't updated.
MSG
GEMFILE_LOCK_NOT_UPDATED_MESSAGE_FULL = <<~MSG.freeze
**#{GEMFILE_LOCK_NOT_UPDATED_MESSAGE_SHORT}**
Usually, when %<gemfile>s is updated, you should run
```
bundle install
```
or
```
bundle update <the-added-or-updated-gem>
```
and commit the %<gemfile_lock>s changes.
MSG
gemfile_modified = git.modified_files.include?("Gemfile")
gemfile_lock_modified = git.modified_files.include?("Gemfile.lock")
if gemfile_modified && !gemfile_lock_modified
gitlab_danger = GitlabDanger.new(helper.gitlab_helper)
format_str = gitlab_danger.ci? ? GEMFILE_LOCK_NOT_UPDATED_MESSAGE_FULL : GEMFILE_LOCK_NOT_UPDATED_MESSAGE_SHORT
message = format(format_str,
gemfile: gitlab_danger.html_link("Gemfile"),
gemfile_lock: gitlab_danger.html_link("Gemfile.lock")
)
warn(message)
end
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
class GitlabDanger class GitlabDanger
LOCAL_RULES ||= %w[ LOCAL_RULES ||= %w[
changes_size changes_size
gemfile
documentation documentation
frozen_string frozen_string
duplicate_yarn_dependencies duplicate_yarn_dependencies
......
#!/bin/sh
gemfile_lock_changed() {
if [ -n "$(git diff --name-only -- Gemfile.lock)" ]; then
cat << EOF
Gemfile was updated but Gemfile.lock was not updated.
Usually, when Gemfile is updated, you should run
\`\`\`
bundle install
\`\`\`
or
\`\`\`
bundle update <the-added-or-updated-gem>
\`\`\`
and commit the Gemfile.lock changes.
EOF
exit 1
fi
}
gemfile_lock_changed
...@@ -49,7 +49,8 @@ def jobs_to_run(node_index, node_total) ...@@ -49,7 +49,8 @@ def jobs_to_run(node_index, node_total)
%w[scripts/lint-conflicts.sh], %w[scripts/lint-conflicts.sh],
%w[scripts/lint-rugged], %w[scripts/lint-rugged],
%w[scripts/frontend/check_no_partial_karma_jest.sh], %w[scripts/frontend/check_no_partial_karma_jest.sh],
%w[scripts/lint-changelog-filenames] %w[scripts/lint-changelog-filenames],
%w[scripts/gemfile_lock_changed.sh]
] ]
case node_total case node_total
......
...@@ -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, commit_messages') expect(described_class.local_warning_message).to eq('==> Only the following Danger rules can be run locally: changes_size, 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