1
+ """
2
+ Usage: python scripts/release_notes/retrieve_prs.py tags/v0.10.0 \
3
+ 18685a517ae68353b05b9a0ede5343df31525c76 --file data.json
4
+ """
5
+ import argparse
1
6
import json
2
- import locale
3
- import os
4
7
import re
5
- import sys
6
- import argparse
7
8
import subprocess
8
9
from collections import namedtuple
9
10
from os .path import expanduser
11
+ from pathlib import Path
10
12
11
13
import requests
12
14
15
+ ROOT_DIR = Path (__file__ ).parent .resolve ()
16
+
13
17
Features = namedtuple (
14
18
"Features" ,
15
19
[
@@ -59,11 +63,12 @@ def get_ghstack_token():
59
63
60
64
61
65
def run_query (query ):
62
- request = requests .post ("https://api.github.com/graphql" , json = {"query" : query }, headers = headers )
63
- if request .status_code == 200 :
64
- return request .json ()
65
- else :
66
- raise Exception ("Query failed to run by returning code of {}. {}" .format (request .status_code , query ))
66
+ response = requests .post ("https://api.github.com/graphql" , json = {"query" : query }, headers = headers )
67
+ try :
68
+ response .raise_for_status ()
69
+ return response .json ()
70
+ except requests .exceptions .HTTPError as e :
71
+ print (e )
67
72
68
73
69
74
def gh_labels (pr_number ):
@@ -111,7 +116,10 @@ def get_commits_between(base_version, new_version):
111
116
112
117
113
118
def _parse_args (args ):
114
- parser = argparse .ArgumentParser ()
119
+ parser = argparse .ArgumentParser (
120
+ description = __doc__ ,
121
+ formatter_class = argparse .RawTextHelpFormatter ,
122
+ )
115
123
parser .add_argument ("base_version" , type = str , help = "starting tag or commit (exclusive)" )
116
124
parser .add_argument ("new_version" , type = str , help = "final tag or commit (inclusive)" )
117
125
parser .add_argument ("--file" , type = str , default = "data.json" , help = "output json file" )
@@ -127,12 +135,10 @@ def _main(args):
127
135
if idx % 10 == 0 :
128
136
print (f"{ idx } / { len (hashes )} " )
129
137
130
- data = {commit : features ._asdict () for commit , features in data .items ()}
138
+ data = {commit : features ._asdict () for commit , features in data .items ()}
131
139
with open (args .file , "w" ) as f :
132
140
json .dump (data , f )
133
141
134
142
135
143
if __name__ == "__main__" :
136
- # Usage: python scripts/release_notes/retrieve_prs.py tags/v0.10.0 \
137
- # 18685a517ae68353b05b9a0ede5343df31525c76 --file data.json
138
- _main (_parse_args (sys .argv [1 :]))
144
+ _main (_parse_args ())
0 commit comments