tools: Fix changelog script to be case insensitive and support auth

This commit is contained in:
Christian Decker 2019-12-11 20:40:00 +01:00
parent d449423983
commit 5ca938015a
1 changed files with 12 additions and 8 deletions

View File

@ -1,13 +1,14 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from collections import namedtuple from collections import namedtuple
import re from datetime import datetime
import sys
import shlex
import subprocess
import requests
from mako.template import Template from mako.template import Template
import argparse import argparse
from datetime import datetime import os
import re
import requests
import shlex
import subprocess
import sys
# What sections do we support in the changelog: # What sections do we support in the changelog:
sections = [ sections = [
@ -49,7 +50,7 @@ def get_log_entries(commitrange):
commit = m.group(1) commit = m.group(1)
m = re.match( m = re.match(
r'^\s+Changelog-({}): (.*)$'.format("|".join(sections)), l) r'^\s+Changelog-({}): (.*)$'.format("|".join(sections)), l, re.IGNORECASE)
if not m: if not m:
continue continue
@ -58,6 +59,9 @@ def get_log_entries(commitrange):
'Accept': 'application/vnd.github.groot-preview+json', 'Accept': 'application/vnd.github.groot-preview+json',
} }
if os.environ.get('GH_TOKEN'):
headers['Authorization'] = 'token ' + os.environ.get('GH_TOKEN')
url = 'https://api.github.com/repos/{repo}/commits/{commit}/pulls'.format(repo=repo, commit=commit) url = 'https://api.github.com/repos/{repo}/commits/{commit}/pulls'.format(repo=repo, commit=commit)
content = requests.get(url, headers=headers).json() content = requests.get(url, headers=headers).json()
if len(content): if len(content):
@ -65,7 +69,7 @@ def get_log_entries(commitrange):
else: else:
pullreq = None pullreq = None
e = Entry(commit, pullreq, m.group(2), m.group(1)) e = Entry(commit, pullreq, m.group(2), m.group(1).lower())
entries.append(e) entries.append(e)
return entries return entries