Commit 7de4fdd7 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch...

Merge branch '226929-automatically-label-mr-that-changes-doc-directory-with-documentation-label' into 'master'

Automatically add the documentation label via Danger

Closes #226929

See merge request gitlab-org/gitlab!36041
parents bca25c0b a8ac7a8d
# frozen_string_literal: true
def gitlab_danger
@gitlab_danger ||= GitlabDanger.new(helper.gitlab_helper)
end
docs_paths_to_review = helper.changes_by_category[:docs]
unless docs_paths_to_review.empty?
message 'This merge request adds or changes files that require a review ' \
'from the Technical Writing team.'
return if docs_paths_to_review.empty?
message 'This merge request adds or changes files that require a review ' \
'from the Technical Writing team.'
return unless gitlab_danger.ci?
if GitlabDanger.new(helper.gitlab_helper).ci?
markdown(<<~MARKDOWN)
## Documentation review
markdown(<<~MARKDOWN)
## Documentation review
The following files require a review from a technical writer:
The following files require a review from a technical writer:
* #{docs_paths_to_review.map { |path| "`#{path}`" }.join("\n* ")}
* #{docs_paths_to_review.map { |path| "`#{path}`" }.join("\n* ")}
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.
- [Documentation workflows](https://docs.gitlab.com/ee/development/documentation/workflow.html) for information on when to assign a merge request for review.
MARKDOWN
- [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.
MARKDOWN
unless gitlab.mr_labels.include?('documentation')
warn 'This merge request is missing the ~documentation label.'
end
end
unless gitlab.mr_labels.include?('documentation')
gitlab.api.update_merge_request(gitlab.mr_json['project_id'],
gitlab.mr_json['iid'],
labels: (gitlab.mr_labels + ['documentation']).join(','))
end
......@@ -62,6 +62,8 @@ changes = helper.changes_by_category
# Ignore any files that are known but uncategorized. Prompt for any unknown files
changes.delete(:none)
# To reinstate roulette for documentation, remove this line.
changes.delete(:docs)
categories = changes.keys - [:unknown]
# Ensure to spin for database reviewer/maintainer when ~database is applied (e.g. to review SQL queries)
......
......@@ -102,8 +102,8 @@ module Gitlab
}.freeze
# First-match win, so be sure to put more specific regex at the top...
CATEGORIES = {
%r{\Adoc/} => :none, # To reinstate roulette for documentation, set to `:docs`.
%r{\A(CONTRIBUTING|LICENSE|MAINTENANCE|PHILOSOPHY|PROCESS|README)(\.md)?\z} => :none, # To reinstate roulette for documentation, set to `:docs`.
%r{\Adoc/} => :docs,
%r{\A(CONTRIBUTING|LICENSE|MAINTENANCE|PHILOSOPHY|PROCESS|README)(\.md)?\z} => :docs,
%r{\A(ee/)?app/(assets|views)/} => :frontend,
%r{\A(ee/)?public/} => :frontend,
......
......@@ -167,13 +167,13 @@ RSpec.describe Gitlab::Danger::Helper do
describe '#categories_for_file' do
where(:path, :expected_categories) do
'doc/foo' | [:none]
'CONTRIBUTING.md' | [:none]
'LICENSE' | [:none]
'MAINTENANCE.md' | [:none]
'PHILOSOPHY.md' | [:none]
'PROCESS.md' | [:none]
'README.md' | [:none]
'doc/foo' | [:docs]
'CONTRIBUTING.md' | [:docs]
'LICENSE' | [:docs]
'MAINTENANCE.md' | [:docs]
'PHILOSOPHY.md' | [:docs]
'PROCESS.md' | [:docs]
'README.md' | [:docs]
'ee/doc/foo' | [: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