Commit status change depending on e2e tests results

Signed-off-by: Anton Danchenko <ant.danchenko@gmail.com>
This commit is contained in:
yevh-berdnyk 2018-11-24 17:18:31 +01:00 committed by Anton Danchenko
parent 5f910a0bec
commit 62c7d645b7
No known key found for this signature in database
GPG Key ID: C2D4819B698627E4
3 changed files with 39 additions and 2 deletions

View File

@ -0,0 +1,11 @@
import requests
def get_jenkins_build_url(pr_number: str) -> str:
jenkins_api_url = 'https://ci.status.im/job/end-to-end-tests/job/status-app-end-to-end-tests/'
builds_list = requests.get(jenkins_api_url + 'api/json?tree=builds[id,url]').json()[
'builds']
for build in builds_list:
data = requests.get('%s/%s/api/json' % (jenkins_api_url, build['id'])).json()
if data['displayName'] == 'PR-' + pr_number:
return build['url'] + '/console'

View File

@ -102,6 +102,16 @@ class TestrailReport(BaseTestReport):
else devices + test_steps}
self.post(method, data=data)
def get_run_results(self):
return self.get('get_results_for_run/%s' % self.run_id)
def is_run_successful(self):
for test in self.get_run_results():
if test['status_id'] != 1:
return False
else:
return True
def get_test_result_link(self, test_run_id, test_case_id):
try:
test_id = self.get('get_results_for_case/%s/%s' % (test_run_id, test_case_id))[0]['test_id']

View File

@ -10,6 +10,7 @@ from datetime import datetime
from os import environ
from io import BytesIO
from sauceclient import SauceClient
from support.api.jenkins_api import get_jenkins_build_url
from support.api.network_api import NetworkApi
from support.github_report import GithubHtmlReport
from support.testrail_report import TestrailReport
@ -143,14 +144,21 @@ def pytest_configure(config):
test_suite_data.apk_name = ([i for i in [i for i in config.getoption('apk').split('/')
if '.apk' in i]])[0]
if is_master(config):
pr_number = config.getoption('pr_number')
if config.getoption('testrail_report'):
pr_number = config.getoption('pr_number')
if pr_number:
run_number = len(testrail_report.get_runs(pr_number)) + 1
run_name = 'PR-%s run #%s' % (pr_number, run_number)
else:
run_name = test_suite_data.apk_name
testrail_report.add_run(run_name)
if pr_number:
from github import Github
repo = Github(github_token).get_user('status-im').get_repo('status-react')
pull = repo.get_pull(int(pr_number))
pull.get_commits()[0].create_status(state='pending', context='Mobile e2e tests',
description='e2e tests are running',
target_url=get_jenkins_build_url(pr_number))
if config.getoption('env') == 'sauce':
if not is_uploaded():
if 'http' in config.getoption('apk'):
@ -175,7 +183,15 @@ def pytest_unconfigure(config):
from github import Github
repo = Github(github_token).get_user('status-im').get_repo('status-react')
pull = repo.get_pull(int(config.getoption('pr_number')))
pull.create_issue_comment(github_report.build_html_report(testrail_report.run_id))
comment = pull.create_issue_comment(github_report.build_html_report(testrail_report.run_id))
if not testrail_report.is_run_successful():
pull.get_commits()[0].create_status(state='failure', context='Mobile e2e tests',
description='Failure - e2e tests are failed',
target_url=comment.html_url)
else:
pull.get_commits()[0].create_status(state='success', context='Mobile e2e tests',
description='Success - e2e tests are passed',
target_url=comment.html_url)
def should_save_device_stats(config):