From 0b43bf1a382e77571c5808e8ca73ea29d3a95c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Fri, 5 Jan 2024 12:51:13 +0100 Subject: [PATCH] Fix Danger rules for flagging release note issues The logic contained in dangerfile.py incorrectly warns about missing release note changes for merge requests preparing release documentation as such merge requests rename files in the doc/notes/ directory. This (correctly) causes these files to be passed to dangerfile.py via danger.git.created_files and danger.git.deleted_files rather than via danger.git.modified_files, which in turn causes the logic checking the use of the "Release Notes" label to assume that no release notes are added, removed, or modified by a given merge request. Fix by considering all types of file changes (modifications, additions, and removals - which also covers file renaming) when checking whether a given merge request modifies release notes. Update the warning messages accordingly. However, when trying to find release notes added by a given merge request, deleted files must not be considered. Tweak the logic looking for GitLab identifiers in the release notes added by a given merge request so that it only scans modified and added (or renamed) files. (cherry picked from commit 0fec404c64cf367b9c2d676535c50f228355b6b5) --- dangerfile.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/dangerfile.py b/dangerfile.py index 119f6e23a3..cb25ffb3cc 100644 --- a/dangerfile.py +++ b/dangerfile.py @@ -44,6 +44,9 @@ relnotes_issue_or_mr_id_regex = re.compile(rb":gl:`[#!][0-9]+`") release_notes_regex = re.compile(r"doc/(arm|notes)/notes-.*\.(rst|xml)") modified_files = danger.git.modified_files +affected_files = ( + danger.git.modified_files + danger.git.created_files + danger.git.deleted_files +) mr_labels = danger.gitlab.mr.labels target_branch = danger.gitlab.mr.target_branch is_backport = "Backport" in mr_labels or "Backport::Partial" in mr_labels @@ -341,18 +344,18 @@ if changes_added_lines: # MR. release_notes_regex = re.compile(r"doc/(arm|notes)/notes-.*\.(rst|xml)") -release_notes_changed = list(filter(release_notes_regex.match, modified_files)) +release_notes_changed = list(filter(release_notes_regex.match, affected_files)) release_notes_label_set = "Release Notes" in mr_labels if not release_notes_changed: if release_notes_label_set: fail( "This merge request has the *Release Notes* label set. " - "Add a release note or unset the *Release Notes* label." + "Update release notes or unset the *Release Notes* label." ) elif "Customer" in mr_labels: warn( "This merge request has the *Customer* label set. " - "Add a release note unless the changes introduced are trivial." + "Update release notes unless the changes introduced are trivial." ) if release_notes_changed and not release_notes_label_set: fail( @@ -361,7 +364,9 @@ if release_notes_changed and not release_notes_label_set: ) if release_notes_changed: - notes_added_lines = added_lines(target_branch, release_notes_changed) + modified_or_new_files = danger.git.modified_files + danger.git.created_files + release_notes_added = list(filter(release_notes_regex.match, modified_or_new_files)) + notes_added_lines = added_lines(target_branch, release_notes_added) identifiers_found = filter(relnotes_issue_or_mr_id_regex.search, notes_added_lines) if notes_added_lines and not any(identifiers_found): warn("No valid issue/MR identifiers found in added release notes.")