Skip to content

Commit

Permalink
Update changelog.py
Browse files Browse the repository at this point in the history
  • Loading branch information
fkiraly committed Aug 9, 2024
1 parent 59f614e commit 5472121
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions build_tools/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import os
from collections import defaultdict
from typing import Dict, List

HEADERS = {
"Accept": "application/vnd.github.v3+json",
Expand All @@ -16,8 +15,23 @@
GITHUB_REPOS = "https://api.github.com/repos"


def fetch_merged_pull_requests(page: int = 1) -> List[Dict]: # noqa
"Fetch a page of pull requests"
def fetch_merged_pull_requests(page: int = 1) -> list[dict]:
"""Fetch a page of merged pull requests.
Parameters
----------
page : int, optional
Page number to fetch, by default 1.
Returns all merged pull request from the ``page``-th page of closed PRs,
where pages are in descending order of last update.
Returns
-------
list
List of merged pull requests from the ``page``-th page of closed PRs.
Elements of list are dictionaries with PR details, as obtained
from the GitHub API via ``httpx.get``, from the ``pulls`` endpoint.
"""
import httpx

params = {
Expand All @@ -36,7 +50,16 @@ def fetch_merged_pull_requests(page: int = 1) -> List[Dict]: # noqa
return [pr for pr in r.json() if pr["merged_at"]]


def fetch_latest_release(): # noqa
def fetch_latest_release():
"""Fetch the latest release from the GitHub API.
Returns
-------
dict
Dictionary with details of the latest release.
Dictionary is as obtained from the GitHub API via ``httpx.get``,
for ``releases/latest`` endpoint.
"""
import httpx

response = httpx.get(
Expand Down Expand Up @@ -93,7 +116,7 @@ def github_compare_tags(tag_left: str, tag_right: str = "HEAD"): # noqa
raise ValueError(response.text, response.status_code)


def render_contributors(prs: List, fmt: str = "rst"): # noqa
def render_contributors(prs: list, fmt: str = "rst"): # noqa
"Find unique authors and print a list in given format"
authors = sorted({pr["user"]["login"] for pr in prs}, key=lambda x: x.lower())

Expand All @@ -107,7 +130,7 @@ def render_contributors(prs: List, fmt: str = "rst"): # noqa
print(",\n".join(f":user:`{user}`" for user in authors)) # noqa


def assign_prs(prs, categs: List[Dict[str, List[str]]]): # noqa
def assign_prs(prs, categs: list[dict[str, list[str]]]): # noqa
"Assign PR to categories based on labels"
assigned = defaultdict(list)

Expand All @@ -121,7 +144,7 @@ def assign_prs(prs, categs: List[Dict[str, List[str]]]): # noqa
# print(i, pr_labels)

assigned["Other"] = list(
set(range(len(prs))) - {i for _, l in assigned.items() for i in l}
set(range(len(prs))) - {i for _, j in assigned.items() for i in j}
)

return assigned
Expand Down

0 comments on commit 5472121

Please sign in to comment.