uses CI message version 0.2.X

process CI messages as defined on https://pagure.io/fedora-ci/messages/blob/master/f/schemas
This commit is contained in:
Bruno Goncalves 2019-11-21 10:53:10 +01:00
parent 8baf2bfc88
commit 4120c9c71d
4 changed files with 45 additions and 20 deletions

View file

@ -1,5 +1,5 @@
---
- name: ci.pipeline.allpackages-pr.complete
- name: ci.dist-git-pr.test.complete
hosts: localhost
gather_facts: false

View file

@ -0,0 +1,14 @@
---
- name: ci.dist-git-pr.test.error
hosts: localhost
gather_facts: false
vars_files:
- "/srv/private/vars_loopabull.yml"
tasks:
- debug: var=msg
roles:
- {role: flag_ci_pr, msg: msg, state: "error"}

View file

@ -1,5 +1,5 @@
---
- name: ci.pipeline.allpackages-pr.package.running
- name: ci.dist-git-pr.test.running
hosts: localhost
gather_facts: false

View file

@ -40,56 +40,69 @@ def main(msg, pipeline_state='complete', seed='empty'):
requests_session.mount(
'https://', requests.adapters.HTTPAdapter(max_retries=retry_conf))
if pipeline_state not in ['complete', 'running']:
print("Pipeline state is not 'complete' or 'running'.")
if pipeline_state not in ['complete', 'running', 'error']:
print("Pipeline state is not 'complete' or 'running' or 'error'.")
return
if 'version' not in msg or not msg['version'].startswith('0.2.'):
print('Unsupported msg version, ignoring')
return
commit_hash_text = ''
# test complete messages
if pipeline_state == 'complete':
done_states = {
'SUCCESS': {'api': 'success', 'human': 'passed'},
'UNSTABLE': {'api': 'failure', 'human': 'failed'},
'FAILURE': {'api': 'error', 'human': 'errored'},
'passed': {'api': 'success', 'human': 'passed'},
'error': {'api': 'error', 'human': 'errored'},
'failed': {'api': 'failure', 'human': 'failed'},
'needs_inspection': {'api': 'failure', 'human': 'failed'},
}
state = msg['status']
state = msg['test']['result']
if state not in done_states:
print('Build is not in one of the expected status, ignoring')
return
status = done_states[state]['api']
human_status = done_states[state]['human']
if 'commit_hash' in msg:
commit_hash_text = ' for %s' % msg['commit_hash'][:8]
if 'commit_hash' in msg['artifact']:
commit_hash_text = ' for %s' % msg['artifact']['commit_hash'][:8]
# test running messages
elif pipeline_state == 'running':
status = 'pending'
human_status = 'running'
pr_id = str(msg['rev']).partition('PR-')[2]
if not pr_id:
# test error messages
elif pipeline_state == 'error':
status = 'error'
human_status = 'errored'
if 'id' not in msg['artifact']:
print(
'Invalid revision: %s, could not extract the PR id from it' %
msg['rev'])
'Invalid message: %s, could not extract the PR id from it' %
msg['artifact'])
return
pr_id = str(msg['artifact']['id'])
data = {
'username': 'Fedora CI',
'status': status,
'comment': 'Package tests%s: %s' % (commit_hash_text, human_status),
'url': msg['build_url'],
'url': msg['run']['url'],
'uid': hashlib.md5(pr_id + seed).hexdigest()
}
pagure_url = 'https://src.fedoraproject.org'
env_var = 'API_TOKEN'
namespace = msg['artifact']['repository'].split('/')[-2]
repo = msg['artifact']['repository'].split('/')[-1]
target_url = '/'.join([
'api',
'0',
msg['namespace'],
msg['repo'],
namespace,
repo,
'pull-request',
pr_id,
'flag'
@ -116,9 +129,7 @@ def main(msg, pipeline_state='complete', seed='empty'):
return 1
else:
print('All clear')
print('User-URL: %s' % pagure_url + '/' + '/'.join([
msg['namespace'],
msg['repo'],
print('User-URL: %s' % msg['artifact']['repository'] + '/'.join([
'pull-request',
pr_id,
]))