From 7ffba52c1b1d80af4e78e77d46b282d5b91cd7ae Mon Sep 17 00:00:00 2001 From: Freddy Date: Fri, 19 May 2023 16:44:47 +0200 Subject: [PATCH] Relese note generator: check `merged_at` field --- misc/infrastructure/prepare_releasenotes.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/misc/infrastructure/prepare_releasenotes.py b/misc/infrastructure/prepare_releasenotes.py index 0532a7e4..71e19903 100644 --- a/misc/infrastructure/prepare_releasenotes.py +++ b/misc/infrastructure/prepare_releasenotes.py @@ -2,6 +2,7 @@ from enum import Enum import logging import requests from typing import NamedTuple, TextIO +from datetime import datetime # TODO: remove after testing import os @@ -92,7 +93,7 @@ def process_description(description: str) -> str: -def process(data: list[dict]) -> dict[MR_TYPE, dict[str, MergeRequestInfo]]: +def process(timestamp: datetime, data: list[dict]) -> dict[MR_TYPE, dict[str, MergeRequestInfo]]: # extract type, size and topic from labels for easier filtering/ordering # extract short description from description # extract author->name @@ -102,6 +103,15 @@ def process(data: list[dict]) -> dict[MR_TYPE, dict[str, MergeRequestInfo]]: continue if item["target_branch"] not in TARGET_BRANCHES: continue + # Workaround for missing merge information + if "merged_at" not in item or not isinstance(item["merged_at"], str): + logging.warning(f"Invalid merge information for {item['iid']} " + f"(project: {item['project_id']})") + continue + # GitLab's rest API doesn't offer a way to filter by "merged_after", so + # check the "merge_at" field + if datetime.fromisoformat(item["merged_at"]) < timestamp: + continue mr_type = MR_TYPE.NO_TYPE_GIVEN size = MR_SIZE.UNKNOWN section = "UNKNOWN SECTION" @@ -162,10 +172,11 @@ def draft_releasenotes(fp: TextIO, data: dict[MR_TYPE, dict[str, MergeRequestInf def main() -> None: - release_timestamp = get_time_of_latest_release() - merge_requests = get_merge_requests(release_timestamp) - processed_data = process(merge_requests) - with open(f"RN_draft_since_{release_timestamp}.md", "w") as f: + release_timestamp_str = get_time_of_latest_release() + release_timestamp = datetime.fromisoformat(release_timestamp_str) + merge_requests = get_merge_requests(release_timestamp_str) + processed_data = process(release_timestamp, merge_requests) + with open(f"RN_draft_since_{release_timestamp_str}.md", "w") as f: draft_releasenotes(f, processed_data) -- 2.39.2