How to use the stashy.helpers.ResourceBase 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
import json

from .branch_permissions import BranchPermissions
from .compat import update_doc
from .errors import ok_or_error, response_or_error
from .helpers import Nested, ResourceBase, IterableResource
from .permissions import Permissions, RepositoryPermissions
from .pullrequests import PullRequests
from .settings import Settings


class Webhook(ResourceBase):
    def __init__(self, key, url, client, parent):
        super(Webhook, self).__init__(url, client, parent)
        self._key = key

    @response_or_error
    def get(self):
        """
        Retrieve a repository webhook
        """
        return self._client.get(self.url())

    @response_or_error
    def enable(self, configuration=None):
        """
        Enable a repository webhook, optionally applying new configuration.
        """
github cosmin / stashy / stashy / branch_permissions.py View on Github external
"""Valid values for the matcher_type for Restriction create/update"""
    PATTERN = 'PATTERN'
    BRANCH = 'BRANCH'
    MODEL_CATEGORY = 'MODEL_CATEGORY'
    MODEL_BRANCH = 'MODEL_BRANCH'


class RestrictionType(Enum):
    """Valid values for the restriction_type for Restriction create/update"""
    PULL_REQUEST = 'pull-request-only'
    FAST_FORWARD = 'fast-forward-only'
    NO_DELETES = 'no-deletes'
    READ_ONLY = 'read-only'


class Restriction(ResourceBase):
    def __init__(self, id, url, client, parent):
        super(Restriction, self).__init__(url, client, parent, API_OVERRIDE_PATH)
        self._id = id

    @response_or_error
    def get(self):
        """
        Retrieve a restriction
        """
        return self._client.get(self.url())

    @ok_or_error
    def delete(self):
        """
        Delete a restriction
        """
github cosmin / stashy / stashy / branch_permissions.py View on Github external
"""
        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.
        """
        data = Restriction.request_data(match, users, groups, keys,
                                        restriction_type, matcher_type)

        return self._client.post(self.url(""), data=data)


update_doc(Restrictions.all, """Retrieve list of restrictions for a repo""")


class BranchPermissions(ResourceBase):
    """Simple parent resource for this api, to distinguish restrictions from anything else"""
    restrictions = Nested(Restrictions)
github cosmin / stashy / stashy / projects.py View on Github external
"""
        Convenience method to return a list (rather than iterable) of all elements
        """
        return list(self.all(type=type))

    def __getitem__(self, item):
        """
        Return a :class:`Hook` object for operations on a specific hook
        """
        return Hook(item, self.url(item), self._client, self)


class Settings(ResourceBase):
    hooks = Nested(Hooks)

class Project(ResourceBase):
    def __init__(self, key, url, client, parent):
        super(Project, self).__init__(url, client, parent)
        self._key = key

    @ok_or_error
    def delete(self):
        """
        Delete the project
        """
        return self._client.delete(self.url())

    @response_or_error
    def update(self, new_key=None, name=None, description=None, avatar=None, public=None):
        """
        Update project information. If supplied, avatar should be a base64 encoded image.