Show More
@@ -7,6 +7,8 b' except NameError:' | |||
|
7 | 7 | pass |
|
8 | 8 | |
|
9 | 9 | import os |
|
10 | import re | |
|
11 | import sys | |
|
10 | 12 | |
|
11 | 13 | import requests |
|
12 | 14 | import getpass |
@@ -86,21 +88,56 b" def post_gist(content, description='', filename='file', auth=False):" | |||
|
86 | 88 | response_data = json.loads(response.text) |
|
87 | 89 | return response_data['html_url'] |
|
88 | 90 | |
|
89 | def get_pull_request(project, num): | |
|
91 | def get_pull_request(project, num, auth=False): | |
|
90 | 92 | """get pull request info by number |
|
91 | 93 | """ |
|
92 | 94 | url = "https://api.github.com/repos/{project}/pulls/{num}".format(project=project, num=num) |
|
93 | response = requests.get(url) | |
|
95 | if auth: | |
|
96 | header = make_auth_header() | |
|
97 | else: | |
|
98 | header = None | |
|
99 | response = requests.get(url, headers=header) | |
|
94 | 100 | response.raise_for_status() |
|
95 | 101 | return json.loads(response.text, object_hook=Obj) |
|
96 | 102 | |
|
97 | def get_pulls_list(project): | |
|
103 | element_pat = re.compile(r'<(.+?)>') | |
|
104 | rel_pat = re.compile(r'rel=[\'"](\w+)[\'"]') | |
|
105 | ||
|
106 | def get_paged_request(url, headers=None): | |
|
107 | """get a full list, handling APIv3's paging""" | |
|
108 | results = [] | |
|
109 | while True: | |
|
110 | print("fetching %s" % url, file=sys.stderr) | |
|
111 | response = requests.get(url, headers=headers) | |
|
112 | response.raise_for_status() | |
|
113 | results.extend(response.json()) | |
|
114 | if 'next' in response.links: | |
|
115 | url = response.links['next']['url'] | |
|
116 | else: | |
|
117 | break | |
|
118 | return results | |
|
119 | ||
|
120 | def get_pulls_list(project, state="closed", auth=False): | |
|
98 | 121 | """get pull request list |
|
99 | 122 | """ |
|
100 | url = "https://api.github.com/repos/{project}/pulls".format(project=project) | |
|
101 | response = requests.get(url) | |
|
102 | response.raise_for_status() | |
|
103 | return json.loads(response.text) | |
|
123 | url = "https://api.github.com/repos/{project}/pulls?state={state}&per_page=100".format(project=project, state=state) | |
|
124 | if auth: | |
|
125 | headers = make_auth_header() | |
|
126 | else: | |
|
127 | headers = None | |
|
128 | pages = get_paged_request(url, headers=headers) | |
|
129 | return pages | |
|
130 | ||
|
131 | def get_issues_list(project, state="closed", auth=False): | |
|
132 | """get pull request list | |
|
133 | """ | |
|
134 | url = "https://api.github.com/repos/{project}/pulls?state={state}&per_page=100".format(project=project, state=state) | |
|
135 | if auth: | |
|
136 | headers = make_auth_header() | |
|
137 | else: | |
|
138 | headers = None | |
|
139 | pages = get_paged_request(url, headers=headers) | |
|
140 | return pages | |
|
104 | 141 | |
|
105 | 142 | # encode_multipart_formdata is from urllib3.filepost |
|
106 | 143 | # The only change is to iter_fields, to enforce S3's required key ordering |
General Comments 0
You need to be logged in to leave comments.
Login now