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
c7cfc1b9
Commit
c7cfc1b9
authored
Feb 20, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
2074dbef
d3c6f9c4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
128 additions
and
115 deletions
+128
-115
danger/commit_messages/Dangerfile
danger/commit_messages/Dangerfile
+128
-115
No files found.
danger/commit_messages/Dangerfile
View file @
c7cfc1b9
...
...
@@ -64,11 +64,12 @@ def too_many_changed_lines?(commit)
lines_changed_in_commit
(
commit
)
>=
30
end
def
lint_commits
(
commits
)
failures
=
false
emoji_checker
=
EmojiChecker
.
new
def
emoji_checker
@emoji_checker
||=
EmojiChecker
.
new
end
unicode_emoji_regex
=
%r((
def
unicode_emoji_regex
@unicode_emoji_regex
||=
%r((
[
\u
{1F300}-
\u
{1F5FF}] |
[
\u
{1F1E6}-
\u
{1F1FF}] |
[
\u
{2700}-
\u
{27BF}] |
...
...
@@ -77,120 +78,132 @@ def lint_commits(commits)
[
\u
{1F680}-
\u
{1F6FF}] |
[
\u
{2600}-
\u
{26FF}]
))x
end
def
lint_commit
(
commit
)
# For now we'll ignore merge commits, as getting rid of those is a problem
# separate from enforcing good commit messages.
return
false
if
commit
.
message
.
start_with?
(
'Merge branch'
)
# We ignore revert commits as they are well structured by Git already
return
false
if
commit
.
message
.
start_with?
(
'Revert "'
)
failures
=
false
subject
,
separator
,
details
=
commit
.
message
.
split
(
"
\n
"
,
3
)
if
subject
.
split
.
length
<
3
fail_commit
(
commit
,
'The commit subject must contain at least three words'
)
failures
=
true
end
if
subject
.
length
>
72
fail_commit
(
commit
,
'The commit subject may not be longer than 72 characters'
)
failures
=
true
elsif
subject
.
length
>
50
warn_commit
(
commit
,
"This commit's subject line is acceptable, but please try to [reduce it to 50 characters](
#{
URL_LIMIT_SUBJECT
}
)."
)
end
unless
subject_starts_with_capital?
(
subject
)
fail_commit
(
commit
,
'The commit subject must start with a capital letter'
)
failures
=
true
end
if
subject
.
end_with?
(
'.'
)
fail_commit
(
commit
,
'The commit subject must not end with a period'
)
failures
=
true
end
if
separator
&&
!
separator
.
empty?
fail_commit
(
commit
,
'The commit subject and body must be separated by a blank line'
)
failures
=
true
end
details
&
.
each_line
do
|
line
|
line
=
line
.
strip
commits
.
each
do
|
commit
|
# For now we'll ignore merge commits, as getting rid of those is a problem
# separate from enforcing good commit messages.
next
if
commit
.
message
.
start_with?
(
'Merge branch'
)
subject
,
separator
,
details
=
commit
.
message
.
split
(
"
\n
"
,
3
)
if
subject
.
split
.
length
<
3
fail_commit
(
commit
,
'The commit subject must contain at least three words'
)
failures
=
true
end
if
subject
.
length
>
72
fail_commit
(
commit
,
'The commit subject may not be longer than 72 characters'
)
failures
=
true
elsif
subject
.
length
>
50
warn_commit
(
commit
,
"This commit's subject line is acceptable, but please try to [reduce it to 50 characters](
#{
URL_LIMIT_SUBJECT
}
)."
)
end
unless
subject_starts_with_capital?
(
subject
)
fail_commit
(
commit
,
'The commit subject must start with a capital letter'
)
failures
=
true
end
if
subject
.
end_with?
(
'.'
)
fail_commit
(
commit
,
'The commit subject must not end with a period'
)
failures
=
true
end
if
separator
&&
!
separator
.
empty?
fail_commit
(
commit
,
'The commit subject and body must be separated by a blank line'
)
failures
=
true
end
details
&
.
each_line
do
|
line
|
line
=
line
.
strip
next
if
line
.
length
<=
72
url_size
=
line
.
scan
(
%r((https?://
\S
+))
).
sum
{
|
(
url
)
|
url
.
length
}
# If the line includes a URL, we'll allow it to exceed 72 characters, but
# only if the line _without_ the URL does not exceed this limit.
next
if
line
.
length
-
url_size
<=
72
fail_commit
(
commit
,
'The commit body should not contain more than 72 characters per line'
)
failures
=
true
end
if
!
details
&&
too_many_changed_lines?
(
commit
)
fail_commit
(
commit
,
'Commits that change 30 or more lines across at least three files '
\
'must describe these changes in the commit body'
)
failures
=
true
end
if
emoji_checker
.
includes_emoji?
(
commit
.
message
)
fail_commit
(
commit
,
'Avoid the use of Markdown Emoji such as `:+1:`. '
\
'These add no value to the commit message, '
\
'and are displayed as plain text outside of GitLab'
)
failures
=
true
end
if
commit
.
message
.
match?
(
unicode_emoji_regex
)
fail_commit
(
commit
,
'Avoid the use of Unicode Emoji. '
\
'These add no value to the commit message, '
\
'and may not be displayed properly everywhere'
)
failures
=
true
end
if
commit
.
message
.
match?
(
%r(([
\w\-\/
]+)?(#|!|&|%)
\d
+
\b
)
)
fail_commit
(
commit
,
'Use full URLs instead of short references '
\
'(`gitlab-org/gitlab-ce#123` or `!123`), as short references are '
\
'displayed as plain text outside of GitLab'
)
failures
=
true
end
next
if
line
.
length
<=
72
url_size
=
line
.
scan
(
%r((https?://
\S
+))
).
sum
{
|
(
url
)
|
url
.
length
}
# If the line includes a URL, we'll allow it to exceed 72 characters, but
# only if the line _without_ the URL does not exceed this limit.
next
if
line
.
length
-
url_size
<=
72
fail_commit
(
commit
,
'The commit body should not contain more than 72 characters per line'
)
failures
=
true
end
if
!
details
&&
too_many_changed_lines?
(
commit
)
fail_commit
(
commit
,
'Commits that change 30 or more lines across at least three files '
\
'must describe these changes in the commit body'
)
failures
=
true
end
if
emoji_checker
.
includes_emoji?
(
commit
.
message
)
fail_commit
(
commit
,
'Avoid the use of Markdown Emoji such as `:+1:`. '
\
'These add no value to the commit message, '
\
'and are displayed as plain text outside of GitLab'
)
failures
=
true
end
if
commit
.
message
.
match?
(
unicode_emoji_regex
)
fail_commit
(
commit
,
'Avoid the use of Unicode Emoji. '
\
'These add no value to the commit message, '
\
'and may not be displayed properly everywhere'
)
failures
=
true
end
if
commit
.
message
.
match?
(
%r(([
\w\-\/
]+)?(#|!|&|%)
\d
+
\b
)
)
fail_commit
(
commit
,
'Use full URLs instead of short references '
\
'(`gitlab-org/gitlab-ce#123` or `!123`), as short references are '
\
'displayed as plain text outside of GitLab'
)
failures
=
true
end
failures
end
def
lint_commits
(
commits
)
failed
=
commits
.
reject
do
|
commit
|
lint_commit
(
commit
)
end
if
fail
ures
if
fail
ed
.
any?
markdown
(
<<~
MARKDOWN
)
## Commit message standards
...
...
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