Skip to content

Commit

Permalink
Skip length check for lines containing references
Browse files Browse the repository at this point in the history
The Danger GitLab CI job currently flags excessively long lines in
commit log messages.  Exclude lines containing references (i.e. starting
with "[1]", "[2]", etc.) from this check.  This allows e.g. long URLs to
be included in commit log messages without triggering Danger warnings.
  • Loading branch information
kempniu committed Jan 18, 2021
1 parent 801d13f commit 09964e8
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions dangerfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,21 @@ def lines_containing(lines, string):
#
# * The length of the subject line exceeds 72 characters.
#
# * There is no log message present (i.e. commit only has a subject) and the
# subject line does not contain any of the following strings: "fixup! ",
# " CHANGES ", " release note".
# * There is no log message present (i.e. commit only has a subject) and
# the subject line does not contain any of the following strings:
# "fixup!", " CHANGES ", " release note".
#
# * Any line of the log message is longer than 72 characters. This rule is
# not evaluated for lines starting with four spaces, which allows long
# lines to be included in the commit log message by prefixing them with
# four spaces (useful for pasting compiler warnings, static analyzer
# messages, log lines, etc.)
# not evaluated for:
#
# - lines starting with four spaces, which allows long lines to be
# included in the commit log message by prefixing them with four
# spaces (useful for pasting compiler warnings, static analyzer
# messages, log lines, etc.),
#
# - lines which contain references (i.e. those starting with "[1]",
# "[2]", etc.) which allows e.g. long URLs to be included in the
# commit log message.

fixup_error_logged = False
for commit in danger.git.commits:
Expand All @@ -86,7 +92,9 @@ def lines_containing(lines, string):
' release note' not in subject):
warn(f'Please write a log message for commit {commit.sha}.')
for line in message_lines[2:]:
if len(line) > 72 and not line.startswith(' '):
if (len(line) > 72 and
not line.startswith(' ') and
not re.match(r'\[[0-9]+\]', line)):
warn(
f'Line too long in log message for commit {commit.sha}: '
f'```{line}``` ({len(line)} > 72 characters).'
Expand Down

0 comments on commit 09964e8

Please sign in to comment.