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
Show 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
...
@@ -17,6 +17,14 @@ end
anything_to_post
=
status_report
.
values
.
any?
{
|
data
|
data
.
any?
}
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.**"
)
markdown
(
"**If needed, you can retry the [`danger-review` job](
#{
ENV
[
'CI_JOB_URL'
]
}
) that generated this comment.**"
)
end
end
danger/database/Dangerfile
View file @
7c772beb
...
@@ -66,8 +66,6 @@ if gitlab.mr_labels.include?('database') || db_paths_to_review.any?
...
@@ -66,8 +66,6 @@ if gitlab.mr_labels.include?('database') || db_paths_to_review.any?
end
end
unless
helper
.
has_database_scoped_labels?
unless
helper
.
has_database_scoped_labels?
gitlab
.
api
.
update_merge_request
(
gitlab
.
mr_json
[
'project_id'
],
project_helper
.
labels_to_add
<<
'database::review pending'
gitlab
.
mr_json
[
'iid'
],
add_labels:
'database::review pending'
)
end
end
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:)
...
@@ -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
)
return
if
feature_flag
.
group_match_mr_label?
(
mr_group_label
)
if
mr_group_label
.
nil?
if
mr_group_label
.
nil?
gitlab
.
api
.
update_merge_request
(
gitlab
.
mr_json
[
'project_id'
],
project_helper
.
labels_to_add
<<
feature_flag
.
group
gitlab
.
mr_json
[
'iid'
],
add_labels:
feature_flag
.
group
)
else
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!)
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
end
...
...
danger/product_intelligence/Dangerfile
View file @
7c772beb
...
@@ -13,12 +13,10 @@ MSG
...
@@ -13,12 +13,10 @@ MSG
# exit if not matching files or if no product intelligence labels
# exit if not matching files or if no product intelligence labels
product_intelligence_paths_to_review
=
project_helper
.
changes_by_category
[
:product_intelligence
]
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
))
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'
],
project_helper
.
labels_to_add
.
concat
(
labels_to_add
)
gitlab
.
mr_json
[
'iid'
],
add_labels:
labels
)
danger/specialization_labels/Dangerfile
View file @
7c772beb
...
@@ -19,8 +19,4 @@ labels_to_add = project_helper.changes_by_category.each_with_object([]) do |(cat
...
@@ -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
)
memo
<<
label
if
label
&&
!
gitlab
.
mr_labels
.
include?
(
label
)
end
end
if
labels_to_add
.
any?
project_helper
.
labels_to_add
.
concat
(
labels_to_add
)
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
danger/metadata/Dangerfile
→
danger/
z_
metadata/Dangerfile
View file @
7c772beb
...
@@ -18,7 +18,7 @@ if gitlab.mr_body.size < 5
...
@@ -18,7 +18,7 @@ if gitlab.mr_body.size < 5
fail
"Please provide a proper merge request description."
fail
"Please provide a proper merge request description."
end
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.'
warn
'Please add a [merge request type](https://about.gitlab.com/handbook/engineering/metrics/#work-type-classification) to this merge request.'
end
end
...
...
doc/development/dangerbot.md
View file @
7c772beb
...
@@ -118,6 +118,23 @@ However, you can speed these cycles up somewhat by emptying the
...
@@ -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
`.gitlab/ci/rails.gitlab-ci.yml`
file in your merge request. Just don't forget
to revert the change before merging!
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
To enable the Dangerfile on another existing GitLab project, run the following
extra steps:
extra steps:
...
...
tooling/danger/project_helper.rb
View file @
7c772beb
...
@@ -22,12 +22,12 @@ module Tooling
...
@@ -22,12 +22,12 @@ module Tooling
ce_ee_vue_templates
ce_ee_vue_templates
ci_templates
ci_templates
datateam
datateam
metadata
feature_flag
feature_flag
roulette
roulette
sidekiq_queues
sidekiq_queues
specialization_labels
specialization_labels
specs
specs
z_metadata
]
.
freeze
]
.
freeze
MESSAGE_PREFIX
=
'==>'
MESSAGE_PREFIX
=
'==>'
...
@@ -189,6 +189,10 @@ module Tooling
...
@@ -189,6 +189,10 @@ module Tooling
read_file
(
filename
).
lines
(
chomp:
true
)
read_file
(
filename
).
lines
(
chomp:
true
)
end
end
def
labels_to_add
@labels_to_add
||=
[]
end
private
private
def
read_file
(
filename
)
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