Пример #1
0
    def get(self, project_id):
        project = Project.get(project_id)
        if not project:
            return '', 404

        args = self.get_parser.parse_args()

        filters = []

        if args.authors:
            filters.append(Build.author_id.in_([a.id for a in args.authors]))
        elif args.authors is not None:
            return []

        if args.source:
            filters.append(Build.target.startswith(args.source))

        # is this from the search bar
        if args.query:
            clauses = []
            # search by revision title
            clauses.append(Build.label.contains(args.query))
            # search by prefix
            clauses.append(Build.target.startswith(args.query))
            # allows users to paste a full commit hash and still
            # find the relevant build(s). Should be fine for mercurial/git,
            # and svn will never have long enough strings
            if len(args.query) > 12:
                clauses.append(Build.target.startswith(args.query[0:12]))
            # if they searched for something that looks like a phabricator
            # identifier, try to find it
            if might_be_diffusion_iden(args.query):
                possible_hash = get_hash_from_diffusion_iden(args.query)
                if possible_hash:
                    # the query should always be at least as long or longer than
                    # our commit identifiers
                    clauses.append(
                        Build.target.startswith(possible_hash[0:12]))
            filters.append(or_(*clauses))

        if args.result:
            filters.append(Build.result == Result[args.result])

        if args.patches_only:
            filters.append(Source.patch_id != None)  # NOQA
        elif not args.include_patches:
            filters.append(Source.patch_id == None)  # NOQA

        queryset = Build.query.options(
            joinedload('project', innerjoin=True),
            joinedload('author'),
            contains_eager('source').joinedload('revision'),
        ).join(
            Source, Source.id == Build.source_id,
        ).filter(
            Build.project_id == project.id,
            *filters
        ).order_by(Build.date_created.desc())

        return self.paginate(queryset)
Пример #2
0
    def test_get_hash(self):
        identifiers = {
            "rREPOabcd": "abcd",
            "rR0ab": "0ab",
        }

        errmsg = "get_hash_from_diffusion_iden failed with string %s"
        for term in identifiers:
            expected = identifiers[term]
            observed = phabricator_utils.get_hash_from_diffusion_iden(term)
            assert expected == observed, errmsg % term
Пример #3
0
    def test_get_hash(self):
        identifiers = {
            "rREPOabcd": "abcd",
            "rR0ab": "0ab",
        }

        errmsg = "get_hash_from_diffusion_iden failed with string %s"
        for term in identifiers:
            expected = identifiers[term]
            observed = phabricator_utils.get_hash_from_diffusion_iden(term)
            assert expected == observed, errmsg % term