chromium: get-commit-message.py: Support specifying a version

This makes the usage from update.py more robust.
It also adds a workaround for [0] which currently lacks a title.

[0]: https://chromereleases.googleblog.com/2021/08/the-stable-channel-has-been-updated-to.html
This commit is contained in:
Michael Weiss 2021-08-03 13:20:15 +02:00
parent 9a626cda34
commit 9bc2d82b55
No known key found for this signature in database
GPG Key ID: 5BE487C4D4771D83
2 changed files with 22 additions and 13 deletions

View File

@ -2,8 +2,10 @@
#!nix-shell -i python3 -p python3Packages.feedparser python3Packages.requests
# This script prints the Git commit message for stable channel updates.
# Usage: ./get-commit-message.py [version]
import re
import sys
import textwrap
from collections import OrderedDict
@ -13,19 +15,29 @@ import requests
feed = feedparser.parse('https://chromereleases.googleblog.com/feeds/posts/default')
html_tags = re.compile(r'<[^>]+>')
target_version = sys.argv[1] if len(sys.argv) == 2 else None
for entry in feed.entries:
if entry.title != 'Stable Channel Update for Desktop':
continue
url = requests.get(entry.link).url.split('?')[0]
if entry.title != 'Stable Channel Update for Desktop':
if target_version and entry.title == '':
# Workaround for a special case (Chrome Releases bug?):
if not 'the-stable-channel-has-been-updated-to' in url:
continue
else:
continue
content = entry.content[0].value
content = html_tags.sub('', content) # Remove any HTML tags
if re.search(r'Linux', content) is None:
continue
#print(url) # For debugging purposes
version = re.search(r'\d+(\.\d+){3}', content).group(0)
print('chromium: TODO -> ' + version)
print('\n' + url)
if target_version:
if version != target_version:
continue
else:
print('chromium: TODO -> ' + version + '\n')
print(url)
if fixes := re.search(r'This update includes .+ security fixes\.', content).group(0):
zero_days = re.search(r'Google is aware( of reports)? that .+ in the wild\.', content)
if zero_days:
@ -35,4 +47,7 @@ for entry in feed.entries:
cve_list = list(OrderedDict.fromkeys(cve_list)) # Remove duplicates but preserve the order
cve_string = ' '.join(cve_list)
print("\nCVEs:\n" + '\n'.join(textwrap.wrap(cve_string, width=72)))
break # We only care about the most recent stable channel update
sys.exit(0) # We only care about the most recent stable channel update
print("Error: No match.")
sys.exit(1)

View File

@ -222,14 +222,8 @@ if len(sys.argv) == 2 and sys.argv[1] == '--commit':
attr_name = channel_name_to_attr_name(channel_name)
commit_message = f'{attr_name}: {version_old} -> {version_new}'
if channel_name == 'stable':
body = subprocess.check_output([COMMIT_MESSAGE_SCRIPT]).decode('utf-8')
prefix = f'chromium: TODO -> {version_new}'
if not body.startswith(prefix):
print("Error: Couldn't fetch the the release notes for the following update:")
print(commit_message)
sys.exit(1)
body = body.removeprefix(prefix)
commit_message += body
body = subprocess.check_output([COMMIT_MESSAGE_SCRIPT, version_new]).decode('utf-8')
commit_message += '\n\n' + body
subprocess.run(['git', 'add', JSON_PATH], check=True)
subprocess.run(['git', 'commit', '--file=-'], input=commit_message.encode(), check=True)
else: