Skip to content

Commit bd73542

Browse files
cynthiajoanCynthia Jiang
andauthored
rename github.py to firebase_github.py (#776)
Co-authored-by: Cynthia Jiang <cynthiajiang@google.com>
1 parent 56d7682 commit bd73542

File tree

4 files changed

+28
-35
lines changed

4 files changed

+28
-35
lines changed

scripts/gha/create_pull_request.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,12 @@
2525
Creates the pull request, and outputs the new PR number to stdout.
2626
"""
2727

28-
import datetime
29-
import shutil
30-
3128
from absl import app
3229
from absl import flags
33-
from absl import logging
3430

35-
import github
31+
import firebase_github
3632

3733
FLAGS = flags.FLAGS
38-
_DEFAULT_MESSAGE = "Creating pull request."
3934

4035
flags.DEFINE_string(
4136
"token", None,
@@ -60,9 +55,9 @@
6055
def main(argv):
6156
if len(argv) > 1:
6257
raise app.UsageError("Too many command-line arguments.")
63-
if github.create_pull_request(FLAGS.token, FLAGS.head, FLAGS.base, FLAGS.title, FLAGS.body, True):
58+
if firebase_github.create_pull_request(FLAGS.token, FLAGS.head, FLAGS.base, FLAGS.title, FLAGS.body, True):
6459
# Find the most recent pull_request with the given base and head, that's ours.
65-
pull_requests = github.list_pull_requests(FLAGS.token, "open", FLAGS.head, FLAGS.base)
60+
pull_requests = firebase_github.list_pull_requests(FLAGS.token, "open", FLAGS.head, FLAGS.base)
6661
print(pull_requests[0]['number'])
6762
else:
6863
exit(1)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""A utility for GitHub REST API.
15+
"""A utility for GitHub REST API for firebase repos.
1616
1717
This script handles GitHub Issue, Pull Request, Comment, Label and Artifact
1818

scripts/gha/it_workflow.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@
4141

4242
import datetime
4343
import pytz
44-
import shutil
4544

4645
from absl import app
4746
from absl import flags
48-
from absl import logging
4947

50-
import github
48+
import firebase_github
5149
import summarize_test_results as summarize
5250

5351
_REPORT_LABEL = "nightly-testing"
@@ -112,9 +110,9 @@
112110

113111
def test_start(token, issue_number, actor, commit, run_id):
114112
"""In PR, when start testing, add comment and label \"tests: in-progress\""""
115-
github.add_label(token, issue_number, _LABEL_PROGRESS)
113+
firebase_github.add_label(token, issue_number, _LABEL_PROGRESS)
116114
for label in [_LABEL_TRIGGER_FULL, _LABEL_TRIGGER_QUICK, _LABEL_FAILED, _LABEL_SUCCEED]:
117-
github.delete_label(token, issue_number, label)
115+
firebase_github.delete_label(token, issue_number, label)
118116

119117
comment = (_COMMENT_TITLE_PROGESS +
120118
_get_description(actor, commit, run_id) +
@@ -136,7 +134,7 @@ def test_progress(token, issue_number, actor, commit, run_id):
136134
else:
137135
# failures/errors still exist after retry
138136
title = _COMMENT_TITLE_PROGESS_FAIL
139-
github.add_label(token, issue_number, _LABEL_FAILED)
137+
firebase_github.add_label(token, issue_number, _LABEL_FAILED)
140138
comment = (title +
141139
_get_description(actor, commit, run_id) +
142140
log_summary +
@@ -151,7 +149,7 @@ def test_end(token, issue_number, actor, commit, run_id, new_token):
151149
success_or_only_flakiness, log_summary = _get_summary_table(token, run_id)
152150
if success_or_only_flakiness and not log_summary:
153151
# succeeded (without flakiness)
154-
github.add_label(token, issue_number, _LABEL_SUCCEED)
152+
firebase_github.add_label(token, issue_number, _LABEL_SUCCEED)
155153
comment = (_COMMENT_TITLE_SUCCEED +
156154
_get_description(actor, commit, run_id) +
157155
_COMMENT_SUFFIX)
@@ -160,18 +158,18 @@ def test_end(token, issue_number, actor, commit, run_id, new_token):
160158
if success_or_only_flakiness:
161159
# all failures/errors are due to flakiness (succeeded after retry)
162160
title = _COMMENT_TITLE_FLAKY
163-
github.add_label(token, issue_number, _LABEL_SUCCEED)
161+
firebase_github.add_label(token, issue_number, _LABEL_SUCCEED)
164162
else:
165163
# failures/errors still exist after retry
166164
title = _COMMENT_TITLE_FAIL
167-
github.add_label(token, issue_number, _LABEL_FAILED)
165+
firebase_github.add_label(token, issue_number, _LABEL_FAILED)
168166
comment = (title +
169167
_get_description(actor, commit, run_id) +
170168
log_summary +
171169
_COMMENT_SUFFIX)
172170
_update_comment(token, issue_number, comment)
173171

174-
github.delete_label(new_token, issue_number, _LABEL_PROGRESS)
172+
firebase_github.delete_label(new_token, issue_number, _LABEL_PROGRESS)
175173

176174

177175
def test_report(token, actor, commit, run_id):
@@ -194,32 +192,32 @@ def test_report(token, actor, commit, run_id):
194192
comment = title + _get_description(actor, commit, run_id) + log_summary
195193

196194
if title == _COMMENT_TITLE_SUCCEED:
197-
github.close_issue(token, issue_number)
195+
firebase_github.close_issue(token, issue_number)
198196
else:
199-
github.open_issue(token, issue_number)
197+
firebase_github.open_issue(token, issue_number)
200198

201-
github.update_issue_comment(token, issue_number, comment)
199+
firebase_github.update_issue_comment(token, issue_number, comment)
202200

203201

204202
def _get_issue_number(token, title, label):
205-
issues = github.search_issues_by_label(label)
203+
issues = firebase_github.search_issues_by_label(label)
206204
for issue in issues:
207205
if issue["title"] == title:
208206
return issue["number"]
209207

210-
return github.create_issue(token, title, label, _COMMENT_SUFFIX)["number"]
208+
return firebase_github.create_issue(token, title, label, _COMMENT_SUFFIX)["number"]
211209

212210

213211
def _update_comment(token, issue_number, comment):
214212
comment_id = _get_comment_id(token, issue_number, _COMMENT_SUFFIX)
215213
if not comment_id:
216-
github.add_comment(token, issue_number, comment)
214+
firebase_github.add_comment(token, issue_number, comment)
217215
else:
218-
github.update_comment(token, comment_id, comment)
216+
firebase_github.update_comment(token, comment_id, comment)
219217

220218

221219
def _get_comment_id(token, issue_number, comment_identifier):
222-
comments = github.list_comments(token, issue_number)
220+
comments = firebase_github.list_comments(token, issue_number)
223221
for comment in comments:
224222
if comment_identifier in comment['body']:
225223
return comment['id']
@@ -245,7 +243,7 @@ def _get_summary_table(token, run_id):
245243

246244

247245
def _get_artifact_id(token, run_id, name):
248-
artifacts = github.list_artifacts(token, run_id)
246+
artifacts = firebase_github.list_artifacts(token, run_id)
249247
for artifact in artifacts:
250248
if artifact["name"] == name:
251249
return artifact["id"]

scripts/gha/trigger_workflow.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,30 @@
3232
import subprocess
3333
import time
3434
import urllib.parse
35-
import github
35+
import firebase_github
3636

3737
def main():
3838
args = parse_cmdline_args()
3939
if args.branch is None:
4040
args.branch=subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).decode('utf-8').rstrip('\n')
4141
print('autodetected branch: %s' % args.branch)
4242
if args.repo: # else use default firebase/firebase-unity-sdk repo
43-
if not github.set_repo_url(args.repo):
43+
if not firebase_github.set_repo_url(args.repo):
4444
exit(2)
4545
else:
46-
print('set repo url to: %s' % github.GITHUB_API_URL)
46+
print('set repo url to: %s' % firebase_github.GITHUB_API_URL)
4747

4848
json_params = {}
4949
for param in args.param:
5050
json_params[param[0]] = param[1]
5151
if args.verbose or args.dryrun:
52-
print(f'request_url: {github.GITHUB_API_URL}/actions/workflows/{args.workflow}/dispatches')
52+
print(f'request_url: {firebase_github.GITHUB_API_URL}/actions/workflows/{args.workflow}/dispatches')
5353
print(f'request_body: ref: {args.branch}, inputs: {json_params}')
5454
if args.dryrun:
5555
return(0)
5656

5757
print('Sending request to GitHub API...')
58-
if not github.create_workflow_dispatch(args.token, args.workflow, args.branch, json_params):
58+
if not firebase_github.create_workflow_dispatch(args.token, args.workflow, args.branch, json_params):
5959
print('%sFailed to trigger workflow %s' % (
6060
'::error ::' if args.in_github_action else '', args.workflow))
6161
return(-1)
@@ -64,7 +64,7 @@ def main():
6464
time.sleep(args.sleep) # Give a few seconds for the job to become queued.
6565
# Unfortunately, the GitHub REST API doesn't return the new workflow's run ID.
6666
# Query the list of workflows to find the one we just added.
67-
workflows = github.list_workflows(args.token, args.workflow, args.branch)
67+
workflows = firebase_github.list_workflows(args.token, args.workflow, args.branch)
6868
run_id = 0
6969
if "workflow_runs" in workflows:
7070
for workflow in workflows['workflow_runs']:
@@ -80,7 +80,7 @@ def main():
8080
else:
8181
# Couldn't get a run ID, use a generic URL.
8282
workflow_url = '/%s/actions/workflows/%s?query=%s+%s' % (
83-
github.GITHUB_API_URL, args.workflow,
83+
firebase_github.GITHUB_API_URL, args.workflow,
8484
urllib.parse.quote('event:workflow_dispatch', safe=''),
8585
urllib.parse.quote('branch:'+args.branch, safe=''))
8686
print('%sStarted workflow %s: %s' % ('::warning ::' if args.in_github_action else '',

0 commit comments

Comments
 (0)