From patchwork Wed Feb 1 12:58:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thadeu Lima de Souza Cascardo X-Patchwork-Id: 722511 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3vD38t1ylQz9t2D; Wed, 1 Feb 2017 23:58:38 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1cYuUd-0001x8-Iw; Wed, 01 Feb 2017 12:58:35 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1cYuUX-0001w5-Ih for kernel-team@lists.ubuntu.com; Wed, 01 Feb 2017 12:58:29 +0000 Received: from 1.general.cascardo.us.vpn ([10.172.70.58] helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1cYuUW-0005mf-RY for kernel-team@lists.ubuntu.com; Wed, 01 Feb 2017 12:58:29 +0000 From: Thadeu Lima de Souza Cascardo To: kernel-team@lists.ubuntu.com Subject: [xenial linux-meta-raspi2 2/3] UBUNTU: add git-ubuntu-log for changelog formatting Date: Wed, 1 Feb 2017 10:58:17 -0200 Message-Id: <20170201125818.10801-3-cascardo@canonical.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170201125818.10801-1-cascardo@canonical.com> References: <20170201125818.10801-1-cascardo@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: kernel-team-bounces@lists.ubuntu.com From: Andy Whitcroft BugLink: http://bugs.launchpad.net/bugs/1601954 Signed-off-by: Andy Whitcroft Signed-off-by: Tim Gardner Signed-off-by: Thadeu Lima de Souza Cascardo --- debian/scripts/misc/git-ubuntu-log | 125 +++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100755 debian/scripts/misc/git-ubuntu-log diff --git a/debian/scripts/misc/git-ubuntu-log b/debian/scripts/misc/git-ubuntu-log new file mode 100755 index 0000000..eee983f --- /dev/null +++ b/debian/scripts/misc/git-ubuntu-log @@ -0,0 +1,125 @@ +#!/usr/bin/python3 + +import os +import sys + +import codecs +import urllib.request +import json + +import textwrap + +sys.stdin = codecs.getreader("utf-8")(sys.stdin.detach()) +sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach()) + +entries = [] +def add_entry(entry): + if entry and 'ignore' not in entry: + if 'bugs' not in entry and 'cves' in entry: + for cve in entry['cves']: + if cve not in bugs: + bugs.append(cve) + entries.append(entry) + +# Suck up the git log output and extract the information we need. +bugs = [] +entry = None +subject_wait = False +for line in sys.stdin: + if line.startswith('commit '): + add_entry(entry) + entry = {} + subject_wait = True + + elif line.startswith('Author: '): + bits = line.strip().split(maxsplit=1) + entry['author'] = bits[1] + + elif subject_wait and line.startswith(' '): + subject_wait = False + entry['subject'] = line.strip() + + elif line.startswith(' BugLink: ') and 'launchpad.net' in line: + bits = line.strip().split(maxsplit=1) + bits = bits[1].split('/') + entry.setdefault('bugs', []).append(bits[-1]) + + # Accumulate bug numbers. + if bits[-1] not in bugs: + bugs.append(bits[-1]) + + elif line.startswith(' CVE-'): + entry.setdefault('cves', []).append(line.strip()) + + elif line.startswith(' Ignore:'): + entry['ignore'] = True + +add_entry(entry) + +entries.reverse() + +# Go through the entries and clear out authors for upstream commits. +for entry in entries: + if entry['subject'].startswith('UBUNTU:'): + entry['subject'] = entry['subject'][7:].strip() + else: + del entry['author'] + +# Lump everything without a bug at the bottom. +bugs.append('__packaging__') +bugs.append('__mainline__') + +emit_nl = False +for bug in bugs: + if bug == '__packaging__': + title = 'Miscellaneous Ubuntu changes' + elif bug == '__mainline__': + title = 'Miscellaneous upstream changes' + elif bug.startswith('CVE-'): + title = bug + else: + bug_info = None + + try: + #urllib.request.urlcleanup() + request = urllib.request.Request('https://api.launchpad.net/devel/bugs/' + bug) + request.add_header('Cache-Control', 'max-age=0') + with urllib.request.urlopen(request) as response: + data = response.read() + bug_info = json.loads(data.decode('utf-8')) + + title = bug_info['title'] + if 'description' in bug_info: + for line in bug_info['description'].split('\n'): + if line.startswith('Kernel-Description:'): + title = line.split(' ', 1)[1] + + except urllib.error.HTTPError: + title = 'INVALID or PRIVATE BUG' + + title += ' (LP###' + bug + ')' + + emit_title = True + for entry in entries: + if (bug == '__packaging__' and 'bugs' not in entry and 'cves' not in entry and 'author' in entry) or \ + (bug == '__mainline__' and 'bugs' not in entry and 'cves' not in entry and 'author' not in entry) or \ + ('bugs' in entry and bug in entry['bugs']) or \ + ('cves' in entry and bug in entry['cves']): + if emit_title: + if emit_nl: + print('') + emit_nl = True + + title_lines = textwrap.wrap(title, 76) + print(' * ' + title_lines[0].replace('LP###', 'LP: #')) + for line in title_lines[1:]: + line = line.replace('LP###', 'LP: #') + print(' ' + line) + + emit_title = False + title_lines = textwrap.wrap(entry['subject'], 76) + print(' - ' + title_lines[0]) + for line in title_lines[1:]: + line = line.replace('LP###', 'LP: #') + print(' ' + line) +