GitLab CI/CD is already set up to run Danger, you have to add this to your .gitlab-ci.yml
file:
include:
- project: 'gitlab-org/quality/pipeline-common'
file: '/ci/danger-review.yml'
Reference: /ci/danger-review.yml
I'm also overriding the ruby image via:
danger-review:
image: ruby:3.2.2
My Gemfile
references the danger-gitlab
gem:
# frozen_string_literal: true
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '3.2.2'
# ...
gem 'danger-gitlab', '~> 8.0.0'
You should be able to add a Ruby-flavored Dangerfile
and it should work:
# frozen_string_literal: true
# ignore inline messages that are outside of the current diff
gitlab.dismiss_out_of_range_messages
message "Author @#{gitlab.mr_author}"
# Make it more obvious that a PR is a work in progress and shouldn't be merged yet
warn('This pull request is a Work in Progress and not ready to merge') if gitlab.mr_title.include? 'WIP'
# Large MR
warn('Big MR! Big changes, big things may happen! Check them.') if git.lines_of_code > 100
# Encourage contributors to write useful descriptions
warn('Please provide a Merge Request description') if gitlab.mr_body.length < 5
# If these are all empty something has gone wrong, better to raise it in a comment
if git.modified_files.empty? && git.added_files.empty? && git.deleted_files.empty?
fail 'This PR has no changes at all, this is likely a developer issue.'
end
if git.deletions > git.insertions
message ' Code Cleanup!'
end
However, in the danger-review
stage it cannot resolve the gitlab
references:
bundler: failed to load command: danger (/usr/local/bundle/bin/danger)
/usr/local/bundle/gems/danger-9.3.0/lib/danger/danger_core/dangerfile.rb:73:in `method_missing': (Danger::DSLError)
[!] Invalid `Dangerfile` file: undefined local variable or method `gitlab' for #<Danger::Dangerfile:0x00007f2243d7dcc0 ...
Any ideas?