Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deduplication of entries to Changelog script #1081

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions scripts/generate_changelog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import subprocess
from dataclasses import dataclass
from datetime import datetime
from typing import List
from typing import List, Set

import requests # type: ignore

Expand Down Expand Up @@ -29,7 +29,7 @@ def __init__(
self.current_version = current_version
self.new_version = new_version
self.commits = self.get_commits_after_tag(current_version)
self.prs = [self.get_pr_for_commit(commit) for commit in self.commits]
self.prs = self.get_prs_for_commits(self.commits)

def get_commits_after_tag(self, tag: str) -> List[str]:
result = subprocess.run(
Expand All @@ -52,6 +52,18 @@ def get_pr_for_commit(self, commit_sha: str) -> PullRequest:
url=pr_data["html_url"],
)

def get_prs_for_commits(self, commit_shas: List[str]) -> List[PullRequest]:
prs: List[PullRequest] = []
unique_prs: Set[int] = set()
for commit_sha in commit_shas:
pr = self.get_pr_for_commit(commit_sha)
pr_id = pr.number
if pr_id not in unique_prs:
unique_prs.add(pr_id)
prs.append(pr)
prs.sort(key=lambda pr: pr.number, reverse=True)
return prs

def generate_changelog(self) -> str:
markdown = f"\n## [{self.new_version}] - {datetime.now().strftime('%Y-%m-%d')}\n"
for pr in self.prs:
Expand Down
Loading