Пример #1
0
 def test_git(self):
     repo = Repository(
         url='http://example.com/git-repo',
         backend=RepositoryBackend.git,
     )
     result = repo.get_vcs()
     assert type(result) == GitVcs
Пример #2
0
 def test_unknown(self):
     repo = Repository(
         url='http://example.com/git-repo',
         backend=RepositoryBackend.unknown,
     )
     result = repo.get_vcs()
     assert result is None
Пример #3
0
 def test_hg(self):
     repo = Repository(
         url='http://example.com/git-repo',
         backend=RepositoryBackend.hg,
     )
     result = repo.get_vcs()
     assert type(result) == MercurialVcs
Пример #4
0
    def post(self):
        user = get_current_user()
        if user is None:
            return error('Not logged in.', http_code=401)
        args = self.post_parser.parse_args()

        slug = str(args.slug or args.name.replace(' ', '-').lower())

        if not user_has_project_permission(user, slug):
            return error(
                'User does not have permission to create a project with slug {}.'
                .format(slug),
                http_code=403)

        match = Project.query.filter(Project.slug == slug, ).first()
        if match:
            return error('Project with slug {} already exists.'.format(slug),
                         http_code=400)

        repository = Repository.get(args.repository)
        if repository is None:
            return error('Repository with url {} does not exist.'.format(
                args.repository),
                         http_code=400)

        project = Project(
            name=args.name,
            slug=slug,
            repository=repository,
        )
        db.session.add(project)
        db.session.commit()

        return self.respond(project)
Пример #5
0
    def post(self):
        user = get_current_user()
        if user is None:
            return error('Not logged in.', http_code=401)
        args = self.post_parser.parse_args()

        slug = str(args.slug or args.name.replace(' ', '-').lower())

        if not user_has_project_permission(user, slug):
            return error('User does not have permission to create a project with slug {}.'.format(slug), http_code=403)

        match = Project.query.filter(
            Project.slug == slug,
        ).first()
        if match:
            return error('Project with slug {} already exists.'.format(slug), http_code=400)

        repository = Repository.get(args.repository)
        if repository is None:
            return error('Repository with url {} does not exist.'.format(args.repository), http_code=400)

        project = Project(
            name=args.name,
            slug=slug,
            repository=repository,
        )
        db.session.add(project)
        db.session.commit()

        return self.respond(project)
Пример #6
0
    def create_repo(self, **kwargs):
        kwargs.setdefault('url', 'http://example.com/{0}'.format(uuid4().hex))
        kwargs.setdefault('status', RepositoryStatus.active)

        repo = Repository(**kwargs)
        db.session.add(repo)
        db.session.commit()

        return repo
Пример #7
0
def repository(**kwargs):
    if 'url' not in kwargs:
        kwargs['url'] = 'https://github.com/example-{0}/example.git'.format(
            random.randint(1, 100000))

    try:
        result = Repository.query.filter_by(url=kwargs['url'])[0]
    except IndexError:
        result = Repository(**kwargs)
        db.session.add(result)
    return result
Пример #8
0
    def post(self, project_id):
        project = Project.get(project_id)
        if project is None:
            return '', 404

        args = self.post_parser.parse_args()

        if args.name:
            project.name = args.name

        if args.slug:
            match = Project.query.filter(
                Project.slug == args.slug,
                Project.id != project.id,
            ).first()
            if match:
                return '{"error": "Project with slug %r already exists"}' % (
                    args.slug, ), 400

            project.slug = args.slug

        if args.repository:
            repository = Repository.get(args.repository)
            if repository is None:
                return '{"error": "Repository with url %r does not exist"}' % (
                    args.repository, ), 400
            project.repository = repository

        if args.status == 'inactive':
            project.status = ProjectStatus.inactive
        elif args.status == 'active':
            project.status = ProjectStatus.active

        db.session.add(project)

        data = self.serialize(project)
        data['repository'] = self.serialize(project.repository)

        return self.respond(data, serialize=False)
Пример #9
0
    def post(self):
        args = self.post_parser.parse_args()

        match = Repository.query.filter(Repository.url == args.url, ).first()
        if match:
            return '{"error": "Repository with url %r already exists"}' % (
                args.url, ), 400

        repo = Repository(
            url=args.url,
            backend=RepositoryBackend[args.backend],
            status=RepositoryStatus.importing,
        )
        db.session.add(repo)
        db.session.commit()

        import_repo.delay(
            repo_id=repo.id.hex,
            task_id=repo.id.hex,
        )

        return self.respond(repo)
Пример #10
0
    def post(self, project_id):
        project = Project.get(project_id)
        if project is None:
            return '', 404

        args = self.post_parser.parse_args()

        if args.name:
            project.name = args.name

        if args.slug:
            match = Project.query.filter(
                Project.slug == args.slug,
                Project.id != project.id,
            ).first()
            if match:
                return '{"error": "Project with slug %r already exists"}' % (args.slug,), 400

            project.slug = args.slug

        if args.repository:
            repository = Repository.get(args.repository)
            if repository is None:
                return '{"error": "Repository with url %r does not exist"}' % (args.repository,), 400
            project.repository = repository

        if args.status == 'inactive':
            project.status = ProjectStatus.inactive
        elif args.status == 'active':
            project.status = ProjectStatus.active

        db.session.add(project)

        data = self.serialize(project)
        data['repository'] = self.serialize(project.repository)

        return self.respond(data, serialize=False)
Пример #11
0
    def post(self):
        args = self.post_parser.parse_args()

        slug = str(args.slug or args.name.replace(' ', '-').lower())

        match = Project.query.filter(
            Project.slug == slug,
        ).first()
        if match:
            return '{"error": "Project with slug %r already exists"}' % (slug,), 400

        repository = Repository.get(args.repository)
        if repository is None:
            return '{"error": "Repository with url %r does not exist"}' % (args.repository,), 400

        project = Project(
            name=args.name,
            slug=slug,
            repository=repository,
        )
        db.session.add(project)
        db.session.commit()

        return self.respond(project)
Пример #12
0
 def _create_repository(self):
     return Repository(
         url='http://example.com/git-repo',
         backend=RepositoryBackend.git,
     )