PR flags: adds support for running/pending state
This patch adds support for runinng state for Fedora CI. It keeps only the recent flag around, so running transitions nicely to complete/error state and vice versa (for reruns). Resolves https://pagure.io/fedora-ci/general/issue/3 Signed-off-by: Miroslav Vadkerti <mvadkert@redhat.com>
This commit is contained in:
parent
e42c8ddf0a
commit
e803bad648
4 changed files with 49 additions and 18 deletions
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
- name: buildsys.build.state.change
|
||||
- name: ci.pipeline.allpackages-pr.complete
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
|
||||
|
@ -10,5 +10,5 @@
|
|||
- debug: var=msg
|
||||
|
||||
roles:
|
||||
- {role: flag_ci_pr, msg: msg}
|
||||
- {role: flag_ci_pr, msg: msg, state: "running", seed_flag_ci_pr: seed_flag_ci_pr}
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
- name: ci.pipeline.allpackages-pr.package.running
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
|
||||
vars_files:
|
||||
- "/srv/private/vars_loopabull.yml"
|
||||
|
||||
tasks:
|
||||
- debug: var=msg
|
||||
|
||||
roles:
|
||||
- {role: flag_ci_pr, msg: msg, state: "running", seed_flag_ci_pr: seed_flag_ci_pr}
|
||||
|
|
@ -12,6 +12,7 @@ Authors: Pierre-Yves Chibon <pingou@pingoured.fr>
|
|||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
@ -19,11 +20,13 @@ import sys
|
|||
import requests
|
||||
from requests.packages.urllib3.util import retry
|
||||
|
||||
|
||||
|
||||
def main(msg):
|
||||
def main(msg, pipeline_state='complete', seed='empty'):
|
||||
""" Check if the build was successful and if so, flag the commit in
|
||||
pagure.
|
||||
|
||||
:param str msg: the fedmsg message body
|
||||
:param str pipeline_state: state of the testing, one of 'complete'
|
||||
or 'running'
|
||||
"""
|
||||
|
||||
timeout = (30, 30)
|
||||
|
@ -37,16 +40,30 @@ def main(msg):
|
|||
requests_session.mount(
|
||||
'https://', requests.adapters.HTTPAdapter(max_retries=retry_conf))
|
||||
|
||||
done_states = {
|
||||
'SUCCESS': {'api': 'success', 'human': 'passed'},
|
||||
'UNSTABLE': {'api': 'failure', 'human': 'failed'},
|
||||
'FAILURE': {'api': 'error', 'human': 'errored'},
|
||||
}
|
||||
state = msg['status']
|
||||
if state not in done_states:
|
||||
print('Build is not in one of the expected status, ignoring')
|
||||
if pipeline_state not in ['complete', 'running']:
|
||||
print("Pipeline state is not 'complete' or 'running'.")
|
||||
return
|
||||
|
||||
# test complete messages
|
||||
if pipeline_state == 'complete':
|
||||
done_states = {
|
||||
'SUCCESS': {'api': 'success', 'human': 'passed'},
|
||||
'UNSTABLE': {'api': 'failure', 'human': 'failed'},
|
||||
'FAILURE': {'api': 'error', 'human': 'errored'},
|
||||
}
|
||||
state = msg['status']
|
||||
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']
|
||||
|
||||
# test running messages
|
||||
elif pipeline_state == 'running':
|
||||
status = 'pending'
|
||||
human_status = 'running'
|
||||
|
||||
pr_id = msg['rev'].partition('PR-')[2]
|
||||
if not pr_id:
|
||||
print(
|
||||
|
@ -54,12 +71,12 @@ def main(msg):
|
|||
msg['rev'])
|
||||
return
|
||||
|
||||
|
||||
data = {
|
||||
'username': 'Fedora CI',
|
||||
'status': done_states[state]['api'],
|
||||
'comment': 'Package tests: %s' % (done_states[state]['human']),
|
||||
'status': status,
|
||||
'comment': 'Package tests: %s' % human_status,
|
||||
'url': msg['build_url'],
|
||||
'uid': hashlib.md5(pr_id + seed).hexdigest()
|
||||
}
|
||||
|
||||
pagure_url = 'https://src.fedoraproject.org'
|
||||
|
@ -107,4 +124,4 @@ def main(msg):
|
|||
if __name__ == '__main__':
|
||||
msg = sys.argv[1]
|
||||
msg = json.loads(msg)
|
||||
sys.exit(main(msg))
|
||||
sys.exit(main(msg, sys.argv[2], sys.argv[3]))
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
mode: 0755
|
||||
|
||||
- name: Run the script
|
||||
command: /usr/local/bin/flag_ci_pr.py {{ msg | to_json | quote }}
|
||||
command: /usr/local/bin/flag_ci_pr.py {{ msg | to_json | quote }} {{ state | quote }} {{ seed_flag_pr_ci | quote }}
|
||||
register: output
|
||||
environment:
|
||||
API_TOKEN: "{{ api_token_flag_pr_ci }}"
|
||||
|
|
Reference in a new issue