コード例 #1
0
ファイル: quarantine_tasks.py プロジェクト: dropbox/changes
    def get(self):
        """
        Gets the list of open tasks associated with quarantined tests. We find
        them based on the fact that they're always created by the same
        bot/user.
        """

        try:
            quarantine_user = current_app.config['QUARANTINE_PHID']
            if not quarantine_user:
                return self.respond({
                    'fetched_data_from_phabricator': False
                })

            request = PhabricatorClient()
            request.connect()
            task_info = request.call('maniphest.query', {'authorPHIDs': [quarantine_user]})

            # we need to get the names of the task owners too
            user_info = {}
            owner_phids = [t['ownerPHID'] for t in task_info.values() if t.get('ownerPHID')]
            if owner_phids:
                user_info = request.call('phid.query', {'phids': owner_phids})

            return self.respond({
                'fetched_data_from_phabricator': True,
                'tasks': task_info,
                'users': user_info
            })

        except requests.exceptions.ConnectionError:
            return 'Unable to connect to Phabricator', 503
コード例 #2
0
    def get(self):
        """
        Gets the list of open tasks associated with quarantined tests. We find
        them based on the fact that they're always created by the same
        bot/user.
        """

        try:
            quarantine_user = current_app.config['QUARANTINE_PHID']
            if not quarantine_user:
                return self.respond({'fetched_data_from_phabricator': False})

            request = PhabricatorClient()
            request.connect()
            task_info = request.call('maniphest.query',
                                     {'authorPHIDs': [quarantine_user]})

            # we need to get the names of the task owners too
            user_info = {}
            owner_phids = [
                t['ownerPHID'] for t in task_info.values()
                if t.get('ownerPHID')
            ]
            if owner_phids:
                user_info = request.call('phid.query', {'phids': owner_phids})

            return self.respond({
                'fetched_data_from_phabricator': True,
                'tasks': task_info,
                'users': user_info
            })

        except requests.exceptions.ConnectionError:
            return 'Unable to connect to Phabricator', 503
コード例 #3
0
ファイル: author_diffs.py プロジェクト: mitsuhiko/changes
    def get(self, author_id):
        authors = Author.find(author_id, get_current_user())
        if not authors and author_id == 'me':
            return '''Either there is no current user or you are not in the
              author table''', 401
        elif not authors:
            return 'author not found', 404

        try:
            author_email = authors[0].email
            request = PhabricatorClient()
            request.connect()
            user_info = request.call('user.query', {'emails': [author_email]})

            if not user_info:
                return 'phabricator: %s not found' % author_email, 404

            author_phid = user_info[0]["phid"]

            diff_info = request.call('differential.query', {
                'authors': [author_phid],
                'status': "status-open"
            })

            diff_info.sort(key=lambda k: -1 * int(k['dateModified']))

        except requests.exceptions.ConnectionError:
            return 'Unable to connect to Phabricator', 503

        if not diff_info:
            # No diffs, no point in trying to find builds.
            return self.respond([])

        rows = list(db.session.query(
            PhabricatorDiff, Build
        ).join(
            Build, Build.source_id == PhabricatorDiff.source_id
        ).filter(
            PhabricatorDiff.revision_id.in_([d['id'] for d in diff_info])
        ))

        serialized_builds = zip(
            self.serialize([row.Build for row in rows]),
            [row.PhabricatorDiff for row in rows]
        )

        builds_map = defaultdict(list)
        for build, phabricator_diff in serialized_builds:
            builds_map[str(phabricator_diff.revision_id)].append(build)

        for d in diff_info:
            d['builds'] = builds_map[str(d['id'])]

        return self.respond(diff_info)
コード例 #4
0
    def get(self, author_id):
        if author_id == 'me' and not get_current_user():
            return error('Must be logged in to ask about yourself',
                         http_code=401)
        authors = Author.find(author_id, get_current_user())
        if not authors:
            return self.respond([])

        try:
            author_email = authors[0].email
            request = PhabricatorClient()
            request.connect()
            user_info = request.call('user.query', {'emails': [author_email]})

            if not user_info:
                return 'phabricator: %s not found' % author_email, 404

            author_phid = user_info[0]["phid"]

            diff_info = request.call('differential.query', {
                'authors': [author_phid],
                'status': "status-open"
            })

            diff_info.sort(key=lambda k: -1 * int(k['dateModified']))

        except requests.exceptions.ConnectionError:
            return 'Unable to connect to Phabricator', 503

        if not diff_info:
            # No diffs, no point in trying to find builds.
            return self.respond([])

        rows = list(
            db.session.query(PhabricatorDiff, Build).join(
                Build, Build.source_id == PhabricatorDiff.source_id).filter(
                    PhabricatorDiff.revision_id.in_(
                        [d['id'] for d in diff_info])))

        serialized_builds = zip(self.serialize([row.Build for row in rows]),
                                [row.PhabricatorDiff for row in rows])

        builds_map = defaultdict(list)
        for build, phabricator_diff in serialized_builds:
            builds_map[str(phabricator_diff.revision_id)].append(build)

        for d in diff_info:
            d['builds'] = builds_map[str(d['id'])]

        return self.respond(diff_info)
コード例 #5
0
    def get(self, diff_ident):
        if not diff_ident.startswith('D') or not diff_ident[1:].isdigit():
            return error('diff id not valid')

        # grab diff info from phabricator.
        phabricator_info = {}
        try:
            request = PhabricatorClient()
            request.connect()

            phabricator_info = request.call('differential.query',
                                            {'ids': [int(diff_ident[1:])]})
            if len(phabricator_info) == 0:
                return error('%s not found in phabricator' % diff_ident,
                             http_code=404)
            assert len(phabricator_info) == 1
            phabricator_info = phabricator_info[0]
            phabricator_info["fetched_data_from_phabricator"] = True
        except Exception as e:
            # If the phabricator call fails for whatever reason, we'll still
            # return the builds info from changes. We don't want changes to
            # be unusable if phabricator is down
            print e
            phabricator_info = {"fetched_data_from_phabricator": False}
            pass

        # TODO: if we want the name/email of the author of the diff, we'd have
        # to make another conduit call. Instead, we'll let the frontend rely
        # on the fact that any phabricator-tagged build always has the same
        # author as the diff

        # grab builds
        rows = list(
            db.session.query(Build, PhabricatorDiff).join(
                PhabricatorDiff,
                Build.source_id == PhabricatorDiff.source_id,
            ).filter(PhabricatorDiff.revision_id == diff_ident[1:]))

        build_ids = set([row.Build.id for row in rows])

        jobs = []
        if len(build_ids) > 0:
            jobs = self.serialize(
                list(Job.query.filter(Job.build_id.in_(build_ids))))

        serialized_builds = zip(self.serialize([row.Build for row in rows]),
                                [row.PhabricatorDiff for row in rows])

        build_info = {}
        for build, phabricator_diff in serialized_builds:
            # we may have multiple diffs within a single differential revision
            single_diff_id = phabricator_diff.diff_id
            if single_diff_id not in build_info:
                build_info[single_diff_id] = {
                    'id': phabricator_diff.id,
                    'builds': [],
                    'diff_id': phabricator_diff.diff_id,
                    'revision_id': phabricator_diff.revision_id,
                    'url': phabricator_diff.url,
                    'source_id': phabricator_diff.source_id,
                    'dateCreated': phabricator_diff.date_created
                }
            build['jobs'] = [
                j for j in jobs if j['build']['id'] == build['id']
            ]
            build_info[single_diff_id]['builds'].append(build)

        phabricator_info['changes'] = build_info

        return self.respond(phabricator_info)
コード例 #6
0
ファイル: diff_builds.py プロジェクト: mitsuhiko/changes
    def get(self, diff_ident):
        if not diff_ident.startswith('D') or not diff_ident[1:].isdigit():
            return 400, 'diff id not valid'

        # grab diff info from phabricator.
        phabricator_info = {}
        try:
            request = PhabricatorClient()
            request.connect()

            phabricator_info = request.call('differential.query', {
                'ids': [int(diff_ident[1:])]
            })
            if len(phabricator_info) == 0:
                return 404, '%s not found in phabricator' % diff_ident
            assert len(phabricator_info) == 1
            phabricator_info = phabricator_info[0]
            phabricator_info["fetched_data_from_phabricator"] = True
        except Exception as e:
            # If the phabricator call fails for whatever reason, we'll still
            # return the builds info from changes. We don't want changes to
            # be unusable if phabricator is down
            print e
            phabricator_info = {
                "fetched_data_from_phabricator": False
            }
            pass

        # TODO: if we want the name/email of the author of the diff, we'd have
        # to make another conduit call. Instead, we'll let the frontend rely
        # on the fact that any phabricator-tagged build always has the same
        # author as the diff

        # grab builds
        rows = list(db.session.query(
            Build, PhabricatorDiff
        ).join(
            PhabricatorDiff, Build.source_id == PhabricatorDiff.source_id,
        ).filter(
            PhabricatorDiff.revision_id == diff_ident[1:]
        ))

        build_ids = set([row.Build.id for row in rows])

        jobs = []
        if len(build_ids) > 0:
            jobs = self.serialize(list(Job.query.filter(
                Job.build_id.in_(build_ids)
            )))

        serialized_builds = zip(
            self.serialize([row.Build for row in rows]),
            [row.PhabricatorDiff for row in rows]
        )

        build_info = {}
        for build, phabricator_diff in serialized_builds:
            # we may have multiple diffs within a single differential revision
            single_diff_id = phabricator_diff.diff_id
            if single_diff_id not in build_info:
                build_info[single_diff_id] = {
                    'id': phabricator_diff.id,
                    'builds': [],
                    'diff_id': phabricator_diff.diff_id,
                    'revision_id': phabricator_diff.revision_id,
                    'url': phabricator_diff.url,
                    'source_id': phabricator_diff.source_id,
                    'dateCreated': phabricator_diff.date_created
                }
            build['jobs'] = [j for j in jobs if j['build']['id'] == build['id']]
            build_info[single_diff_id]['builds'].append(build)

        phabricator_info['changes'] = build_info

        return self.respond(phabricator_info, serialize=False)