Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/doctest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Run doctests

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'

- name: Install package
run: pip install .

- name: Run tests
run: python -m doctest riot_release_manager.py
24 changes: 23 additions & 1 deletion riot_release_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,32 @@ def update_branch(repo_dir, remote, branch):
stderr=subprocess.DEVNULL
)


def _merge_commits_to_prs(log: str):
"""Extracts PR numbers from merge commits in a git log.

Args:
log: git log

Returns:
list of PR numbers

>>> log = 'Merge #19495\\n'
>>> log += 'drivers/lsm303agr: Rename deprecated unit G to GForce\\n'
>>> log += 'Merge #19499 #19500\\n'
>>> log += 'sam0/usbdev: partial revert of #17086\\n'
>>> prs = _merge_commits_to_prs(log)
>>> assert prs == [19495, 19499, 19500]
"""
merge_lines = [line for line in log.splitlines() if line.strip().startswith('Merge #')]
return [int(line) for line in re.findall(r"#([0-9]+)", '\n'.join(merge_lines))]
Comment on lines +143 to +144
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should now be

Suggested change
merge_lines = [line for line in log.splitlines() if line.strip().startswith('Merge #')]
return [int(line) for line in re.findall(r"#([0-9]+)", '\n'.join(merge_lines))]
return [int(line["PR"]) for line in re.findall(r"(Merge pull request|Merge) #(?P<PR>[0-9]+)"), log]

this way we are also backwards compatible with bors based PRs.



def get_merged_prs_with_git(repo_dir, since):
log = subprocess.run(git(repo_dir) + ["log", "--merges", "%s..HEAD" % since],
capture_output=True, text=True).stdout
return [int(line) for line in re.findall(r"Merge pull request #([0-9]+) from", log)]
return _merge_commits_to_prs(log)


def get_tags(repo_dir, remote):
subprocess.run(git(repo_dir) + ["fetch", "--tags", remote])
Expand Down
Loading