Skip to content

Commit

Permalink
Revise parsing of commit history to include also GitHub squash commits
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioRAgostinho committed Sep 2, 2018
1 parent 78d2d22 commit bedf09a
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions .github/change_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,34 @@ def find_pr_list(start: str, end: str):
"""

# Let git generate the proper pr history
cmd = "git log --merges --oneline " + start + ".." + end
cmd = "git log --oneline " + start + ".." + end
cmd = cmd.split()
output = subprocess.run(cmd, cwd=FOLDER, stdout=subprocess.PIPE)
pr_commits = output.stdout.split(b"\n")

# Fetch ids for all merge requests from PRS
pattern_re = re.compile("(\S+) Merge pull request #\d+ from (\S+)")
uid_re = re.compile("#\d+")
merge_re = re.compile("\S+ Merge pull request #(\d+) from \S+")
squash_re = re.compile("\(#(\d+)\)")

ids = []
for pr in pr_commits:

pr_s = str(pr)

# ignore if doesn't follow the usual pattern
if not pattern_re.fullmatch(pr_s):
continue
# Match agains usual pattern
uid = None
match = merge_re.fullmatch(pr_s)

# Match agains squash pattern
if not match:
match = squash_re.search(pr_s)

# Abort
if not match:
continue

# Extract PR uid
uid = int(uid_re.search(pr_s).group(0)[1:])
uid = int(match.group(1))
ids.append(uid)

return ids
Expand Down

0 comments on commit bedf09a

Please sign in to comment.