from github import Github
import re


class ChangelogGenerator:
    def __init__(self, github_repo):
        # Replace <your_github_token> with your Github Token
        self._github = Github('<your_github_token>')
        self._github_repo = self._github.get_repo(github_repo)

    def generate(self, pr_id):
        pr = self._github_repo.get_pull(pr_id)

        return "{title} ([#{pr_id}]({pr_link}), @{user})".format(
            title=pr.title,
            pr_id=pr_id,
            pr_link=pr.html_url,
            user=pr.user.login
        )


# generated by `git log <oldTag>..HEAD --oneline`
payload = '''
6f1e96c4 Update container image for v1.1.1 (#1328)
47a74b73 add a specific version of tensorflow_datasets (#1305)
e3061132 Remove vendor folder (#1288)
eb362bd8 Fix invalid pointer when tfjob is deleted (#1285)
0c41b273 fix get_logs pod_names type and iteration blocking (#1280)
af5bdd58 Add job namespace to `tf_operator_jobs_*` counters (#1283)
6fd9489e fix custom_api.delete_namespaced_custom_object args (#1281)
c095f7a9 feat: upgrade kubeflow common and volcano version (#1276)
13b17b0e Use remote Kustomize build option in standalone installation instructions (#1266)
faf34868 fix: Remove the dup comment tag (#1274)
9a297876 add podgroups rule in cluster-role.yaml (#1272)
58c9bc4a Fix: the "follow" of TFJobClient.get_logs (#1254)
3d9e7c8a Add task type annotation for pods when EnableGangScheduling is true. (#1268)
8d179f70 Fix: Remove Github CD workflow (#1263)
'''

g = ChangelogGenerator("kubeflow/training-operator")
for pr_match in re.finditer(r"#(\d+)", payload):
    pr_id = int(pr_match.group(1))
    print("* {}".format(g.generate(pr_id)))
