Skip to content

Commit a7b82dc

Browse files
authored
Merge pull request #8949 from bwiseman77/v4.0.x
v4.0.x: CI: Fix a bug in the cherry pick checker.
2 parents e29818b + 7374471 commit a7b82dc

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

.github/workflows/git-commit-checks.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ def _is_entirely_submodule_updates(repo, commit):
186186
return GOOD, "skipped (submodules updates)"
187187

188188
non_existent = dict()
189+
unmerged = dict()
189190
found_cherry_pick_line = False
190191
for match in prog_cp.findall(commit.message):
191192
found_cherry_pick_line = True
@@ -195,9 +196,11 @@ def _is_entirely_submodule_updates(repo, commit):
195196
# These errors mean that the git library recognized the
196197
# hash as a valid commit, but the GitHub Action didn't
197198
# fetch the entire repo, so we don't have all the meta
198-
# data about this commit. Bottom line: it's a good hash.
199-
# So -- no error here.
200-
pass
199+
# data about this commit. This occurs because the commit
200+
# only exists in an as-yet unmerged pull request on github. Therefore, we
201+
# want to fail this commit until the corresponding pull request
202+
# is merged.
203+
unmerged[match] = True
201204
except git.BadName as e:
202205
# Use a dictionary to track the non-existent hashes, just
203206
# on the off chance that the same non-existent hash exists
@@ -208,15 +211,27 @@ def _is_entirely_submodule_updates(repo, commit):
208211

209212
# Process the results for this commit
210213
if found_cherry_pick_line:
211-
if len(non_existent) == 0:
214+
if len(non_existent) == 0 and len(unmerged) == 0:
212215
return GOOD, None
213-
else:
216+
elif len(non_existent) > 0 and len(unmerged) == 0:
214217
str = f"contains a cherry pick message that refers to non-existent commit"
215218
if len(non_existent) > 1:
216219
str += "s"
217220
str += ": "
218221
str += ", ".join(non_existent)
219222
return BAD, str
223+
elif len(non_existent) == 0 and len(unmerged) > 0:
224+
str = f"contains a cherry pick message that refers to a commit that exists, but is in an as-yet unmerged pull request"
225+
if len(non_existent) > 1:
226+
str += "s"
227+
str += ": "
228+
str += ", ".join(unmerged)
229+
return BAD, str
230+
else:
231+
str = f"contains a cherry pick message that refers to both non-existent commits and commits that exist but are in as-yet unmerged pull requests"
232+
str += ": "
233+
str += ", ".join(non_existent + unmerged)
234+
return BAD, str
220235

221236
else:
222237
if config['cherry pick required']:

0 commit comments

Comments
 (0)