Commit a8ac7a8d authored by Rémy Coutable's avatar Rémy Coutable Committed by Bob Van Landuyt

Automatically add the documentation label via Danger

This makes sure MR are well categorized and Technical Writing people
subscribed to the label will get notifications.
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent c9029b83
# frozen_string_literal: true # frozen_string_literal: true
def gitlab_danger
@gitlab_danger ||= GitlabDanger.new(helper.gitlab_helper)
end
docs_paths_to_review = helper.changes_by_category[:docs] docs_paths_to_review = helper.changes_by_category[:docs]
unless docs_paths_to_review.empty? return if docs_paths_to_review.empty?
message 'This merge request adds or changes files that require a review ' \
message 'This merge request adds or changes files that require a review ' \
'from the Technical Writing team.' 'from the Technical Writing team.'
if GitlabDanger.new(helper.gitlab_helper).ci? return unless gitlab_danger.ci?
markdown(<<~MARKDOWN)
markdown(<<~MARKDOWN)
## Documentation review ## Documentation review
The following files require a review from a technical writer: The following files require a review from a technical writer:
...@@ -16,12 +22,12 @@ unless docs_paths_to_review.empty? ...@@ -16,12 +22,12 @@ unless docs_paths_to_review.empty?
The review does not need to block merging this merge request. See the: The review does not need to block merging this merge request. See the:
- [DevOps stages](https://about.gitlab.com/handbook/product/categories/#devops-stages) for the appropriate technical writer for this review. - [Technical Writers assignments](https://about.gitlab.com/handbook/engineering/technical-writing/#designated-technical-writers) for the appropriate technical writer for this review.
- [Documentation workflows](https://docs.gitlab.com/ee/development/documentation/workflow.html) for information on when to assign a merge request for review. - [Documentation workflows](https://docs.gitlab.com/ee/development/documentation/workflow.html) for information on when to assign a merge request for review.
MARKDOWN MARKDOWN
unless gitlab.mr_labels.include?('documentation') unless gitlab.mr_labels.include?('documentation')
warn 'This merge request is missing the ~documentation label.' gitlab.api.update_merge_request(gitlab.mr_json['project_id'],
end gitlab.mr_json['iid'],
end labels: (gitlab.mr_labels + ['documentation']).join(','))
end end
...@@ -58,6 +58,8 @@ changes = helper.changes_by_category ...@@ -58,6 +58,8 @@ changes = helper.changes_by_category
# Ignore any files that are known but uncategorized. Prompt for any unknown files # Ignore any files that are known but uncategorized. Prompt for any unknown files
changes.delete(:none) changes.delete(:none)
# To reinstate roulette for documentation, remove this line.
changes.delete(:docs)
categories = changes.keys - [:unknown] categories = changes.keys - [:unknown]
# Ensure to spin for database reviewer/maintainer when ~database is applied (e.g. to review SQL queries) # Ensure to spin for database reviewer/maintainer when ~database is applied (e.g. to review SQL queries)
......
...@@ -102,8 +102,8 @@ module Gitlab ...@@ -102,8 +102,8 @@ module Gitlab
}.freeze }.freeze
# First-match win, so be sure to put more specific regex at the top... # First-match win, so be sure to put more specific regex at the top...
CATEGORIES = { CATEGORIES = {
%r{\Adoc/} => :none, # To reinstate roulette for documentation, set to `:docs`. %r{\Adoc/} => :docs,
%r{\A(CONTRIBUTING|LICENSE|MAINTENANCE|PHILOSOPHY|PROCESS|README)(\.md)?\z} => :none, # To reinstate roulette for documentation, set to `:docs`. %r{\A(CONTRIBUTING|LICENSE|MAINTENANCE|PHILOSOPHY|PROCESS|README)(\.md)?\z} => :docs,
%r{\A(ee/)?app/(assets|views)/} => :frontend, %r{\A(ee/)?app/(assets|views)/} => :frontend,
%r{\A(ee/)?public/} => :frontend, %r{\A(ee/)?public/} => :frontend,
......
...@@ -167,13 +167,13 @@ RSpec.describe Gitlab::Danger::Helper do ...@@ -167,13 +167,13 @@ RSpec.describe Gitlab::Danger::Helper do
describe '#categories_for_file' do describe '#categories_for_file' do
where(:path, :expected_categories) do where(:path, :expected_categories) do
'doc/foo' | [:none] 'doc/foo' | [:docs]
'CONTRIBUTING.md' | [:none] 'CONTRIBUTING.md' | [:docs]
'LICENSE' | [:none] 'LICENSE' | [:docs]
'MAINTENANCE.md' | [:none] 'MAINTENANCE.md' | [:docs]
'PHILOSOPHY.md' | [:none] 'PHILOSOPHY.md' | [:docs]
'PROCESS.md' | [:none] 'PROCESS.md' | [:docs]
'README.md' | [:none] 'README.md' | [:docs]
'ee/doc/foo' | [:unknown] 'ee/doc/foo' | [:unknown]
'ee/README' | [:unknown] 'ee/README' | [:unknown]
......
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