def test_get_commit_history_not_found(test_push, test_repository): test_revision = '4c45a777949168d16c03a4cba167678b7ab65f76' # Does not exist as a Push in the DB. parent_revision = 'abcdef77949168d16c03a4cba167678b7ab65f76' commits_url = '{}/json-pushes?version=2&full=1&changeset={}'.format( test_repository.url, test_revision) commits = { 'pushes': { 1: { 'changesets': [ { 'author': 'Boris Chiou <*****@*****.**>', 'backsoutnodes': [], 'desc': 'Bug 1612891 - Suppress parsing easing error in early returns of ConvertKeyframeSequence.\n\nWe add a stack based class and supress the exception of parsing easing\nin the destructor, to avoid hitting the potential assertions.\n\nDifferential Revision: https://phabricator.services.mozilla.com/D64268\nDifferential Diff: PHID-DIFF-c4e7dcfpalwiem7bxsnk', 'node': '3ca259f9cbdea763e64f10e286e58b271d89ab9d', 'parents': [parent_revision], }, ] } } } responses.add(responses.GET, commits_url, json=commits, content_type='application/json', status=200) parent = get_commit_history(test_repository, test_revision, test_push) assert parent['parentSha'] == parent_revision assert parent['parentPushRevision'] is None
def test_get_commit_history(test_push, test_repository, mock_rev, mock_json_pushes): Push.objects.create( revision=parent_revision, repository=test_repository, author='*****@*****.**', time=datetime.datetime.now(), ) history = get_commit_history(test_repository, test_revision, test_push) print('\n<><><>history') print(history) assert history['parentSha'] == parent_revision assert history['parentRepository']['name'] == test_repository.name
def test_get_commit_history(test_push, test_repository, mock_rev, mock_json_pushes): Push.objects.create( revision=parent_revision, repository=test_repository, author='*****@*****.**', time=datetime.datetime.now(), ) mozciPush = MozciPush([parent_revision], test_repository.name) history = get_commit_history(mozciPush, test_push) assert history['parentSha'] == parent_revision assert history['parentRepository'] == test_repository.name
def test_get_commit_history_automationrelevance(test_push, test_repository): test_revision = '4c45a777949168d16c03a4cba167678b7ab65f76' parent_revision = 'abcdef77949168d16c03a4cba167678b7ab65f76' Push.objects.create( revision=parent_revision, repository=test_repository, author='*****@*****.**', time=datetime.datetime.now(), ) autorel_commits = { 'changesets': [ { 'author': 'Cheech Marin <*****@*****.**>', 'backsoutnodes': [], 'desc': 'Bug 1612891 - Suppress parsing easing error in early returns of ConvertKeyframeSequence.\n\nWe add a stack based class and supress the exception of parsing easing\nin the destructor, to avoid hitting the potential assertions.\n\nDifferential Revision: https://phabricator.services.mozilla.com/D64268\nDifferential Diff: PHID-DIFF-c4e7dcfpalwiem7bxsnk', 'node': '3ca259f9cbdea763e64f10e286e58b271d89ab9d', 'parents': [parent_revision], }, { 'author': 'libmozevent <*****@*****.**>', 'desc': 'try_task_config for https://phabricator.services.mozilla.com/D64268\nDifferential Diff: PHID-DIFF-c4e7dcfpalwiem7bxsnk', 'node': '18f68eb12ebbd88fe3a4fc3afe7df6529a0153fb', 'parents': ['3ca259f9cbdea763e64f10e286e58b271d89ab9d'], }, ], 'visible': True, } autorel_url = 'https://hg.mozilla.org/{}/json-automationrelevance/{}'.format( test_repository.name, test_revision) responses.add( responses.GET, autorel_url, json=autorel_commits, content_type='application/json', status=200, ) history = get_commit_history(test_repository, test_revision, test_push) assert history['parentSha'] == parent_revision assert history['parentPushRevision'] == parent_revision assert history['parentRepository']['name'] == test_repository.name
def test_get_commit_history_json_pushes(test_push, test_repository): test_revision = '4c45a777949168d16c03a4cba167678b7ab65f76' parent_revision = 'abcdef77949168d16c03a4cba167678b7ab65f76' Push.objects.create( revision=parent_revision, repository=test_repository, author='*****@*****.**', time=datetime.datetime.now(), ) autorel_url = 'https://hg.mozilla.org/{}/json-automationrelevance/{}'.format( test_repository.name, test_revision) responses.add(responses.GET, autorel_url, json={}, content_type='application/json', status=500) jsonpushes_commits = { 'pushes': { '108872': { 'changesets': [{ 'author': 'Hiro Protagonist <*****@*****.**>', 'desc': 'Bug 1617666 - Use a separate Debugger to improve performance of eval.', 'node': '4fb5e268cf7440332e917e431f14e8bb6dc41a0d', 'parents': [parent_revision], }] } } } commits_url = '{}/json-pushes?version=2&full=1&changeset={}'.format( test_repository.url, test_revision) responses.add( responses.GET, commits_url, json=jsonpushes_commits, content_type='application/json', status=200, ) history = get_commit_history(test_repository, test_revision, test_push) assert history['parentSha'] == parent_revision assert history['parentPushRevision'] == parent_revision assert history['parentRepository']['name'] == test_repository.name
def test_get_commit_history(test_push, test_repository, mock_rev, mock_json_pushes): autoland = Repository.objects.create( repository_group=test_repository.repository_group, name='autoland', dvcs_type=test_repository.dvcs_type, url='autoland', codebase=test_repository.codebase, ) Push.objects.create( revision=parent_revision, repository=autoland, author='*****@*****.**', time=datetime.datetime.now(), ) history = get_commit_history(test_push.repository, test_revision, test_push) assert history['parentSha'] == parent_revision assert history['parentPushRevision'] == parent_revision assert history['parentRepository']['name'] == autoland.name
def health(self, request, project): """ Return a calculated assessment of the health of this push. """ revision = request.query_params.get('revision') try: repository = Repository.objects.get(name=project) push = Push.objects.get(revision=revision, repository=repository) except Push.DoesNotExist: return Response( "No push with revision: {0}".format(revision), status=HTTP_404_NOT_FOUND ) commit_history_details = None result_status, jobs = get_test_failure_jobs(push) # Parent compare only supported for Hg at this time. # Bug https://bugzilla.mozilla.org/show_bug.cgi?id=1612645 if repository.dvcs_type == 'hg': commit_history_details = get_commit_history(repository, revision, push) test_result, push_health_test_failures = get_test_failures( push, jobs, result_status, ) build_result, build_failures, _unused = get_build_failures(push) lint_result, lint_failures, _unused = get_lint_failures(push) push_result = 'pass' for metric_result in [test_result, lint_result, build_result]: if ( metric_result == 'indeterminate' or metric_result == 'unknown' and push_result != 'fail' ): push_result = metric_result elif metric_result == 'fail': push_result = metric_result newrelic.agent.record_custom_event( 'push_health_need_investigation', { 'revision': revision, 'repo': repository.name, 'needInvestigation': len(push_health_test_failures['needInvestigation']), 'author': push.author, }, ) return Response( { 'revision': revision, 'id': push.id, 'result': push_result, 'jobs': jobs, 'metrics': { 'commitHistory': { 'name': 'Commit History', 'result': 'none', 'details': commit_history_details, }, 'linting': { 'name': 'Linting', 'result': lint_result, 'details': lint_failures, }, 'tests': { 'name': 'Tests', 'result': test_result, 'details': push_health_test_failures, }, 'builds': { 'name': 'Builds', 'result': build_result, 'details': build_failures, }, }, 'status': push.get_status(), } )
def health(self, request, project): """ Return a calculated assessment of the health of this push. """ revision = request.query_params.get('revision') try: push = Push.objects.select_related('repository').get( revision=revision, repository__name=project) except Push.DoesNotExist: return Response(f"No push with revision: {revision}", status=HTTP_404_NOT_FOUND) mozciPush = MozciPush([revision], project) commit_history_details = None if push.repository.dvcs_type == 'hg': commit_history_details = get_commit_history(mozciPush, push) tests, builds, lints, status, total_failures, jobs = self._get_failure_data( mozciPush, push) test_result, test_failures = tests build_result, build_failures, _unused = builds lint_result, lint_failures, _unused = lints push_result = 'pass' for metric_result in [test_result, lint_result, build_result]: if (metric_result == 'indeterminate' or metric_result == 'unknown' and push_result != 'fail'): push_result = metric_result elif metric_result == 'fail': push_result = metric_result newrelic.agent.record_custom_event( 'push_health_need_investigation', { 'revision': revision, 'repo': project, 'needInvestigation': len(test_failures['needInvestigation']['tests']), 'author': push.author, }, ) return Response({ 'revision': revision, 'id': push.id, 'result': push_result, 'jobs': jobs, 'metrics': { 'commitHistory': { 'name': 'Commit History', 'result': 'none', 'details': commit_history_details, }, 'linting': { 'name': 'Linting', 'result': lint_result, 'details': lint_failures, }, 'tests': { 'name': 'Tests', 'result': test_result, 'details': test_failures, }, 'builds': { 'name': 'Builds', 'result': build_result, 'details': build_failures, }, }, 'status': status, })
def health(self, request, project): """ Return a calculated assessment of the health of this push. """ revision = request.query_params.get('revision') try: repository = Repository.objects.get(name=project) push = Push.objects.get(revision=revision, repository=repository) except Push.DoesNotExist: return Response("No push with revision: {0}".format(revision), status=HTTP_404_NOT_FOUND) push_health_test_failures = get_test_failures(push, REPO_GROUPS['trunk']) test_result = 'pass' if len(push_health_test_failures['unsupported']): test_result = 'indeterminate' if len(push_health_test_failures['needInvestigation']): test_result = 'fail' # Parent link only supported for Hg at this time. # Bug https://bugzilla.mozilla.org/show_bug.cgi?id=1612645 commit_history_details = None if repository.dvcs_type == 'git' \ else get_commit_history(repository, revision, push) build_failures = get_build_failures(push) build_result = 'fail' if len(build_failures) else 'pass' lint_failures = get_lint_failures(push) lint_result = 'fail' if len(lint_failures) else 'pass' perf_failures = get_perf_failures(push) perf_result = 'fail' if len(perf_failures) else 'pass' push_result = 'pass' for metric_result in [ test_result, lint_result, build_result, perf_result ]: if metric_result == 'indeterminate' and push_result != 'fail': push_result = metric_result elif metric_result == 'fail': push_result = metric_result newrelic.agent.record_custom_event( 'push_health_need_investigation', { 'revision': revision, 'repo': repository.name, 'needInvestigation': len(push_health_test_failures['needInvestigation']), 'unsupported': len(push_health_test_failures['unsupported']), }) return Response({ 'revision': revision, 'id': push.id, 'result': push_result, 'metrics': { 'commitHistory': { 'name': 'Commit History', 'result': 'none', 'details': commit_history_details, }, 'linting': { 'name': 'Linting', 'result': lint_result, 'details': lint_failures, }, 'tests': { 'name': 'Tests', 'result': test_result, 'details': push_health_test_failures, }, 'builds': { 'name': 'Builds', 'result': build_result, 'details': build_failures, }, 'performance': { 'name': 'Performance', 'result': perf_result, 'details': perf_failures, }, }, 'status': push.get_status(), })