Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
7c772beb
Commit
7c772beb
authored
Oct 25, 2021
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
danger: Don't warn for missing labels while adding some
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
cb5df34a
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
38 additions
and
19 deletions
+38
-19
Dangerfile
Dangerfile
+9
-1
danger/database/Dangerfile
danger/database/Dangerfile
+1
-3
danger/feature_flag/Dangerfile
danger/feature_flag/Dangerfile
+1
-3
danger/product_intelligence/Dangerfile
danger/product_intelligence/Dangerfile
+3
-5
danger/specialization_labels/Dangerfile
danger/specialization_labels/Dangerfile
+1
-5
danger/z_metadata/Dangerfile
danger/z_metadata/Dangerfile
+1
-1
doc/development/dangerbot.md
doc/development/dangerbot.md
+17
-0
tooling/danger/project_helper.rb
tooling/danger/project_helper.rb
+5
-1
No files found.
Dangerfile
View file @
7c772beb
...
...
@@ -17,6 +17,14 @@ end
anything_to_post
=
status_report
.
values
.
any?
{
|
data
|
data
.
any?
}
if
helper
.
ci?
&&
anything_to_post
return
unless
helper
.
ci?
if
project_helper
.
labels_to_add
.
any?
gitlab
.
api
.
update_merge_request
(
gitlab
.
mr_json
[
'project_id'
],
gitlab
.
mr_json
[
'iid'
],
add_labels:
project_helper
.
labels_to_add
.
join
(
','
))
end
if
anything_to_post
markdown
(
"**If needed, you can retry the [`danger-review` job](
#{
ENV
[
'CI_JOB_URL'
]
}
) that generated this comment.**"
)
end
danger/database/Dangerfile
View file @
7c772beb
...
...
@@ -66,8 +66,6 @@ if gitlab.mr_labels.include?('database') || db_paths_to_review.any?
end
unless
helper
.
has_database_scoped_labels?
gitlab
.
api
.
update_merge_request
(
gitlab
.
mr_json
[
'project_id'
],
gitlab
.
mr_json
[
'iid'
],
add_labels:
'database::review pending'
)
project_helper
.
labels_to_add
<<
'database::review pending'
end
end
danger/feature_flag/Dangerfile
View file @
7c772beb
...
...
@@ -58,9 +58,7 @@ def message_for_feature_flag_with_group!(feature_flag:, mr_group_label:)
return
if
feature_flag
.
group_match_mr_label?
(
mr_group_label
)
if
mr_group_label
.
nil?
gitlab
.
api
.
update_merge_request
(
gitlab
.
mr_json
[
'project_id'
],
gitlab
.
mr_json
[
'iid'
],
add_labels:
feature_flag
.
group
)
project_helper
.
labels_to_add
<<
feature_flag
.
group
else
fail
%(`group` is set to ~"#{feature_flag.group}" in #{gitlab.html_link(feature_flag.path)}, which does not match ~"#{mr_group_label}" set on the MR!)
end
...
...
danger/product_intelligence/Dangerfile
View file @
7c772beb
...
...
@@ -13,12 +13,10 @@ MSG
# exit if not matching files or if no product intelligence labels
product_intelligence_paths_to_review
=
project_helper
.
changes_by_category
[
:product_intelligence
]
labels
=
product_intelligence
.
missing_labels
labels
_to_add
=
product_intelligence
.
missing_labels
return
if
product_intelligence_paths_to_review
.
empty?
||
labels
.
empty?
return
if
product_intelligence_paths_to_review
.
empty?
||
labels
_to_add
.
empty?
warn
format
(
CHANGED_FILES_MESSAGE
,
changed_files:
helper
.
markdown_list
(
product_intelligence_paths_to_review
))
gitlab
.
api
.
update_merge_request
(
gitlab
.
mr_json
[
'project_id'
],
gitlab
.
mr_json
[
'iid'
],
add_labels:
labels
)
project_helper
.
labels_to_add
.
concat
(
labels_to_add
)
danger/specialization_labels/Dangerfile
View file @
7c772beb
...
...
@@ -19,8 +19,4 @@ labels_to_add = project_helper.changes_by_category.each_with_object([]) do |(cat
memo
<<
label
if
label
&&
!
gitlab
.
mr_labels
.
include?
(
label
)
end
if
labels_to_add
.
any?
gitlab
.
api
.
update_merge_request
(
gitlab
.
mr_json
[
'project_id'
],
gitlab
.
mr_json
[
'iid'
],
add_labels:
labels_to_add
.
join
(
','
))
end
project_helper
.
labels_to_add
.
concat
(
labels_to_add
)
if
labels_to_add
.
any?
danger/metadata/Dangerfile
→
danger/
z_
metadata/Dangerfile
View file @
7c772beb
...
...
@@ -18,7 +18,7 @@ if gitlab.mr_body.size < 5
fail
"Please provide a proper merge request description."
end
if
(
TYPE_LABELS
&
gitlab
.
mr_labels
).
empty?
if
(
TYPE_LABELS
&
(
gitlab
.
mr_labels
+
project_helper
.
labels_to_add
)
).
empty?
warn
'Please add a [merge request type](https://about.gitlab.com/handbook/engineering/metrics/#work-type-classification) to this merge request.'
end
...
...
doc/development/dangerbot.md
View file @
7c772beb
...
...
@@ -118,6 +118,23 @@ However, you can speed these cycles up somewhat by emptying the
`.gitlab/ci/rails.gitlab-ci.yml`
file in your merge request. Just don't forget
to revert the change before merging!
#### Adding labels via Danger
NOTE:
This is currently applicable to the
[
`gitlab-org/gitlab`
](
https://gitlab.com/gitlab-org/gitlab
)
project only.
Danger is often used to improve MR hygiene by adding labels. Instead of calling the
API directly in your
`Dangerfile`
, add the labels to the
`project_helper.labels_to_add`
array.
The main
`Dangerfile`
will then take care of adding the labels to the MR with a single API call.
#### Shared rules and plugins
If the rule or plugin you implement can be useful for other projects, think about
upstreaming them to the
[
`gitlab-org/gitlab-dangerfiles`
](
https://gitlab.com/gitlab-org/gitlab-dangerfiles
)
project.
#### Enable Danger on a project
To enable the Dangerfile on another existing GitLab project, run the following
extra steps:
...
...
tooling/danger/project_helper.rb
View file @
7c772beb
...
...
@@ -22,12 +22,12 @@ module Tooling
ce_ee_vue_templates
ci_templates
datateam
metadata
feature_flag
roulette
sidekiq_queues
specialization_labels
specs
z_metadata
]
.
freeze
MESSAGE_PREFIX
=
'==>'
...
...
@@ -189,6 +189,10 @@ module Tooling
read_file
(
filename
).
lines
(
chomp:
true
)
end
def
labels_to_add
@labels_to_add
||=
[]
end
private
def
read_file
(
filename
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment