Skip to content

Commit 9c76581

Browse files
authored
Use correct commit hashes when uploading metric reports. (#1517)
1 parent 7ec62f2 commit 9c76581

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

ci/fireci/fireci/uploader.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import logging
1717
import os
1818
import requests
19+
import subprocess
1920

2021
_logger = logging.getLogger('fireci.uploader')
2122

@@ -41,14 +42,20 @@ def _construct_request_endpoint():
4142
repo_owner = os.getenv('REPO_OWNER')
4243
repo_name = os.getenv('REPO_NAME')
4344
branch = os.getenv('PULL_BASE_REF')
44-
base_commit = os.getenv('PULL_BASE_SHA')
45-
head_commit = os.getenv('PULL_PULL_SHA')
4645
pull_request = os.getenv('PULL_NUMBER')
4746

48-
commit = head_commit if head_commit else base_commit
47+
commit = _get_commit_hash('HEAD@{0}')
4948

50-
endpoint = f'/repos/{repo_owner}/{repo_name}/commits/{commit}/reports?branch={branch}'
49+
endpoint = f'/repos/{repo_owner}/{repo_name}/commits/{commit}/reports'
5150
if pull_request:
52-
endpoint += f'&pull_request={pull_request}&base_commit={base_commit}'
51+
base_commit = _get_commit_hash('HEAD@{1}')
52+
endpoint += f'?pull_request={pull_request}&base_commit={base_commit}'
53+
else:
54+
endpoint += f'?branch={branch}'
5355

5456
return endpoint
57+
58+
59+
def _get_commit_hash(revision):
60+
result = subprocess.run(['git', 'rev-parse', revision], capture_output=True, check=True)
61+
return result.stdout.decode('utf-8').strip()

0 commit comments

Comments
 (0)