in services/lambda-pr-status-labeler/pr_status_bot/PRStatusBot.py [0:0]
def parse_payload(self, payload):
"""
This method parses the payload and process it according to the event status
"""
# CI is run for non-PR commits as well
# for instance, after PR is merged into the master/v1.x branch
# we exit in such a case
# to detect if the status update is for a PR commit or a merged commit
# we rely on Target_URL in the event payload
# e.g. http//jenkins.mxnet-ci.amazon-ml.com/job/mxnet-validation/job/sanity/job/PR-18899/1/display/redirect
target_url = payload['target_url']
if 'PR' not in target_url:
logging.info('Status update doesnt belong to a PR commit')
return 1
# strip PR number from the target URL
# use raw string instead of normal string to make regex check pep8 compliant
pr_number = re.search(r"PR-(\d+)", target_url, re.IGNORECASE).group(1)
logging.info(f'--------- PR : {pr_number} ----------')
pull_request_obj = self._get_pull_request_object(pr_number)
# verify PR is open
# return if PR is closed
if pull_request_obj.state == 'closed':
logging.info('PR is closed. No point in labeling')
return 2
# CI runs for stale commits
# return if its status update of a stale commit
commit_sha = payload['commit']['sha']
if self._is_stale_commit(commit_sha, pull_request_obj):
return
context = payload['context']
state = payload['state']
logging.info(f'PR Context: {context}')
logging.info(f'Context State: {state}')
commit_obj = self._get_commit_object(commit_sha)
combined_status_state = commit_obj.get_combined_status().state
logging.info(f'PR Combined Status State: {combined_status_state}')
full_build_status_state = self._get_full_build_status_from_combined_status(commit_obj, combined_status_state)
logging.info(f'PR Full Build Status State: {full_build_status_state}')
self._label_pr_based_on_status(full_build_status_state, pull_request_obj)