From eafb1d527d8fc1f367215429fde9421aac876ef2 Mon Sep 17 00:00:00 2001 From: Lidi Zheng Date: Mon, 17 Dec 2018 18:14:58 -0800 Subject: Reorgnize dependencies and variables --- tools/run_tests/python_utils/check_on_pr.py | 35 +++++++++++++++-------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'tools/run_tests') diff --git a/tools/run_tests/python_utils/check_on_pr.py b/tools/run_tests/python_utils/check_on_pr.py index 78f1dca817..d59f99b252 100644 --- a/tools/run_tests/python_utils/check_on_pr.py +++ b/tools/run_tests/python_utils/check_on_pr.py @@ -25,21 +25,21 @@ _GITHUB_API_PREFIX = 'https://api.github.com' _GITHUB_REPO = 'grpc/grpc' _GITHUB_APP_ID = 22338 _INSTALLATION_ID = 519109 -_GITHUB_APP_KEY = open( - os.path.join(os.environ['KOKORO_KEYSTORE_DIR'], '73836_grpc_checks_private_key'), - 'rb').read() _ACCESS_TOKEN_CACHE = None def _jwt_token(): + github_app_key = open( + os.path.join(os.environ['KOKORO_KEYSTORE_DIR'], + '73836_grpc_checks_private_key'), 'rb').read() return jwt.encode( { 'iat': int(time.time()), 'exp': int(time.time() + 60 * 10), # expire in 10 minutes 'iss': _GITHUB_APP_ID, }, - _GITHUB_APP_KEY, + github_app_key, algorithm='RS256') @@ -90,25 +90,26 @@ def check_on_pr(name, summary, success=True): summary: A str in Markdown to be used as the detail information of the check. success: A bool indicates whether the check is succeed or not. """ + if 'KOKORO_GIT_COMMIT' not in os.environ: + print('Missing KOKORO_GIT_COMMIT env var: not checking') + return + if 'KOKORO_KEYSTORE_DIR' not in os.environ: + print('Missing KOKORO_KEYSTORE_DIR env var: not checking') + return if 'ghprbPullId' not in os.environ: - print('Missing ghprbPullId env var: not commenting') + print('Missing ghprbPullId env var: not checking') return - commit = _latest_commit() + completion_time = str( + datetime.datetime.utcnow().replace(microsecond=0).isoformat()) + 'Z' resp = _call( '/repos/%s/check-runs' % _GITHUB_REPO, method='POST', json={ - 'name': - name, - 'head_sha': - commit['sha'], - 'status': - 'completed', - 'completed_at': - '%sZ' % - datetime.datetime.utcnow().replace(microsecond=0).isoformat(), - 'conclusion': - 'success' if success else 'failure', + 'name': name, + 'head_sha': os.environ['KOKORO_GIT_COMMIT'], + 'status': 'completed', + 'completed_at': completion_time, + 'conclusion': 'success' if success else 'failure', 'output': { 'title': name, 'summary': summary, -- cgit v1.2.3