1
+ """Collect the PRs between two specified tags or commits and
2
+ output the commit titles, PR numbers, and labels in a json file.
3
+ Usage: python tools/release_notes/retrieve_prs.py tags/v0.10.0 \
4
+ 18685a517ae68353b05b9a0ede5343df31525c76 --file data.json
5
+ """
6
+ import argparse
1
7
import json
2
8
import re
3
- import sys
4
- import argparse
5
9
import subprocess
6
10
from collections import namedtuple
7
11
from os .path import expanduser
8
12
9
13
import requests
10
14
15
+
11
16
Features = namedtuple (
12
17
"Features" ,
13
18
[
19
24
20
25
21
26
def _run_cmd (cmd ):
22
- try :
23
- return subprocess .check_output (cmd ).strip ()
24
- except Exception :
25
- return None
27
+ return subprocess .check_output (cmd ).decode ('utf-8' ).strip ()
26
28
27
29
28
30
def commit_title (commit_hash ):
@@ -57,11 +59,9 @@ def get_ghstack_token():
57
59
58
60
59
61
def run_query (query ):
60
- request = requests .post ("https://github.com/api/graphql" , json = {"query" : query }, headers = headers )
61
- if request .status_code == 200 :
62
- return request .json ()
63
- else :
64
- raise Exception ("Query failed to run by returning code of {}. {}" .format (request .status_code , query ))
62
+ response = requests .post ("https://github.com/api/graphql" , json = {"query" : query }, headers = headers )
63
+ response .raise_for_status ()
64
+ return response .json ()
65
65
66
66
67
67
def gh_labels (pr_number ):
@@ -108,8 +108,11 @@ def get_commits_between(base_version, new_version):
108
108
return hashes , titles
109
109
110
110
111
- def _parse_args (args ):
112
- parser = argparse .ArgumentParser ()
111
+ def _parse_args (args = None ):
112
+ parser = argparse .ArgumentParser (
113
+ description = __doc__ ,
114
+ formatter_class = argparse .RawTextHelpFormatter ,
115
+ )
113
116
parser .add_argument ("base_version" , type = str , help = "starting tag or commit (exclusive)" )
114
117
parser .add_argument ("new_version" , type = str , help = "final tag or commit (inclusive)" )
115
118
parser .add_argument ("--file" , type = str , default = "data.json" , help = "output json file" )
@@ -131,6 +134,4 @@ def _main(args):
131
134
132
135
133
136
if __name__ == "__main__" :
134
- # Usage: python scripts/release_notes/retrieve_prs.py tags/v0.10.0 \
135
- # 18685a517ae68353b05b9a0ede5343df31525c76 --file data.json
136
- _main (_parse_args (sys .argv [1 :]))
137
+ _main (_parse_args ())
0 commit comments