CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
veeralakrishna

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: veeralakrishna/DataCamp-Project-Solutions-Python
Path: blob/master/update_changelog.py
Views: 1229
1
import os
2
import sys
3
import datetime
4
from github import Github
5
from dateutil.parser import parse
6
7
commit_sha = sys.argv[1]
8
github_token = sys.argv[2]
9
10
g = Github(github_token)
11
12
repo = g.get_repo("veeralakrishna/DataCamp-Project-Solutions-Python")
13
14
def get_associated_issues_prs(commit_sha):
15
commit = repo.get_commit(commit_sha)
16
commit_date = parse(commit.commit.author.date)
17
18
issues = repo.get_issues(state="closed", since=commit_date)
19
prs = repo.get_pulls(state="closed", sort="created", direction="desc", base=commit_sha)
20
21
associated_issues_prs = []
22
23
for issue in issues:
24
associated_issues_prs.append(f"Issue {issue.number}: {issue.title}")
25
26
for pr in prs:
27
associated_issues_prs.append(f"PR {pr.number}: {pr.title}")
28
29
return associated_issues_prs
30
31
def update_changelog(commit_sha):
32
associated_issues_prs = get_associated_issues_prs(commit_sha)
33
34
with open("changelog.md", "a") as changelog_file:
35
changelog_file.write("\n\n")
36
changelog_file.write(f"## {datetime.datetime.now().strftime('%Y-%m-%d')}\n\n")
37
changelog_file.write("### Changes\n")
38
changelog_file.write(f"- [Commit {commit_sha[:7]}](https://github.com/veeralakrishna/DataCamp-Project-Solutions-Python/commit/{commit_sha})\n")
39
changelog_file.write("### Associated Issues/PRs\n")
40
changelog_file.write('\n'.join([f"- {item}" for item in associated_issues_prs]))
41
42
if __name__ == "__main__":
43
update_changelog(commit_sha)
44
print("Success!")
45
46