Skip to content

Commit

Permalink
Merge pull request #6 from sunweaver/pr/add-quiet-option
Browse files Browse the repository at this point in the history
gitlab_release_notes/generate.py: Add --quiet cmdline option.
  • Loading branch information
vuillaut authored Oct 6, 2023
2 parents da91cbc + 47008b7 commit 84c1fee
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions gitlab_release_notes/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
from .version import __version__

def generate_release_notes(project_id, endstr = ' <br>', since=None, **config):
def generate_release_notes(project_id, endstr = ' <br>', since=None, quiet=False, **config):
"""
Generate the release notes of a gitlab project from the last release
Expand Down Expand Up @@ -36,15 +36,17 @@ def generate_release_notes(project_id, endstr = ' <br>', 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
Expand All @@ -54,9 +56,12 @@ def generate_release_notes(project_id, endstr = ' <br>', 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}{endstr}"
return log

log += log_pending
while list_mrs:
for mr in list_mrs:
line = f" * {mr.title} (@{mr.author['username']}){endstr}"
Expand Down Expand Up @@ -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()

Expand All @@ -98,9 +104,11 @@ def main():
url=args.url,
endstr=endstr,
since=args.since,
quiet=args.quiet,
private_token=args.private_token,
)
print(notes)
if notes:
print(notes)

if __name__ == "__main__":
main()

0 comments on commit 84c1fee

Please sign in to comment.