From 0e2738cbfd177fcb4d0d99f330ea3469e3e052d4 Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Sun, 13 Aug 2023 15:20:44 +0100 Subject: Try to add relevant changelog excerpt to announce message Look for a relevant section of changelog in README, between '----' delimiters, starting with one also containing the version, to add to the generated announce message. --- calm/calm.py | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/calm/calm.py b/calm/calm.py index 59f6263..0ed44ff 100755 --- a/calm/calm.py +++ b/calm/calm.py @@ -53,6 +53,7 @@ # import argparse +import codecs import functools import logging import lzma @@ -63,6 +64,8 @@ import sys import tempfile import time +import xtarfile + from . import common_constants from . import db from . import irk @@ -201,7 +204,7 @@ def process_maintainer_uploads(args, state, all_packages, m, basedir, desc, scru # automatically generate announce email if requested if announce and success and any([scan_result[a].to_relarea for a in scan_result]): - _announce_upload(scan_result, m) + _announce_upload(args, scan_result, m) # remove upload files on success in homedir, always in stagingdir for arch in common_constants.ARCHES + ['noarch', 'src']: @@ -215,7 +218,7 @@ def process_maintainer_uploads(args, state, all_packages, m, basedir, desc, scru return success -def _announce_upload(scan_result, maintainer): +def _announce_upload(args, scan_result, maintainer): srcpkg = None pkglist = set() for arch in common_constants.ARCHES + ['noarch', 'src']: @@ -234,6 +237,38 @@ def _announce_upload(scan_result, maintainer): return logging.debug("source package is %s, version %s, test %s", srcpkg.orig_name, version, test) + # find source tarfile for this particular package version + to = srcpkg.tar(version) + tf = to.repopath.abspath(args.rel_area) + + # look in the source tar file for a README + cl = '' + with xtarfile.open(tf, mode='r') as a: + files = a.getnames() + for readme in ['README', srcpkg.orig_name + '.README']: + fn = srcpkg.orig_name + '-' + version + '.src/' + readme + if fn in files: + logging.debug("extracting %s from archive for changelog" % readme) + + f = codecs.getreader("utf-8")(a.extractfile(fn)) + + # extract relevant part of ChangeLog + # (between one '---- .* ----' and the next '----' line) + found = False + for l in f: + if not found: + if l.startswith('----') and (version in l): + cl = l + found = True + else: + if l.startswith('----'): + break + cl = cl + '\n' + l + + break + + # TODO: maybe other mechanisms for getting package ChangeLog? + # build the email hdr = {} hdr['From'] = maintainer.name + ' via Cygwin package uploader ' @@ -249,7 +284,9 @@ The following packages have been uploaded to the Cygwin distribution: %s %s -''' % ('\n'.join('* ' + p + '-' + version for p in sorted(pkglist)), ldesc) + +%s +''' % ('\n'.join('* ' + p + '-' + version for p in sorted(pkglist)), ldesc, cl) # TODO: add an attachment: sha512 hashes of packages, gpg signed? -- cgit v1.2.3