Store the history of the GitHub PRs with a map from pr_number to CommitInfo
| 81 | |
| 82 | |
| 83 | class CommitHistory: |
| 84 | """Store the history of the GitHub PRs with a map from pr_number to CommitInfo""" |
| 85 | |
| 86 | commits: dict[int, CommitInfo] |
| 87 | |
| 88 | @classmethod |
| 89 | def from_git(self, *args): |
| 90 | result = run(["git", "log", "--oneline", *args], capture_output=True) |
| 91 | lines = result.stdout.splitlines() |
| 92 | return CommitHistory(lines) |
| 93 | |
| 94 | def __init__(self, lines): |
| 95 | commits = {} |
| 96 | PR_NUMBER_RE = re.compile(r"\(#[0-9]+\)$") |
| 97 | for history_idx, line in enumerate(lines): |
| 98 | if not (m := PR_NUMBER_RE.search(line)): |
| 99 | continue |
| 100 | pr_number = int(m.group(0)[2:-1]) |
| 101 | shorthash, shortlog = line.split(" ", 1) |
| 102 | commits[pr_number] = CommitInfo(pr_number, shorthash, shortlog, history_idx) |
| 103 | |
| 104 | self.commits = commits |
| 105 | |
| 106 | def lookup_pr(self, pr_number: int) -> CommitInfo: |
| 107 | return self.commits[pr_number] |
| 108 | |
| 109 | def has_pr(self, pr_number: int) -> bool: |
| 110 | return pr_number in self.commits |
| 111 | |
| 112 | |
| 113 | @functools.cache |
no outgoing calls
no test coverage detected
searching dependent graphs…