|
| 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(ACTION_TOKEN) |
| 11 | +repo = g.get_repo("veeralakrishna/DataCamp-Project-Solutions-Python") |
| 12 | + |
| 13 | +def get_associated_issues_prs(commit_sha): |
| 14 | + commit = repo.get_commit(commit_sha) |
| 15 | + commit_date = parse(commit.commit.author.date) |
| 16 | + |
| 17 | + issues = repo.get_issues(state="closed", since=commit_date) |
| 18 | + prs = repo.get_pulls(state="closed", sort="created", direction="desc", base=commit_sha) |
| 19 | + |
| 20 | + associated_issues_prs = [] |
| 21 | + |
| 22 | + for issue in issues: |
| 23 | + associated_issues_prs.append(f"Issue {issue.number}: {issue.title}") |
| 24 | + |
| 25 | + for pr in prs: |
| 26 | + associated_issues_prs.append(f"PR {pr.number}: {pr.title}") |
| 27 | + |
| 28 | + return associated_issues_prs |
| 29 | + |
| 30 | +def update_changelog(commit_sha): |
| 31 | + associated_issues_prs = get_associated_issues_prs(commit_sha) |
| 32 | + |
| 33 | + with open("changelog.md", "a") as changelog_file: |
| 34 | + changelog_file.write("\n\n") |
| 35 | + changelog_file.write(f"## {datetime.datetime.now().strftime('%Y-%m-%d')}\n\n") |
| 36 | + changelog_file.write("### Changes\n") |
| 37 | + changelog_file.write(f"- [Commit {commit_sha[:7]}](https://github.com/veeralakrishna/DataCamp-Project-Solutions-Python/commit/{commit_sha})\n") |
| 38 | + changelog_file.write("### Associated Issues/PRs\n") |
| 39 | + changelog_file.write('\n'.join([f"- {item}" for item in associated_issues_prs])) |
| 40 | + |
| 41 | +if __name__ == "__main__": |
| 42 | + update_changelog(commit_sha) |
0 commit comments