Esempio n. 1
0
# -*- coding: utf-8 -*-
"""
Defines the PullRequest resource and registers the type with the Client.

Classes:
- PullRequestState: enumerates the possible states of a pull request
- PullRequest: represents a pull request for code review
"""
from functools import partial
from uritemplate import expand

from pybitbucket.bitbucket import Bitbucket, BitbucketBase, Client, enum

PullRequestState = enum('PullRequestState',
                        OPEN='open',
                        MERGED='merged',
                        DECLINED='declined')


class PullRequest(BitbucketBase):
    id_attribute = 'id'
    resource_type = 'pullrequests'

    @staticmethod
    def is_type(data):
        return (PullRequest.has_v2_self_url(data))

    def __init__(self, data, client=Client()):
        super(PullRequest, self).__init__(data, client=client)
        if data.get('source', {}).get('commit', {}):
            self.source_commit = client.convert_to_object(
Esempio n. 2
0
"""
Provides a class for manipulating Team resources on Bitbucket.
"""
from pybitbucket.bitbucket import Bitbucket, BitbucketBase, Client, enum

TeamRole = enum('TeamRole',
                ADMIN='admin',
                CONTRIBUTOR='contributor',
                MEMBER='member')


class Team(BitbucketBase):
    id_attribute = 'username'
    resource_type = 'teams'

    @staticmethod
    def is_type(data):
        return (Team.has_v2_self_url(data))

    """
    A convenience method for finding teams by the user's role.
    The method is a generator Team objects.
    """

    @staticmethod
    def find_teams_for_role(role=TeamRole.ADMIN, client=Client()):
        TeamRole.expect_valid_value(role)
        return Bitbucket(client=client).teamsForRole(role=role)

    """
    A convenience method for finding a specific team.
Esempio n. 3
0
"""
Defines the PullRequest resource and registers the type with the Client.

Classes:
- PullRequestState: enumerates the possible states of a pull request
- PullRequest: represents a pull request for code review
"""
from functools import partial
from uritemplate import expand

from pybitbucket.bitbucket import Bitbucket, BitbucketBase, Client, enum


PullRequestState = enum(
    'PullRequestState',
    OPEN='OPEN',
    MERGED='MERGED',
    DECLINED='DECLINED')


class PullRequest(BitbucketBase):
    id_attribute = 'id'
    resource_type = 'pullrequests'

    @staticmethod
    def is_type(data):
        return (PullRequest.has_v2_self_url(data))

    def __init__(self, data, client=Client()):
        super(PullRequest, self).__init__(data, client=client)
        if data.get('source', {}).get('commit', {}):
Esempio n. 4
0
# -*- coding: utf-8 -*-
"""
Defines the BuildStatus resource and registers the type with the Client.

Classes:
- BuildStatusStates: enumerates the possible states of a build status
- BuildStatus: represents the result of a build
"""
from uritemplate import expand

from pybitbucket.bitbucket import Bitbucket, BitbucketBase, Client, enum

BuildStatusStates = enum('BuildStatusStates',
                         INPROGRESS='INPROGRESS',
                         SUCCESSFUL='SUCCESSFUL',
                         FAILED='FAILED')


class BuildStatus(BitbucketBase):
    id_attribute = 'key'
    resource_type = 'build'

    @staticmethod
    def is_type(data):
        return (BuildStatus.has_v2_self_url(data))

    @staticmethod
    def make_payload(key, state, url, name=None, description=None):
        BuildStatusStates.expect_valid_value(state)
        payload = {
            'key': key,
# -*- coding: utf-8 -*-
"""
Defines the BranchRestriction resource and registers the type with the Client.

Classes:
- BranchRestriction: represents a restriction on a branch for a repository.
"""
from uritemplate import expand
from pybitbucket.bitbucket import Bitbucket, BitbucketBase, Client, enum

BranchRestrictionKind = enum('BranchRestrictionKind',
                             PUSH='push',
                             DELETE='delete',
                             FORCE='force')


class BranchRestriction(BitbucketBase):
    id_attribute = 'id'
    resource_type = 'branch-restrictions'

    @staticmethod
    def is_type(data):
        return (BranchRestriction.has_v2_self_url(data))

    @staticmethod
    def payload(kind=None, pattern=None, groups=None, users=None):
        payload = {}
        # Since server defaults may change, method defaults are None.
        # If the parameters are not provided, then don't send them
        # so the server can decide what defaults to use.
        if kind is not None:
Esempio n. 6
0
# -*- coding: utf-8 -*-
from uritemplate import expand

from pybitbucket.bitbucket import BitbucketBase, Client, enum

PermissionScope = enum('PermissionScope',
                       EMAIL='email',
                       ACCOUNT_READ='account',
                       ACCOUNT_WRITE='account:write',
                       TEAM_READ='team',
                       TEAM_WRITE='team:write',
                       REPOSITORY_READ='repository',
                       REPOSITORY_WRITE='repository:write',
                       REPOSITORY_ADMIN='repository:admin',
                       PULLREQUEST_READ='pullrequest',
                       PULLREQUEST_WRITE='pullrequest:write',
                       ISSUE_READ='issue',
                       ISSUE_WRITE='issue:write',
                       WIKI='wiki',
                       SNIPPET_READ='snippet',
                       SNIPPET_WRITE='snippet:write',
                       WEBHOOK='webhook')


class Consumer(BitbucketBase):
    id_attribute = 'id'
    links_json = """
{
  "_links": {
    "self": {
      "href": "{+bitbucket_url}/1.0/users{/username}/consumers{/consumer_id}"
Esempio n. 7
0
Provides classes for manipulating Snippet resources.
"""
from uritemplate import expand

from pybitbucket.bitbucket import Bitbucket, BitbucketBase, Client, enum


def open_files(filelist):
    files = []
    for filename in filelist:
        files.append(('file', (filename, open(filename, 'rb'))))
    return files


SnippetRole = enum('SnippetRole',
                   OWNER='owner',
                   CONTRIBUTOR='contributor',
                   MEMBER='member')


class Snippet(BitbucketBase):
    id_attribute = 'id'
    resource_type = 'snippets'

    @staticmethod
    def is_type(data):
        # Snippet URLs look like this:
        # https://api.bitbucket.org/2.0/snippets/pybitbucket/Xqoz8
        # Which doesn't follow the pattern of:
        # resource_type/id_attribute
        # So we can't use `has_v2_self_url` to categorize.
        if ((data.get('links') is None) or (data['links'].get('self') is None)
Esempio n. 8
0
"""
Provides a class for manipulating Repository resources on Bitbucket.
"""
from uritemplate import expand

from pybitbucket.bitbucket import Bitbucket, BitbucketBase, Client, enum
from pybitbucket.user import User

RepositoryRole = enum('RepositoryRole',
                      OWNER='owner',
                      ADMIN='admin',
                      CONTRIBUTOR='contributor',
                      MEMBER='member')

RepositoryForkPolicy = enum('RepositoryForkPolicy',
                            ALLOW_FORKS='allow_forks',
                            NO_PUBLIC_FORKS='no_public_forks',
                            NO_FORKS='no_forks')

RepositoryType = enum('RepositoryType', GIT='git', HG='hg')


class Repository(BitbucketBase):
    id_attribute = 'full_name'
    resource_type = 'repositories'
    templates = {
        'create': '{+bitbucket_url}/2.0/repositories{/owner,repository_name}'
    }

    @staticmethod
    def is_type(data):