How to use the stashy.errors.response_or_error function in stashy

To help you get started, we’ve selected a few stashy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cosmin / stashy / stashy / repos.py View on Github external
def browse(self, path='', at=None, type=False, blame='', noContent=''):
        """
        Retrieve a page of content for a file path at a specified revision.
        """
        params = {}
        if at is not None:
            params['at'] = at
        if type:
            params['type'] = type
            return response_or_error(lambda: self._client.get(self.url('/browse/' + path), params=params))()
        else:
            if blame:
                params['blame'] = blame
            if noContent:
                params['noContent'] = noContent

            return self.paginate("/browse/" + path, params=params, values_key='lines')
github cosmin / stashy / stashy / repos.py View on Github external
    @response_or_error
    def get(self):
        """
        Retrieve the repository
        """
        return self._client.get(self.url())
github cosmin / stashy / stashy / pullrequests.py View on Github external
    @response_or_error
    def approve(self):
        """
        Approve a pull request as the current user. Implicitly adds the user as a participant if they are not already.
        """
        data = dict(approved=True, status="approved")
        return self._client.put(self.url("/participants/%s/" % self._client._session.auth[0]), data=data)
github cosmin / stashy / stashy / pullrequests.py View on Github external
    @response_or_error
    def create(self, title, fromRef, toRef, description='', state='OPEN', reviewers=None):
        """
        Create a new pull request between two branches.
        """
        data = dict(title=title,
                    description=description,
                    fromRef=self._make_ref(fromRef, "fromRef"),
                    toRef=self._make_ref(toRef, "toRef"),
                    state=state)

        if reviewers is not None:
            data['reviewers'] = []
            for reviewer in reviewers:
                data['reviewers'].append({"user": dict(name=reviewer)})

        return self._client.post(self.url(""), data=data)
github cosmin / stashy / stashy / ssh.py View on Github external
    @response_or_error
    def get(self, user):
        """
        Retrieve the keys matching the supplied user.
        """
        params = dict(user=user)
        return self._client.get(self.url(""), params=params)
github cosmin / stashy / stashy / repos.py View on Github external
    @response_or_error
    def _get_forkable(self):
        """
        Args:
            N/A
        Returns:
            (bool): True if repo is forkable, False if it is not forkable
        """
        return self._client.get(self.url())
github cosmin / stashy / stashy / repos.py View on Github external
    @response_or_error
    def move(self, newProject):
        """
        Move the repository to the given project
        """
        return self._client.put(self.url(), data=dict(project=dict(key=newProject)))
github cosmin / stashy / stashy / branch_permissions.py View on Github external
    @response_or_error
    def update(self, match, users=None, groups=None, keys=None,
               restriction_type=RestrictionType.READ_ONLY,
               matcher_type=Matcher.PATTERN):
        """
        Re-restrict a branch, or set of branches defined by a pattern,
        to a set of users, groups, and access keys.
        Warning: The REST API does not actually support a direct update of
        branch permissions. The Restriction will be deleted and recreated instead.
        Note: access keys need to be specified by their numerical id. labels are
        not accepted.
        """
        data = self.request_data(match, users, groups, keys, restriction_type,
                                 matcher_type)
        self.delete()
        return self._client.post(self._parent.url(), data=data)
github cosmin / stashy / stashy / pullrequests.py View on Github external
    @response_or_error
    def unwatch(self):
        """
        Remove the current user as a watcher for the pull request.
        """
        return self._client.delete(self.url("/watch"))
github cosmin / stashy / stashy / projects.py View on Github external
    @response_or_error
    def settings(self):
        """
        Retrieve the settings for a repository hook
        """
        return self._client.get(self.url("/settings"))