]>
git.ipfire.org Git - thirdparty/pdns.git/blob - build-scripts/changelog-from-pr.py
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 a higher rate limit')
14 argp
.add_argument('--access_token',
15 help='Use API access token instead of username & password combination')
16 argp
.add_argument('pullrequest', metavar
='PULL_REQUEST', nargs
='+',
17 help='Make changelogs for these Pull Request #\'s')
18 arguments
= argp
.parse_args()
20 ticket_regex
= re
.compile(r
'(?:[Cc]loses|[Ff]ixes)? #(\d+)')
24 if arguments
.username
:
25 password
= getpass
.getpass("GitHub password for '" + arguments
.username
+ "': ")
26 httpAuth
= requests
.auth
.HTTPBasicAuth(arguments
.username
, password
)
28 # https://github.com/settings/tokens
29 # A token with `repo` and `user` access will definitely work.
30 access_token
= arguments
.access_token
32 for pr
in arguments
.pullrequest
:
37 res
= requests
.get('https://api.github.com/repos/PowerDNS/pdns/pulls/'
39 headers
={'Authorization': 'token ' + access_token
})
41 res
= requests
.get('https://api.github.com/repos/PowerDNS/pdns/pulls/'
42 '{}'.format(pr
), auth
=httpAuth
)
44 except (requests
.exceptions
.HTTPError
, ValueError) as e
:
49 out
+= '- `#{pr} <{url}>`__: {title}'.format(
50 pr
=pr
, url
=pr_info
['html_url'], title
=pr_info
['title']
53 out
+= ' .. change::\n' + \
54 ' :tags: XXXXXX\n' + \
55 ' :pullreq: {}\n'.format(pr
)
56 body
= pr_info
.get('body', None)
57 if pr_info
.get('message', None) and not body
:
58 # A bit blunt but better than we had.
59 print('{}'.format(pr_info
['message']))
62 tickets
= re
.findall(ticket_regex
, body
)
64 out
+= ' :tickets: {}\n'.format(', '.join(tickets
))
65 out
+= '\n {}'.format(pr_info
['title'][0].capitalize() + pr_info
['title'][1:])
67 if pr_info
['user']['login'].lower() not in ['ahupowerdns', 'habbie',
68 'pieterlexis', 'rgacogne',
69 'aerique', 'chbruyand',
70 'omoerbeek', 'fredmorcos']:
73 user_info
= requests
.get(pr_info
['user']['url'],
74 headers
={'Authorization': 'token ' + access_token
}).json()
76 user_info
= requests
.get(pr_info
['user']['url'], auth
=httpAuth
).json()
77 except (requests
.exceptions
.HTTPError
, ValueError) as e
:
80 if 'name' in user_info
:
81 out
+= ' ({})'.format(user_info
['name'])
83 out
+= ' (@{})'.format(user_info
['login'])
86 if not arguments
.oneline
: