Include danger gem to enforce basic rules.

Most MRs should have a changelog item, all MR's should have
an assignee, proper description and additional metadata.
parent f04541af
Pipeline #26480203 failed with stages
in 31 minutes and 35 seconds
......@@ -37,7 +37,7 @@ variables:
POSTGRES_DB: $CI_ENVIRONMENT_SLUG
stages:
- test
- prepare
- review
- staging
- canary
......@@ -47,20 +47,6 @@ stages:
- package
- cleanup
.test:
services:
- postgres:latest
variables:
POSTGRES_DB: test
stage: test
image: gliderlabs/herokuish:latest
script:
- setup_test_db
- cp -R . /tmp/app
- /bin/herokuish buildpack test
only:
- branches
lint_package:
stage: package
when: always
......@@ -95,7 +81,6 @@ review:
- terraform_init
- check_kube_domain
- terraform_up
# - download_chart
- ensure_namespace
- install_tiller
- create_secret
......@@ -358,6 +343,19 @@ debug_review:
except:
- master
danger-review:
# Dockerfile in https://gitlab.com/gitlab-org/gitaly/blob/master/_support/dangercontainer/Dockerfile
# For now, reuse existing container to avoid duplicating effort. In future we might consider using one specific for this repository
image: registry.gitlab.com/gitlab-org/gitaly/dangercontainer:latest
stage: prepare
cache: {}
only:
refs:
- branches
script:
- git version
- danger --fail-on-errors=true
# ---------------------------------------------------------------------------
.auto_devops: &auto_devops |
......
danger.import_dangerfile(path: 'scripts/support/changelog')
danger.import_dangerfile(path: 'scripts/support/metadata')
require 'yaml'
NO_CHANGELOG_LABELS = %w[Documentation backstage].freeze
SEE_DOC = "See [the documentation](https://docs.gitlab.com/ce/development/changelog.html).".freeze
MISSING_CHANGELOG_MESSAGE = <<~MSG.freeze
**[CHANGELOG missing](https://docs.gitlab.com/ce/development/changelog.html).**
You can create one with:
```
bin/changelog -m %<mr_iid>s
```
If your merge request doesn't warrant a CHANGELOG entry,
consider adding any of the %<labels>s labels.
#{SEE_DOC}
MSG
def check_changelog(path)
yaml = YAML.safe_load(File.read(path))
fail "`title` should be set, in #{gitlab.html_link(path)}! #{SEE_DOC}" if yaml["title"].nil?
fail "`type` should be set, in #{gitlab.html_link(path)}! #{SEE_DOC}" if yaml["type"].nil?
if yaml["merge_request"].nil?
message "Consider setting `merge_request` to #{gitlab.mr_json["iid"]} in #{gitlab.html_link(path)}. #{SEE_DOC}"
elsif yaml["merge_request"] != gitlab.mr_json["iid"]
fail "Merge request ID was not set to #{gitlab.mr_json["iid"]}! #{SEE_DOC}"
end
rescue StandardError
# YAML could not be parsed, fail the build.
fail "#{gitlab.html_link(path)} isn't valid YAML! #{SEE_DOC}"
end
def presented_no_changelog_labels
NO_CHANGELOG_LABELS.map { |label| "~#{label}" }.join(', ')
end
changelog_needed = (gitlab.mr_labels & NO_CHANGELOG_LABELS).empty?
changelog_found = git.added_files.find { |path| path =~ %r{\Achangelogs/unreleased/} }
if git.modified_files.include?("CHANGELOG.md")
fail "CHANGELOG.md was edited. Please remove the additions and create an entry with `bin/changelog -m #{gitlab.mr_json["iid"]}` instead."
end
if changelog_needed
if changelog_found
check_changelog(path)
else
warn format(MISSING_CHANGELOG_MESSAGE, mr_iid: gitlab.mr_json["iid"], labels: presented_no_changelog_labels)
end
end
if gitlab.mr_body.size < 5
fail "Please provide a proper merge request description."
end
if gitlab.mr_labels.empty?
fail "Please add labels to this merge request."
end
unless gitlab.mr_json["assignee"]
warn "This merge request does not have any assignee yet. Setting an assignee clarifies who needs to take action on the merge request at any given time."
end
has_milestone = !gitlab.mr_json["milestone"].nil?
unless has_milestone
warn "This merge request does not refer to an existing milestone.", sticky: false
end
has_pick_into_stable_label = gitlab.mr_labels.find { |label| label.start_with?('Pick into') }
if gitlab.branch_for_base != "master" && !has_pick_into_stable_label
warn "Most of the time, all merge requests should target `master`. Otherwise, please set the relevant `Pick into X.Y` label."
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