Skip to content

Commit 8555336

Browse files
authored
Add: automatically detect squashes so we don't depend on a label (#6)
1 parent b3ada72 commit 8555336

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

backport/backport.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
title
4949
commits(first: 100) {
5050
totalCount
51+
nodes {
52+
commit {
53+
messageHeadline
54+
}
55+
}
5156
}
5257
mergedAt
5358
mergeCommit {
@@ -179,9 +184,19 @@ def main():
179184
else:
180185
print(f"Merging #{pr['node']['number']}: {pr['node']['title']}")
181186

182-
if any(True for node in pr["node"]["labels"]["nodes"] if node["name"] == "backport squash"):
183-
print(" -> was squashed")
184-
pr["node"]["commits"]["totalCount"] = 1
187+
# In case of multiple commits, check if it was squashed or rebased.
188+
# We do this by comparing commit titles. As if you rebased, they have
189+
# to be identical.
190+
if pr["node"]["commits"]["totalCount"] > 1:
191+
for i in range(pr["node"]["commits"]["totalCount"]):
192+
commit = pr["node"]["commits"]["totalCount"] - i - 1
193+
commit_str = f'{pr["node"]["mergeCommit"]["oid"]}' + "".join(["^"] * commit)
194+
195+
res = do_command(["git", "log", "--pretty=format:%s", f"{commit_str}^..{commit_str}"])
196+
if res.stdout.decode() != pr["node"]["commits"]["nodes"][i]["commit"]["messageHeadline"]:
197+
print(" -> was squashed")
198+
pr["node"]["commits"]["totalCount"] = 1
199+
break
185200

186201
for i in range(pr["node"]["commits"]["totalCount"]):
187202
if resume_i is not None:

0 commit comments

Comments
 (0)