def test_mozreview(): ''' Test a mozreview revision ''' from shipit_static_analysis.revisions import MozReviewRevision r = MozReviewRevision('308c22e7899048467002de4ffb126cac0875c994:164530:7') assert r.mercurial == '308c22e7899048467002de4ffb126cac0875c994' assert r.review_request_id == 164530 assert r.diffset_revision == 7 assert r.url == 'https://reviewboard.mozilla.org/r/164530/' assert r.build_diff_name() == '308c22e7-164530-7-clang-format.diff'
def test_review_publication(mock_mozreview, mock_issues, mock_phabricator): ''' Test publication of a single review ''' from shipit_static_analysis.report.mozreview import MozReviewReporter from shipit_static_analysis.revisions import MozReviewRevision # Add mock files listing httpretty.register_uri( httpretty.POST, re.compile( 'http://mozreview.test/api/review-requests/(\d+)/diffs/(\w+)/files/' ), body='{}', ) # Publish issues on mozreview conf = { 'username': '******', 'api_key': 'deadbeef123', 'url': 'http://mozreview.test', } r = MozReviewReporter(conf, 'test_tc', 'token_tc') mrev = MozReviewRevision('abcdef:12345:1') out = r.publish(mock_issues, mrev, diff_url=None) assert out is None # no publication (no clang-tidy)
def test_mail(mock_issues, mock_phabricator): ''' Test mail sending through Taskcluster ''' from shipit_static_analysis.report.mail import MailReporter from shipit_static_analysis.revisions import MozReviewRevision, PhabricatorRevision from shipit_static_analysis.report.phabricator import PhabricatorReporter phab = PhabricatorReporter({ 'url': 'http://phabricator.test/api/', 'api_key': 'deadbeef', }) def _check_email(request): payload = json.loads(request.body) assert payload['subject'] in ( '[test] New Static Analysis MozReview #12345 - 1', '[test] New Static Analysis Phabricator #42 - PHID-DIFF-test', ) assert payload['address'] == '*****@*****.**' assert payload['template'] == 'fullscreen' assert payload['content'].startswith( '\n# Found 3 publishable issues (5 total)') return (200, {}, '') # ack # Add mock taskcluster email to check output responses.add_callback( responses.POST, 'https://notify.taskcluster.net/v1/email', callback=_check_email, ) # Publish email conf = { 'emails': [ '*****@*****.**', ], } r = MailReporter(conf, 'test_tc', 'token_tc') # Publish for mozreview mrev = MozReviewRevision('abcdef:12345:1') r.publish(mock_issues, mrev) prev = PhabricatorRevision('42:PHID-DIFF-test', phab) r.publish(mock_issues, prev) # Check stats mock_cls = mock_issues[0].__class__ assert r.calc_stats(mock_issues) == { mock_cls: { 'total': 5, 'publishable': 3, } }
def test_review_publication(mock_mozreview, mock_issues, mock_phabricator): ''' Test publication of a single review ''' from shipit_static_analysis.report.mozreview import MozReviewReporter from shipit_static_analysis.revisions import MozReviewRevision # Publish issues on mozreview conf = { 'username': '******', 'api_key': 'deadbeef123', 'url': 'http://mozreview.test', } r = MozReviewReporter(conf, 'test_tc', 'token_tc') mrev = MozReviewRevision('abcdef:12345:1') out = r.publish(mock_issues, mrev, diff_url=None) assert out is None # no publication (no clang-tidy)
def main( phabricator, mozreview, cache_root, taskcluster_secret, taskcluster_client_id, taskcluster_access_token, ): assert (phabricator is None) ^ (mozreview is None), \ 'Specify a phabricator XOR mozreview parameters' secrets = get_secrets( taskcluster_secret, config.PROJECT_NAME, required=( 'APP_CHANNEL', 'REPORTERS', 'ANALYZERS', ), existing={ 'APP_CHANNEL': 'development', 'REPORTERS': [], 'ANALYZERS': [ 'clang-tidy', ], }, taskcluster_client_id=taskcluster_client_id, taskcluster_access_token=taskcluster_access_token, ) init_logger( config.PROJECT_NAME, PAPERTRAIL_HOST=secrets.get('PAPERTRAIL_HOST'), PAPERTRAIL_PORT=secrets.get('PAPERTRAIL_PORT'), SENTRY_DSN=secrets.get('SENTRY_DSN'), MOZDEF=secrets.get('MOZDEF'), ) # Setup settings before stats settings.setup(secrets['APP_CHANNEL']) # Setup statistics datadog_api_key = secrets.get('DATADOG_API_KEY') if datadog_api_key: stats.auth(datadog_api_key) # Load reporters reporters = get_reporters( secrets['REPORTERS'], taskcluster_client_id, taskcluster_access_token, ) # Load revisions revisions = [] if phabricator: # Only one phabricator revision at a time api = reporters.get('phabricator') assert api is not None, \ 'Cannot use a phabricator revision without a phabricator reporter' revisions.append(PhabricatorRevision(phabricator, api)) if mozreview: # Multiple mozreview revisions are possible revisions += [MozReviewRevision(r) for r in mozreview.split(' ')] w = Workflow(cache_root, reporters, secrets['ANALYZERS']) for revision in revisions: try: w.run(revision) except Exception as e: # Log errors to papertrail logger.error( 'Static analysis failure', revision=revision, error=e, )