Exemple #1
0
    def collection_post(self):
        """Initialise a new git repository, or clone from an existing repo."""
        repo_path = extract_json_data(self.request).get("repo_path")
        clone_path = extract_json_data(self.request).get("clone_from")
        clone_refs = extract_json_data(self.request).get("clone_refs", False)

        if not repo_path:
            self.request.errors.add("body", "repo_path", "repo_path is missing")
            return
        repo = os.path.join(self.repo_store, repo_path)
        if not is_valid_path(self.repo_store, repo):
            self.request.errors.add("body", "name", "invalid path.")
            raise exc.HTTPNotFound()

        if clone_path:
            repo_clone = os.path.join(self.repo_store, clone_path)
        else:
            repo_clone = None

        try:
            new_repo_path = store.init_repo(repo, clone_from=repo_clone, clone_refs=clone_refs)
            repo_name = os.path.basename(os.path.normpath(new_repo_path))
            return {"repo_url": "/".join([self.request.url, repo_name])}
        except GitError:
            return exc.HTTPConflict()  # 409
Exemple #2
0
 def collection_post(self, repo_store, repo_name):
     """Get commits in bulk."""
     commits = extract_json_data(self.request).get("commits")
     try:
         commits = store.get_commits(repo_store, repo_name, commits)
     except GitError:
         return exc.HTTPNotFound()
     return commits
Exemple #3
0
 def patch(self, repo_store, repo_name):
     """Change properties of an existing git repository."""
     repo_path = os.path.join(repo_store, repo_name)
     if not os.path.exists(repo_path):
         self.request.errors.add("body", "name", "repository does not exist")
         raise exc.HTTPNotFound()
     data = extract_json_data(self.request)
     for key in data:
         if not hasattr(self, "_patch_%s" % key):
             self.request.errors.add("body", key, "unknown property")
             raise exc.HTTPBadRequest()
     for key, value in data.items():
         getattr(self, "_patch_%s" % key)(repo_path, value)
     return exc.HTTPNoContent()
Exemple #4
0
    def post(self, repo_store, repo_name):
        """Check whether each of the requested commits has been merged.

        The JSON request dictionary should contain a 'sources' key whose
        value is a list of source commit OIDs.  The response is a dictionary
        mapping merged source commit OIDs to the first commit OID in the
        left-hand (first parent only) history of the target commit that is a
        descendant of the corresponding source commit.  Unmerged commits are
        omitted from the response.
        """
        target = self.request.matchdict["target"]
        sources = extract_json_data(self.request).get("sources")
        try:
            merges = store.detect_merges(repo_store, repo_name, target, sources)
        except GitError:
            return exc.HTTPNotFound()
        return merges
Exemple #5
0
    def post(self, repo_store, repo_name):
        repo_path = os.path.join(repo_store, repo_name)

        data = extract_json_data(self.request)
        ignore_alternates = data.get("ignore_alternates")
        no_reuse_delta = data.get("no_reuse_delta")
        prune = data.get("prune")
        single = data.get("single")
        window = data.get("window")
        depth = data.get("depth")

        try:
            store.repack(
                repo_path,
                single=single,
                prune=prune,
                no_reuse_delta=no_reuse_delta,
                ignore_alternates=ignore_alternates,
                window=window,
                depth=depth,
            )
        except (CalledProcessError):
            return exc.HTTPInternalServerError()
        return
Exemple #6
0
 def test_extract_json_data_is_deprecated(self):
     with mock.patch('cornice.util.warnings') as mocked:
         util.extract_json_data(mock.MagicMock())
         self.assertTrue(mocked.warn.called)
Exemple #7
0
 def test_extract_json_data_is_deprecated(self):
     with mock.patch('cornice.util.warnings') as mocked:
         util.extract_json_data(mock.MagicMock())
         self.assertTrue(mocked.warn.called)