Skip to content

Commit

Permalink
Use GitHub API to get commits, since they won't all be fetched on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jspahrsummers committed Jul 28, 2024
1 parent e74e402 commit 6b52764
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions script/markdown_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@
auth = Auth.Token(GITHUB_TOKEN)
client = Github(auth=auth, per_page=1)

def summary_from_commit_message(message: str) -> str:
return message.splitlines()[0]

def main():
last_successful_run: WorkflowRun = client.get_repo("jspahrsummers/Merc").get_workflow("main.yml").get_runs(status="success")[0]
repo = client.get_repo("jspahrsummers/Merc")

last_successful_run: WorkflowRun = repo.get_workflow("main.yml").get_runs(status="success")[0]
from_commit = last_successful_run.head_sha
head_commit = subprocess.check_output(["git","rev-parse","HEAD"]).decode().strip()

commit_log = subprocess.check_output(["git", "log", "--first-parent", "--reverse", r"--pretty=tformat:* [%s](<https://github.com/jspahrsummers/Merc/commit/%H>)", f"{from_commit}..{head_commit}"]).decode().strip()
commit_log = "\n".join(f"* [{summary_from_commit_message(c.commit.message)}](<{c.commit.html_url}>)" for c in repo.compare(base=from_commit, head=head_commit).commits)
print(f"[Changes](<https://github.com/jspahrsummers/Merc/compare/{from_commit}...{head_commit}>):\n{commit_log}")

if __name__ == "__main__":
Expand Down

0 comments on commit 6b52764

Please sign in to comment.