21
21
import requests
22
22
import json
23
23
import shutil
24
- import re
25
24
26
25
from absl import logging
27
26
from requests .adapters import HTTPAdapter
36
35
REPO = 'firebase-cpp-sdk'
37
36
38
37
BASE_URL = 'https://api.github.com'
39
- GITHUB_API_URL = '%s/repos/%s/%s' % (BASE_URL , OWNER , REPO )
38
+ FIREBASE_URL = '%s/repos/%s/%s' % (BASE_URL , OWNER , REPO )
40
39
logging .set_verbosity (logging .INFO )
41
40
42
-
43
- def set_repo_url (repo ):
44
- match = re .match (r'https://github\.com/([^/]+)/([^/.]+)' , repo )
45
- if not match :
46
- logging .info ('Error, only pattern https://github.com/\{repo_owner\}/\{repo_name\} are allowed.' )
47
- return False
48
-
49
- (repo_owner , repo_name ) = match .groups ()
50
- global OWNER , REPO , GITHUB_API_URL
51
- OWNER = repo_owner
52
- REPO = repo_name
53
- GITHUB_API_URL = '%s/repos/%s/%s' % (BASE_URL , OWNER , REPO )
54
- return True
55
-
56
-
57
41
def requests_retry_session (retries = RETRIES ,
58
42
backoff_factor = BACKOFF ,
59
43
status_forcelist = RETRY_STATUS ):
@@ -70,7 +54,7 @@ def requests_retry_session(retries=RETRIES,
70
54
71
55
def create_issue (token , title , label , body ):
72
56
"""Create an issue: https://docs.github.com/en/rest/reference/issues#create-an-issue"""
73
- url = f'{ GITHUB_API_URL } /issues'
57
+ url = f'{ FIREBASE_URL } /issues'
74
58
headers = {'Accept' : 'application/vnd.github.v3+json' , 'Authorization' : f'token { token } ' }
75
59
data = {'title' : title , 'labels' : [label ], 'body' : body }
76
60
with requests .post (url , headers = headers , data = json .dumps (data ), timeout = TIMEOUT ) as response :
@@ -80,7 +64,7 @@ def create_issue(token, title, label, body):
80
64
81
65
def get_issue_body (token , issue_number ):
82
66
"""https://docs.github.com/en/rest/reference/issues#get-an-issue-comment"""
83
- url = f'{ GITHUB_API_URL } /issues/{ issue_number } '
67
+ url = f'{ FIREBASE_URL } /issues/{ issue_number } '
84
68
headers = {'Accept' : 'application/vnd.github.v3+json' , 'Authorization' : f'token { token } ' }
85
69
with requests_retry_session ().get (url , headers = headers , timeout = TIMEOUT ) as response :
86
70
logging .info ("get_issue_body: %s response: %s" , url , response )
@@ -89,7 +73,7 @@ def get_issue_body(token, issue_number):
89
73
90
74
def update_issue (token , issue_number , data ):
91
75
"""Update an issue: https://docs.github.com/en/rest/reference/issues#update-an-issue"""
92
- url = f'{ GITHUB_API_URL } /issues/{ issue_number } '
76
+ url = f'{ FIREBASE_URL } /issues/{ issue_number } '
93
77
headers = {'Accept' : 'application/vnd.github.v3+json' , 'Authorization' : f'token { token } ' }
94
78
with requests_retry_session ().patch (url , headers = headers , data = json .dumps (data ), timeout = TIMEOUT ) as response :
95
79
logging .info ("update_issue: %s response: %s" , url , response )
@@ -118,7 +102,7 @@ def search_issues_by_label(label):
118
102
119
103
def list_comments (token , issue_number ):
120
104
"""https://docs.github.com/en/rest/reference/issues#list-issue-comments"""
121
- url = f'{ GITHUB_API_URL } /issues/{ issue_number } /comments'
105
+ url = f'{ FIREBASE_URL } /issues/{ issue_number } /comments'
122
106
headers = {'Accept' : 'application/vnd.github.v3+json' , 'Authorization' : f'token { token } ' }
123
107
with requests_retry_session ().get (url , headers = headers , timeout = TIMEOUT ) as response :
124
108
logging .info ("list_comments: %s response: %s" , url , response )
@@ -127,7 +111,7 @@ def list_comments(token, issue_number):
127
111
128
112
def add_comment (token , issue_number , comment ):
129
113
"""https://docs.github.com/en/rest/reference/issues#create-an-issue-comment"""
130
- url = f'{ GITHUB_API_URL } /issues/{ issue_number } /comments'
114
+ url = f'{ FIREBASE_URL } /issues/{ issue_number } /comments'
131
115
headers = {'Accept' : 'application/vnd.github.v3+json' , 'Authorization' : f'token { token } ' }
132
116
data = {'body' : comment }
133
117
with requests .post (url , headers = headers , data = json .dumps (data ), timeout = TIMEOUT ) as response :
@@ -136,7 +120,7 @@ def add_comment(token, issue_number, comment):
136
120
137
121
def update_comment (token , comment_id , comment ):
138
122
"""https://docs.github.com/en/rest/reference/issues#update-an-issue-comment"""
139
- url = f'{ GITHUB_API_URL } /issues/comments/{ comment_id } '
123
+ url = f'{ FIREBASE_URL } /issues/comments/{ comment_id } '
140
124
headers = {'Accept' : 'application/vnd.github.v3+json' , 'Authorization' : f'token { token } ' }
141
125
data = {'body' : comment }
142
126
with requests_retry_session ().patch (url , headers = headers , data = json .dumps (data ), timeout = TIMEOUT ) as response :
@@ -145,15 +129,15 @@ def update_comment(token, comment_id, comment):
145
129
146
130
def delete_comment (token , comment_id ):
147
131
"""https://docs.github.com/en/rest/reference/issues#delete-an-issue-comment"""
148
- url = f'{ GITHUB_API_URL } /issues/comments/{ comment_id } '
132
+ url = f'{ FIREBASE_URL } /issues/comments/{ comment_id } '
149
133
headers = {'Accept' : 'application/vnd.github.v3+json' , 'Authorization' : f'token { token } ' }
150
134
with requests .delete (url , headers = headers , timeout = TIMEOUT ) as response :
151
135
logging .info ("delete_comment: %s response: %s" , url , response )
152
136
153
137
154
138
def add_label (token , issue_number , label ):
155
139
"""https://docs.github.com/en/rest/reference/issues#add-labels-to-an-issue"""
156
- url = f'{ GITHUB_API_URL } /issues/{ issue_number } /labels'
140
+ url = f'{ FIREBASE_URL } /issues/{ issue_number } /labels'
157
141
headers = {}
158
142
headers = {'Accept' : 'application/vnd.github.v3+json' , 'Authorization' : f'token { token } ' }
159
143
data = [label ]
@@ -163,15 +147,15 @@ def add_label(token, issue_number, label):
163
147
164
148
def delete_label (token , issue_number , label ):
165
149
"""https://docs.github.com/en/rest/reference/issues#delete-a-label"""
166
- url = f'{ GITHUB_API_URL } /issues/{ issue_number } /labels/{ label } '
150
+ url = f'{ FIREBASE_URL } /issues/{ issue_number } /labels/{ label } '
167
151
headers = {'Accept' : 'application/vnd.github.v3+json' , 'Authorization' : f'token { token } ' }
168
152
with requests .delete (url , headers = headers , timeout = TIMEOUT ) as response :
169
153
logging .info ("delete_label: %s response: %s" , url , response )
170
154
171
155
172
156
def list_artifacts (token , run_id ):
173
157
"""https://docs.github.com/en/rest/reference/actions#list-workflow-run-artifacts"""
174
- url = f'{ GITHUB_API_URL } /actions/runs/{ run_id } /artifacts'
158
+ url = f'{ FIREBASE_URL } /actions/runs/{ run_id } /artifacts'
175
159
headers = {'Accept' : 'application/vnd.github.v3+json' , 'Authorization' : f'token { token } ' }
176
160
with requests_retry_session ().get (url , headers = headers , timeout = TIMEOUT ) as response :
177
161
logging .info ("list_artifacts: %s response: %s" , url , response )
@@ -180,7 +164,7 @@ def list_artifacts(token, run_id):
180
164
181
165
def download_artifact (token , artifact_id , output_path ):
182
166
"""https://docs.github.com/en/rest/reference/actions#download-an-artifact"""
183
- url = f'{ GITHUB_API_URL } /actions/artifacts/{ artifact_id } /zip'
167
+ url = f'{ FIREBASE_URL } /actions/artifacts/{ artifact_id } /zip'
184
168
headers = {'Accept' : 'application/vnd.github.v3+json' , 'Authorization' : f'token { token } ' }
185
169
with requests .get (url , headers = headers , stream = True , timeout = TIMEOUT ) as response :
186
170
logging .info ("download_artifact: %s response: %s" , url , response )
@@ -190,18 +174,17 @@ def download_artifact(token, artifact_id, output_path):
190
174
191
175
def dismiss_review (token , pull_number , review_id , message ):
192
176
"""https://docs.github.com/en/rest/reference/pulls#dismiss-a-review-for-a-pull-request"""
193
- url = f'{ GITHUB_API_URL } /pulls/{ pull_number } /reviews/{ review_id } /dismissals'
177
+ url = f'{ FIREBASE_URL } /pulls/{ pull_number } /reviews/{ review_id } /dismissals'
194
178
headers = {'Accept' : 'application/vnd.github.v3+json' , 'Authorization' : f'token { token } ' }
195
179
data = {'message' : message }
196
180
with requests_retry_session ().put (url , headers = headers , data = json .dumps (data ),
197
181
stream = True , timeout = TIMEOUT ) as response :
198
182
logging .info ("dismiss_review: %s response: %s" , url , response )
199
183
return response .json ()
200
184
201
-
202
185
def get_reviews (token , pull_number ):
203
186
"""https://docs.github.com/en/rest/reference/pulls#list-reviews-for-a-pull-request"""
204
- url = f'{ GITHUB_API_URL } /pulls/{ pull_number } /reviews'
187
+ url = f'{ FIREBASE_URL } /pulls/{ pull_number } /reviews'
205
188
headers = {'Accept' : 'application/vnd.github.v3+json' , 'Authorization' : f'token { token } ' }
206
189
page = 1
207
190
per_page = 100
@@ -220,32 +203,19 @@ def get_reviews(token, pull_number):
220
203
return results
221
204
222
205
223
- def create_workflow_dispatch (token , workflow_id , ref , inputs ):
206
+ def workflow_dispatch (token , workflow_id , ref , inputs ):
224
207
"""https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event"""
225
- url = f'{ GITHUB_API_URL } /actions/workflows/{ workflow_id } /dispatches'
208
+ url = f'{ FIREBASE_URL } /actions/workflows/{ workflow_id } /dispatches'
226
209
headers = {'Accept' : 'application/vnd.github.v3+json' , 'Authorization' : f'token { token } ' }
227
210
data = {'ref' : ref , 'inputs' : inputs }
228
211
with requests .post (url , headers = headers , data = json .dumps (data ),
229
212
stream = True , timeout = TIMEOUT ) as response :
230
- logging .info ("create_workflow_dispatch: %s response: %s" , url , response )
231
- # Response Status: 204 No Content
232
- return True if response .status_code == 204 else False
233
-
234
-
235
- def list_workflows (token , workflow_id , branch ):
236
- """https://docs.github.com/en/rest/reference/actions#list-workflow-runs-for-a-repository"""
237
- url = f'{ GITHUB_API_URL } /actions/workflows/{ workflow_id } /runs'
238
- headers = {'Accept' : 'application/vnd.github.v3+json' , 'Authorization' : f'token { token } ' }
239
- data = {'event' : 'workflow_dispatch' , 'branch' : branch }
240
- with requests .get (url , headers = headers , data = json .dumps (data ),
241
- stream = True , timeout = TIMEOUT ) as response :
242
- logging .info ("list_workflows: %s response: %s" , url , response )
243
- return response .json ()
213
+ logging .info ("workflow_dispatch: %s response: %s" , url , response )
244
214
245
215
246
216
def create_pull_request (token , head , base , title , body , maintainer_can_modify ):
247
217
"""https://docs.github.com/en/rest/reference/pulls#create-a-pull-request"""
248
- url = f'{ GITHUB_API_URL } /pulls'
218
+ url = f'{ FIREBASE_URL } /pulls'
249
219
headers = {'Accept' : 'application/vnd.github.v3+json' , 'Authorization' : f'token { token } ' }
250
220
data = {'head' : head , 'base' : base , 'title' : title , 'body' : body ,
251
221
'maintainer_can_modify' : maintainer_can_modify }
@@ -254,10 +224,9 @@ def create_pull_request(token, head, base, title, body, maintainer_can_modify):
254
224
logging .info ("create_pull_request: %s response: %s" , head , response )
255
225
return True if response .status_code == 201 else False
256
226
257
-
258
227
def list_pull_requests (token , state , head , base ):
259
228
"""https://docs.github.com/en/rest/reference/pulls#list-pull-requests"""
260
- url = f'{ GITHUB_API_URL } /pulls'
229
+ url = f'{ FIREBASE_URL } /pulls'
261
230
headers = {'Accept' : 'application/vnd.github.v3+json' , 'Authorization' : f'token { token } ' }
262
231
page = 1
263
232
per_page = 100
0 commit comments