Esempio n. 1
0
def mock_config():
    '''
    Mock configuration for bot
    '''
    path = os.path.join(MOCK_DIR, 'config.yaml')
    responses.add(
        responses.GET,
        'https://hg.mozilla.org/mozilla-central/raw-file/tip/tools/clang-tidy/config.yaml',
        body=open(path).read(),
        content_type='text/plain',
    )

    from shipit_static_analysis.config import settings
    settings.setup('test')
    return settings
Esempio n. 2
0
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,
            )