From 8121ebf240a34d08b1db286637b0d97055dda3cb Mon Sep 17 00:00:00 2001 From: Yifan Yang Date: Wed, 29 Apr 2020 17:05:01 -0700 Subject: [PATCH] Use correct commit hashes when uploading metric reports. --- ci/fireci/fireci/uploader.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ci/fireci/fireci/uploader.py b/ci/fireci/fireci/uploader.py index a4d0a7a7f39..d2acb41879d 100644 --- a/ci/fireci/fireci/uploader.py +++ b/ci/fireci/fireci/uploader.py @@ -16,6 +16,7 @@ import logging import os import requests +import subprocess _logger = logging.getLogger('fireci.uploader') @@ -41,14 +42,20 @@ def _construct_request_endpoint(): repo_owner = os.getenv('REPO_OWNER') repo_name = os.getenv('REPO_NAME') branch = os.getenv('PULL_BASE_REF') - base_commit = os.getenv('PULL_BASE_SHA') - head_commit = os.getenv('PULL_PULL_SHA') pull_request = os.getenv('PULL_NUMBER') - commit = head_commit if head_commit else base_commit + commit = _get_commit_hash('HEAD@{0}') - endpoint = f'/repos/{repo_owner}/{repo_name}/commits/{commit}/reports?branch={branch}' + endpoint = f'/repos/{repo_owner}/{repo_name}/commits/{commit}/reports' if pull_request: - endpoint += f'&pull_request={pull_request}&base_commit={base_commit}' + base_commit = _get_commit_hash('HEAD@{1}') + endpoint += f'?pull_request={pull_request}&base_commit={base_commit}' + else: + endpoint += f'?branch={branch}' return endpoint + + +def _get_commit_hash(revision): + result = subprocess.run(['git', 'rev-parse', revision], capture_output=True, check=True) + return result.stdout.decode('utf-8').strip()