How to use the stashy.helpers.IterableResource 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
    @response_or_error
    def settings(self):
        """
        Retrieve the settings for a repository webhook
        """
        return self._client.get(self.url("/settings"))

    @response_or_error
    def configure(self, configuration):
        """
        Modify the settings for a repository webhook
        """
        return self._client.put(self.url("/settings"), data=configuration)


class Webhooks(ResourceBase, IterableResource):
    def all(self, type=None):
        """
        Retrieve webhooks for this repository, optionally filtered by type.

        type: Valid values are PRE_RECEIVE or POST_RECEIVE
        """
        params = None
        if type is not None:
            params = dict(type=type)
        return self.paginate("", params=params)

    @response_or_error
    def create(self, name, url, events=["repo:refs_changed"], active=True):
        """
        Create a webhook with the given name and url
        """
github cosmin / stashy / stashy / pullrequests.py View on Github external
if parentCommentId is not -1:
            data['parent'] = dict(id=parentCommentId)
        elif srcPath is not None:
            data['anchor'] = dict(path=srcPath, srcPath=srcPath)
            if fileLine is not -1:
                data['anchor'].update(dict(line=fileLine, lineType=lineType, fileType=fileType))
        return self._client.post(self.url("/comments"), data=data)

    def diff(self):
        """
        Retrieve the diff for the specified pull request.
        """
        return PullRequestDiff(self.url('/diff'), self._client, self)


class PullRequests(ResourceBase, IterableResource):
    def __init__(self, url, client, parent):
        super(PullRequests, self).__init__(url, client, parent)

    def all(self, direction='INCOMING', at=None, state='OPEN', order=None, author=None):
        """
        Retrieve pull requests to or from the specified repository.

        direction: (optional, defaults to INCOMING) the direction relative to the specified repository.
            Either INCOMING or OUTGOING.
        at: (optional) a specific branch to find pull requests to or from.
        state: (optional, defaults to OPEN) only pull requests in the specified state will be returned.
            Either OPEN, DECLINED or MERGED.
        order: (optional) the order to return pull requests in, either OLDEST (as in: "oldest first") or NEWEST.
        """

        params = {}
github cosmin / stashy / stashy / branch_permissions.py View on Github external
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)


class Restrictions(ResourceBase, IterableResource):

    def __init__(self, url, client, parent):
        ResourceBase.__init__(self, url, client, parent, API_OVERRIDE_PATH)

    def __getitem__(self, item):
        return Restriction(item, self.url(item), self._client, self)

    @response_or_error
    def create(self, match, users=None, groups=None, keys=None,
               restriction_type=RestrictionType.READ_ONLY,
               matcher_type=Matcher.PATTERN):
        """
        Restrict a branch, or set of branches defined by a pattern,
        to a set of users, groups, and access keys.
        Note: access keys need to be specified by their numerical id. labels are
        not accepted.
github cosmin / stashy / stashy / helpers.py View on Github external
return self.all()

    def all(self):
        """
        Retrieve all the resources.
        """
        return self.paginate("")

    def list(self):
        """
        Convenience method to return a list (rather than iterable) of all elements
        """
        return list(self.all())


class FilteredIterableResource(IterableResource):
    def all(self, filter=None):
        """
        Retrieve all the resources, optionally modified by filter.
        """
        params = {}
        if filter:
            params['filter'] = filter
        return self.paginate("", params)

    def list(self, filter=None):
        """
        Convenience method to return a list (rather than iterable) of all elements
        """
        return list(self.all(filter))
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"))

    @response_or_error
    def configure(self, configuration):
        """
        Modify the settings for a repository hook
        """
        return self._client.put(self.url("/settings"), data=configuration)


class Hooks(ResourceBase, IterableResource):
    def all(self, type=None):
        """
        Retrieve hooks for this repository, optionally filtered by type.

        type: Valid values are PRE_RECEIVE or POST_RECEIVE
        """
        params=None
        if type is not None:
            params = dict(type=type)
        return self.paginate("", params=params)

    def list(self, type=None):
        """
        Convenience method to return a list (rather than iterable) of all elements
        """
        return list(self.all(type=type))
github cosmin / stashy / stashy / ssh.py View on Github external
# from .helpers import Nested, ResourceBase, IterableResource
from .helpers import ResourceBase, IterableResource
from .errors import ok_or_error, response_or_error
from .compat import update_doc


class SshFilteredIterableResource(IterableResource):
    def all(self, user=None):
        """
        Retrieve all the resources, optionally modified by filter.
        """
        params = {}
        if user:
            params['user'] = user
        return self.paginate("", params)

    def list(self, user=None):
        """
        Convenience method to return a list (rather than iterable) of all
        elements
        """
        return list(self.all(user))
github cosmin / stashy / stashy / repos.py View on Github external
"""
        return self._client.get(self.url())

    @ok_or_error
    def _set_forkable(self, value):
        """
        Args:
            value (bool): True if repo should be forkable, False otherwise
        Returns:
            Sets value of forkable to given argument
        """
        return self._client.put(self.url(), data=dict(forkable=value))

    forkable = property(_get_forkable, _set_forkable, doc="Get or set the allow_forks option")

class Repos(ResourceBase, IterableResource):
    @response_or_error
    def create(self, name, scmId="git", forkable=True):
        """
        Create a repository with the given name
        """
        return self._client.post(self.url(), data={"name": name,
                                                   "scmId": scmId,
                                                   "forkable": forkable,
                                                   })

    def __getitem__(self, item):
        """
        Return a :class:`Repository` object for operations on a specific repository
        """
        return Repository(item, self.url(item), self._client, self)
github cosmin / stashy / stashy / projects.py View on Github external
    @ok_or_error
    def add_key(self, key_text, permission):
        return self._client.post(self.url('/ssh', is_keys=True),
                                 data=dict(key=dict(text=key_text),
                                           permission=permission))


    permissions = Nested(ProjectPermissions, relative_path="/permissions")
    repos = Nested(Repos)
    settings = Nested(Settings)
    branch_permissions = Nested(BranchPermissions, relative_path=None)
    default_reviewers = Nested(DefaultReviewers, relative_path=None)


class Projects(ResourceBase, IterableResource):
    @response_or_error
    def get(self, project):
        """
        Retrieve the project matching the supplied key.
        """
        return self._client.get(self.url(project))

    def __getitem__(self, item):
        return Project(item, self.url(item), self._client, self)

    @response_or_error
    def create(self, key, name, description='', avatar=None):
        """
        Create a project. If supplied, avatar should be a base64 encoded image.
        """
        data = dict(key=key, name=name, description=description)