From 3463e463d0569929b2dbc5cdfb860c25d883712c Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Tue, 3 Oct 2023 15:14:10 +0200 Subject: [PATCH 1/3] gitlab_release_notes/generate.py: Add --quiet cmdline option that hides output if no merge requests occurred since the last release (or given date via --since). --- gitlab_release_notes/generate.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/gitlab_release_notes/generate.py b/gitlab_release_notes/generate.py index 3fb6124..4f50058 100644 --- a/gitlab_release_notes/generate.py +++ b/gitlab_release_notes/generate.py @@ -4,7 +4,7 @@ import sys from .version import __version__ -def generate_release_notes(project_id, endstr = '
', since=None, **config): +def generate_release_notes(project_id, endstr = '
', since=None, quiet=False, **config): """ Generate the release notes of a gitlab project from the last release @@ -36,15 +36,17 @@ def generate_release_notes(project_id, endstr = '
', since=None, **config): if not project.mergerequests.list(get_all=False,state='merged'): raise ValueError(f"There is no merged merge request for project {project_id} {project.name}") + log = "" + if since: - log = f"Changelog of {project.name} since {since}:{endstr}" + log_pending = f"Changelog of {project.name} since {since}:{endstr}" last_date = since elif not project.releases.list(get_all=False): - log = f"Changelog of {project.name}:{endstr}" + log_pending = f"Changelog of {project.name}:{endstr}" last_date = '0000-01-01T00:00:00Z' else: last_release = project.releases.list(get_all=False)[0] - log = f"Changelog since release {last_release.name} of {project.name}:{endstr}" + log_pending = f"Changelog since release {last_release.name} of {project.name}:{endstr}" last_date = last_release.released_at page = 1 @@ -54,9 +56,12 @@ def generate_release_notes(project_id, endstr = '
', since=None, **config): updated_after=last_date, page=page) if not list_mrs: - log += f"There is no merged merge request after {last_date}" + if not quiet: + log += log_pending + log += f"There is no merged merge request after {last_date}" return log + log += log_pending while list_mrs: for mr in list_mrs: line = f" * {mr.title} (@{mr.author['username']}){endstr}" @@ -87,6 +92,7 @@ def main(): parser.add_argument('--version', action='version', version=__version__) parser.add_argument('--html', action='store_true') parser.add_argument('--since', type=datetime.date.fromisoformat, required=False, default=None) + parser.add_argument('--quiet', action='store_true') args = parser.parse_args() @@ -98,6 +104,7 @@ def main(): url=args.url, endstr=endstr, since=args.since, + quiet=args.quiet, private_token=args.private_token, ) print(notes) From 94feef8f86d0b49186673744ba1f5b0e40122f5a Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Tue, 3 Oct 2023 15:15:00 +0200 Subject: [PATCH 2/3] gitlab_release_notes/generate.py: Only print-out release notes if there were any I.e. suppress printing out an empty line on repos with no changes when the --quiet cmdline option was given. --- gitlab_release_notes/generate.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gitlab_release_notes/generate.py b/gitlab_release_notes/generate.py index 4f50058..9d0bea5 100644 --- a/gitlab_release_notes/generate.py +++ b/gitlab_release_notes/generate.py @@ -107,7 +107,8 @@ def main(): quiet=args.quiet, private_token=args.private_token, ) - print(notes) + if notes: + print(notes) if __name__ == "__main__": main() From 47008b731a6ce48cc7632eab7e564c7ded952ace Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Tue, 3 Oct 2023 15:16:14 +0200 Subject: [PATCH 3/3] gitlab_release_notes/generate.py: Use {endstr} in message notifying about no MRs since last (release) date. --- gitlab_release_notes/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab_release_notes/generate.py b/gitlab_release_notes/generate.py index 9d0bea5..a66c81e 100644 --- a/gitlab_release_notes/generate.py +++ b/gitlab_release_notes/generate.py @@ -58,7 +58,7 @@ def generate_release_notes(project_id, endstr = '
', since=None, quiet=Fals if not list_mrs: if not quiet: log += log_pending - log += f"There is no merged merge request after {last_date}" + log += f"There is no merged merge request after {last_date}{endstr}" return log log += log_pending