From ff9034059889187f1e47b3b138b75e2da93ac50b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Wed, 3 Jun 2020 15:45:28 +0200 Subject: [PATCH 1/4] Tweak condition for missing log message warning Commits adding CHANGES entries and/or release notes do not need a commit log message. Do not warn about a missing commit log message for such commits to make the warning more meaningful. (cherry picked from commit c13944ca465eaf209f9804e20285477d9deabd5a) --- dangerfile.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dangerfile.py b/dangerfile.py index b017c6aee9..9bbcc005b8 100644 --- a/dangerfile.py +++ b/dangerfile.py @@ -46,7 +46,9 @@ target_branch = danger.gitlab.mr.target_branch # # * The length of the subject line exceeds 72 characters. # -# * There is no log message present (i.e. commit only has a subject). +# * 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 @@ -67,7 +69,10 @@ for commit in danger.git.commits: ) if len(message_lines) > 1 and message_lines[1]: fail(f'No empty line after subject for commit {commit.sha}.') - if len(message_lines) < 3 and not subject.startswith('fixup! '): + if (len(message_lines) < 3 and + 'fixup! ' not in subject and + ' CHANGES ' not in subject and + ' 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(' '): From 53b3c53d73d00e7287eb2dff3e7e7d5e0f61f513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Wed, 3 Jun 2020 15:45:28 +0200 Subject: [PATCH 2/4] Make fetching target branch reliable As GitLab Runner Docker executor caches Git repositories between jobs, prevent the Danger script from attempting to update local refs to ensure "git fetch" returns with an exit code of 0. Use the FETCH_HEAD ref for determining the differences between the merge request branch and its target branch. (cherry picked from commit d558c4cb7812774952c26202410a7001e20a2256) --- dangerfile.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dangerfile.py b/dangerfile.py index 9bbcc005b8..09f28cb4d6 100644 --- a/dangerfile.py +++ b/dangerfile.py @@ -16,9 +16,9 @@ import re def added_lines(target_branch, paths): import subprocess subprocess.check_output(['/usr/bin/git', 'fetch', '--depth', '1', 'origin', - f'{target_branch}:{target_branch}']) - diff = subprocess.check_output(['/usr/bin/git', 'diff', - f'{target_branch}..', '--'] + paths) + target_branch]) + diff = subprocess.check_output(['/usr/bin/git', 'diff', 'FETCH_HEAD..', + '--'] + paths) added_lines = [] for line in diff.splitlines(): if line.startswith(b'+'): From 3dc4c81cadff007d6868ee257aed4a6196eb657a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Wed, 3 Jun 2020 15:45:28 +0200 Subject: [PATCH 3/4] Prevent invalid warnings about missing identifiers The Danger script inspects differences between the current version of a given merge request's target branch and the merge request branch. If the latter falls behind the former, the Danger script will wrongly warn about missing GitLab/RT identifiers because it incorrectly treats the "+++" diff marker as an indication of the merge request adding new lines to a file. Tweak the relevant conditional expression to prevent such invalid warnings from being raised. (cherry picked from commit e062812c38787dbd37c95c6dda1d32c9dce6a3c8) --- dangerfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dangerfile.py b/dangerfile.py index 09f28cb4d6..3a047c974d 100644 --- a/dangerfile.py +++ b/dangerfile.py @@ -21,7 +21,7 @@ def added_lines(target_branch, paths): '--'] + paths) added_lines = [] for line in diff.splitlines(): - if line.startswith(b'+'): + if line.startswith(b'+') and not line.startswith(b'+++'): added_lines.append(line) return added_lines From dddb154ec7b02c243545fe18e090e189fc0e4a22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Wed, 3 Jun 2020 15:45:28 +0200 Subject: [PATCH 4/4] Only run Danger if DANGER_GITLAB_API_TOKEN is set Prevent the Danger GitLab CI job from failing when the GitLab API key to use is not set. (cherry picked from commit 2c90438583b4a7c44ec7be06ad93962f53faaabb) --- .gitlab-ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ff62185a16..e14eff0561 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -428,7 +428,10 @@ danger: script: - danger-python ci -f only: - - merge_requests + refs: + - merge_requests + variables: + - $DANGER_GITLAB_API_TOKEN flake8: <<: *default_triggering_rules