Exemplo n.º 1
0
    def upload(self, report, changesets=None):
        results = self.generate(report, changesets)

        if secrets[secrets.PHABRICATOR_ENABLED]:
            phabricator = PhabricatorAPI(secrets[secrets.PHABRICATOR_TOKEN], secrets[secrets.PHABRICATOR_URL])
        else:
            phabricator = None

        for rev_id, coverage in results.items():
            logger.info('{} coverage: {}'.format(rev_id, coverage))

            if not phabricator or not coverage:
                continue

            try:
                rev_data = phabricator.load_revision(rev_id=rev_id)
                phabricator.upload_coverage_results(rev_data['fields']['diffPHID'], coverage)
                # XXX: This is only necessary until https://bugzilla.mozilla.org/show_bug.cgi?id=1487843 is resolved.
                phabricator.upload_lint_results(rev_data['fields']['diffPHID'], BuildState.Pass, [])
            except PhabricatorRevisionNotFoundException:
                logger.warn('Phabricator revision not found', rev_id=rev_id)
Exemplo n.º 2
0
    def upload(self, report, changesets=None):
        results = self.generate(report, changesets)

        if secrets[secrets.PHABRICATOR_ENABLED]:
            phabricator = PhabricatorAPI(secrets[secrets.PHABRICATOR_TOKEN],
                                         secrets[secrets.PHABRICATOR_URL])
        else:
            phabricator = None

        for rev_id, coverage in results.items():
            logger.info('{} coverage: {}'.format(rev_id, coverage))

            if not phabricator or not coverage:
                continue

            rev_data = phabricator.load_revision(rev_id=rev_id)
            phabricator.upload_coverage_results(rev_data['fields']['diffPHID'],
                                                coverage)
            # XXX: This is only necessary until https://bugzilla.mozilla.org/show_bug.cgi?id=1487843 is resolved.
            phabricator.upload_lint_results(rev_data['fields']['diffPHID'],
                                            'pass', [])
Exemplo n.º 3
0
class HookPhabricator(Hook):
    '''
    Taskcluster hook handling the static analysis
    for Phabricator differentials
    '''
    latest_id = None

    def __init__(self, configuration):
        assert 'hookId' in configuration
        super().__init__(
            'project-releng',
            configuration['hookId'],
        )

        # Connect to Phabricator API
        assert 'phabricator_url' in configuration
        assert 'phabricator_token' in configuration
        self.api = PhabricatorAPI(
            api_key=configuration['phabricator_token'],
            url=configuration['phabricator_url'],
        )

        # List enabled repositories
        enabled = configuration.get('repositories', [
            'mozilla-central',
        ])
        self.repos = {
            r['phid']: r
            for r in self.api.list_repositories()
            if r['fields']['name'] in enabled
        }
        assert len(self.repos) > 0, 'No repositories enabled'
        logger.info('Enabled Phabricator repositories',
                    repos=[r['fields']['name'] for r in self.repos.values()])

        # Start by getting top id
        diffs = self.api.search_diffs(limit=1)
        assert len(diffs) == 1
        self.latest_id = diffs[0]['id']

    def list_differential(self):
        '''
        List new differential items using pagination
        using an iterator
        '''
        cursor = self.latest_id
        while cursor is not None:
            diffs, cursor = self.api.search_diffs(
                order='oldest',
                limit=20,
                after=self.latest_id,
                output_cursor=True,
            )
            if not diffs:
                break

            for diff in diffs:
                yield diff

            # Update the latest id
            if cursor and cursor['after']:
                self.latest_id = cursor['after']
            elif len(diffs) > 0:
                self.latest_id = diffs[-1]['id']

    async def build_consumer(self, *args, **kwargs):
        '''
        Query phabricator differentials regularly
        '''
        while True:

            # Get new differential ids
            for diff in self.list_differential():
                if diff['type'] != 'DIFF':
                    logger.info('Skipping differential, not a diff',
                                id=diff['id'],
                                type=diff['type'])
                    continue

                # Load revision to check the repository is authorized
                rev = self.api.load_revision(diff['revisionPHID'])
                repo_phid = rev['fields']['repositoryPHID']
                if repo_phid not in self.repos:
                    logger.info('Skipping differential, repo not enabled',
                                id=diff['id'],
                                repo=repo_phid)
                    continue

                # Create new task
                await self.create_task({
                    'ANALYSIS_SOURCE': 'phabricator',
                    'ANALYSIS_ID': diff['phid']
                })

            # Sleep a bit before trying new diffs
            await asyncio.sleep(60)