From c617f97784ff898cfea7bbbc6ab6c92eb409009d Mon Sep 17 00:00:00 2001 From: Tom Krizek Date: Thu, 15 Dec 2022 17:52:52 +0100 Subject: [PATCH] danger: check backport commits for original commit IDs A full backport must have all the commit from the original MR and the original commit IDs must be referenced in the backport commit messages. If the criteria above is not met, the MR should be marked as a partial backport. In that case, any discrepencies are only logged as informative messages rather than failures. --- dangerfile.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/dangerfile.py b/dangerfile.py index de7a6cef0c..a73e6259c8 100644 --- a/dangerfile.py +++ b/dangerfile.py @@ -209,6 +209,28 @@ if is_backport: f"Original MR !{original_mr_id} has not been merged. " "Please re-run `danger` check once it's merged." ) + else: # check for commit IDs once original MR is merged + original_mr_commits = list(original_mr.commits(all=True)) + backport_mr_commits = list(mr.commits(all=True)) + for orig_commit in original_mr_commits: + for backport_commit in backport_mr_commits: + if orig_commit.id in backport_commit.message: + break + else: + msg = ( + f"Commit {orig_commit.id} from original MR !{original_mr_id} " + "is not referenced in any of the backport commits." + ) + if not is_full_backport: + message(msg) + else: + msg += ( + " Please use `-x` when cherry-picking to include " + "the full original commit ID. Alternately, use the " + "`Backport::Partial` label if not all original " + "commits are meant to be backported." + ) + fail(msg) if not is_backport and not version_labels: fail( "If this merge request is a backport, set the *Backport* label and "