|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import sys |
| 4 | + |
| 5 | +from common.github_utils import ( |
| 6 | + REPO_NAME, |
| 7 | + date_range_query, |
| 8 | + last_release_date, |
| 9 | + search_idom_repo, |
| 10 | +) |
| 11 | + |
| 12 | + |
| 13 | +SECTION_FORMAT_TEMPLATES = { |
| 14 | + "md": lambda title: f"# {title}", |
| 15 | + "rst": lambda title: f"**{title}**\n", |
| 16 | + "text": lambda title: f"{title}\n{'-' * len(title)}", |
| 17 | +} |
| 18 | + |
| 19 | + |
| 20 | +ISSUE_FORMAT_TEMPLATES = { |
| 21 | + "md": lambda title, number, **_: f"- {title} - [#{number}](https://github.com/{REPO_NAME}/issues/{number})", |
| 22 | + "rst": lambda title, number, **_: f"- {title} - :issue:`{number}`", |
| 23 | + "text": lambda title, number, **_: f"- {title} - #{number}", |
| 24 | +} |
| 25 | + |
| 26 | +PULL_REQUEST_FORMAT_TEMPLATES = { |
| 27 | + "md": lambda title, number, **_: f"- {title} - [#{number}](https://github.com/{REPO_NAME}/pull/{number})", |
| 28 | + "rst": lambda title, number, **_: f"- {title} - :pull:`{number}`", |
| 29 | + "text": lambda title, number, **_: f"- {title} - #{number}", |
| 30 | +} |
| 31 | + |
| 32 | + |
| 33 | +def show_issues(format: str): |
| 34 | + print(SECTION_FORMAT_TEMPLATES[format]("Closed Issues")) |
| 35 | + template = ISSUE_FORMAT_TEMPLATES[format] |
| 36 | + query = f"type:issue closed:{date_range_query(last_release_date())}" |
| 37 | + for issue in search_idom_repo(query): |
| 38 | + print(template(**issue)) |
| 39 | + |
| 40 | + |
| 41 | +def show_pull_requests(format: str = "text"): |
| 42 | + print(SECTION_FORMAT_TEMPLATES[format]("Merged Pull Requests")) |
| 43 | + template = PULL_REQUEST_FORMAT_TEMPLATES[format] |
| 44 | + query = f"type:pr merged:{date_range_query(last_release_date())}" |
| 45 | + for pull in search_idom_repo(query): |
| 46 | + print(template(**pull)) |
| 47 | + |
| 48 | + |
| 49 | +def main(format: str = "text"): |
| 50 | + for func in [show_issues, show_pull_requests]: |
| 51 | + func(format) |
| 52 | + print() |
| 53 | + |
| 54 | + |
| 55 | +if __name__ == "__main__": |
| 56 | + main(*sys.argv[1:]) |
0 commit comments