]> git.ipfire.org Git - thirdparty/pdns.git/blob - build-scripts/changelog-from-pr.py
Merge pull request #6783 from rgacogne/changelog-from-pr-auth
[thirdparty/pdns.git] / build-scripts / changelog-from-pr.py
1 #!/usr/bin/env python3
2
3 import requests
4 import sys
5 import argparse
6 import re
7 import getpass
8
9 argp = argparse.ArgumentParser()
10 argp.add_argument('--oneline', action='store_true',
11 help='Make one-lined changelog entries (for 4.0 and older)')
12 argp.add_argument('--username',
13 help='Use the specified username for Basic Authentication to the GitHub API, allowing an higher rate limit')
14 argp.add_argument('pullrequest', metavar='PULL_REQUEST', nargs='+',
15 help='Make changelogs for these Pull Request #\'s')
16 arguments = argp.parse_args()
17
18 ticket_regex = re.compile(r'(?:[Cc]loses|[Ff]ixes)? #(\d+)')
19
20 out = ''
21 httpAuth = None
22 if arguments.username:
23 password = getpass.getpass("GitHub password for '" + arguments.username + "': ")
24 httpAuth = requests.auth.HTTPBasicAuth(arguments.username, password)
25
26 for pr in arguments.pullrequest:
27 if pr[0] == '#':
28 pr = pr[1:]
29 try:
30 res = requests.get('https://api.github.com/repos/PowerDNS/pdns/pulls/'
31 '{}'.format(pr), auth=httpAuth)
32 pr_info = res.json()
33 except (requests.exceptions.HTTPError, ValueError) as e:
34 print(e)
35 sys.exit(1)
36
37 if arguments.oneline:
38 out += '- `#{pr} <{url}>`__: {title}'.format(
39 pr=pr, url=pr_info['html_url'], title=pr_info['title']
40 )
41 else:
42 out += ' .. change::\n' + \
43 ' :tags: XXXXXX\n' + \
44 ' :pullreq: {}\n'.format(pr)
45 tickets = re.findall(ticket_regex, pr_info['body'])
46 if len(tickets):
47 out += ' :tickets: {}\n'.format(', '.join(tickets))
48 out += '\n {}'.format(pr_info['title'].capitalize())
49
50 if pr_info['user']['login'].lower() not in ['ahupowerdns', 'habbie',
51 'pieterlexis', 'rgacogne',
52 'aerique', 'chbruyand']:
53 try:
54 user_info = requests.get(pr_info['user']['url'], auth=httpAuth).json()
55 except (requests.exceptions.HTTPError, ValueError) as e:
56 print(e)
57 sys.exit(1)
58 out += ' ({})'.format(user_info['name'])
59 out += '\n'
60
61 if not arguments.oneline:
62 out += '\n'
63
64 print(out)