From 4120c9c71dbcf6e229093e9470219a5c35d9a07e Mon Sep 17 00:00:00 2001 From: Bruno Goncalves Date: Thu, 21 Nov 2019 10:53:10 +0100 Subject: [PATCH] uses CI message version 0.2.X process CI messages as defined on https://pagure.io/fedora-ci/messages/blob/master/f/schemas --- ...tos.prod.ci.dist-git-pr.test.complete.yml} | 2 +- ....centos.prod.ci.dist-git-pr.test.error.yml | 14 ++++++ ...ntos.prod.ci.dist-git-pr.test.running.yml} | 2 +- .../roles/flag_ci_pr/files/flag_ci_pr.py | 47 ++++++++++++------- 4 files changed, 45 insertions(+), 20 deletions(-) rename playbooks/{org.centos.prod.ci.pipeline.allpackages-pr.complete.yml => org.centos.prod.ci.dist-git-pr.test.complete.yml} (81%) create mode 100644 playbooks/org.centos.prod.ci.dist-git-pr.test.error.yml rename playbooks/{org.centos.prod.ci.pipeline.allpackages-pr.package.running.yml => org.centos.prod.ci.dist-git-pr.test.running.yml} (79%) diff --git a/playbooks/org.centos.prod.ci.pipeline.allpackages-pr.complete.yml b/playbooks/org.centos.prod.ci.dist-git-pr.test.complete.yml similarity index 81% rename from playbooks/org.centos.prod.ci.pipeline.allpackages-pr.complete.yml rename to playbooks/org.centos.prod.ci.dist-git-pr.test.complete.yml index 856a885..a34df68 100644 --- a/playbooks/org.centos.prod.ci.pipeline.allpackages-pr.complete.yml +++ b/playbooks/org.centos.prod.ci.dist-git-pr.test.complete.yml @@ -1,5 +1,5 @@ --- -- name: ci.pipeline.allpackages-pr.complete +- name: ci.dist-git-pr.test.complete hosts: localhost gather_facts: false diff --git a/playbooks/org.centos.prod.ci.dist-git-pr.test.error.yml b/playbooks/org.centos.prod.ci.dist-git-pr.test.error.yml new file mode 100644 index 0000000..0d6ea87 --- /dev/null +++ b/playbooks/org.centos.prod.ci.dist-git-pr.test.error.yml @@ -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"} + diff --git a/playbooks/org.centos.prod.ci.pipeline.allpackages-pr.package.running.yml b/playbooks/org.centos.prod.ci.dist-git-pr.test.running.yml similarity index 79% rename from playbooks/org.centos.prod.ci.pipeline.allpackages-pr.package.running.yml rename to playbooks/org.centos.prod.ci.dist-git-pr.test.running.yml index 26ca63e..673497a 100644 --- a/playbooks/org.centos.prod.ci.pipeline.allpackages-pr.package.running.yml +++ b/playbooks/org.centos.prod.ci.dist-git-pr.test.running.yml @@ -1,5 +1,5 @@ --- -- name: ci.pipeline.allpackages-pr.package.running +- name: ci.dist-git-pr.test.running hosts: localhost gather_facts: false diff --git a/playbooks/roles/flag_ci_pr/files/flag_ci_pr.py b/playbooks/roles/flag_ci_pr/files/flag_ci_pr.py index ea0e407..2e39099 100644 --- a/playbooks/roles/flag_ci_pr/files/flag_ci_pr.py +++ b/playbooks/roles/flag_ci_pr/files/flag_ci_pr.py @@ -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, ]))