Skip to content

Use correct commit hashes when uploading metric reports. #1517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions ci/fireci/fireci/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
import os
import requests
import subprocess

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

Expand All @@ -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()