Skip to content

refs

Branch

Bases: Ref

Bitbucket Cloud branch endpoint.

See https://developer.atlassian.com/cloud/bitbucket/rest/api-group-refs/#api-repositories-workspace-repo-slug-refs-branches-name-get

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/refs.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
class Branch(Ref):
    """
    Bitbucket Cloud branch endpoint.

    See https://developer.atlassian.com/cloud/bitbucket/rest/api-group-refs/#api-repositories-workspace-repo-slug-refs-branches-name-get
    """

    def __init__(self, data, *args, **kwargs):
        """See BitbucketCloudBase."""
        super(Branch, self).__init__(None, *args, data=data, expected_type="branch", **kwargs)

    @property
    def author(self):
        """User object of the author."""
        return User(None, self.get_data("author"))

author property

User object of the author.

__init__(data, *args, **kwargs)

See BitbucketCloudBase.

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/refs.py
112
113
114
def __init__(self, data, *args, **kwargs):
    """See BitbucketCloudBase."""
    super(Branch, self).__init__(None, *args, data=data, expected_type="branch", **kwargs)

Branches

Bases: Refs

BitBucket Cloud branches endpoint.

See https://developer.atlassian.com/cloud/bitbucket/rest/api-group-refs/#api-repositories-workspace-repo-slug-refs-branches-get

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/refs.py
67
68
69
70
71
72
73
74
75
class Branches(Refs):
    """
    BitBucket Cloud branches endpoint.

    See https://developer.atlassian.com/cloud/bitbucket/rest/api-group-refs/#api-repositories-workspace-repo-slug-refs-branches-get
    """

    def _get_object(self, data):
        return Branch(data, **self._new_session_args)

Ref

Bases: BitbucketCloudBase

Base object for individual refs.

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/refs.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
class Ref(BitbucketCloudBase):
    """
    Base object for individual refs.
    """

    @property
    def name(self):
        """Ref name."""
        return self.get_data("name")

    @property
    def hash(self):
        """Commit hash."""
        return self.get_data("target")["hash"]

hash property

Commit hash.

name property

Ref name.

Refs

Bases: BitbucketCloudBase

Bitbucket Cloud Refs.

Generic base object for any type of ref list.

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/refs.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class Refs(BitbucketCloudBase):
    """
    Bitbucket Cloud Refs.

    Generic base object for any type of ref list.
    """

    def __init__(self, url, *args, **kwargs):
        """See BitbucketCloudBase."""
        super(Refs, self).__init__(url, *args, **kwargs)

    def create(
        self,
        name,
        commit,
    ):
        """
        Creates a ref with the given target commit
        :param name: string: name
        :param commit: string: commit hash

        :return: Ref
        """

        data = {"name": name, "target": {"hash": commit}}

        return self._get_object(self.post(None, data))

    def each(self, q=None, sort=None):
        """
        Returns the list of refs in this repository.

        :param q: string: Query string to narrow down the response.
                          See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
        :param sort: string: Name of a response property to sort results.
                             See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.

        :return: A generator for the Ref objects
        """
        params = {}
        if sort is not None:
            params["sort"] = sort
        if q is not None:
            params["q"] = q
        for ref in self._get_paged(None, trailing=True, params=params):
            yield self._get_object(super(Refs, self).get(ref.get("name")))

        return

    def get(self, name):
        """
        Returns the Ref with the requested name in the repository.

        :param name: string: The requested name

        :return: The requested Ref object
        """
        return self._get_object(super(Refs, self).get(name))

__init__(url, *args, **kwargs)

See BitbucketCloudBase.

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/refs.py
14
15
16
def __init__(self, url, *args, **kwargs):
    """See BitbucketCloudBase."""
    super(Refs, self).__init__(url, *args, **kwargs)

create(name, commit)

Creates a ref with the given target commit :param name: string: name :param commit: string: commit hash

:return: Ref

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/refs.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def create(
    self,
    name,
    commit,
):
    """
    Creates a ref with the given target commit
    :param name: string: name
    :param commit: string: commit hash

    :return: Ref
    """

    data = {"name": name, "target": {"hash": commit}}

    return self._get_object(self.post(None, data))

each(q=None, sort=None)

Returns the list of refs in this repository.

:param q: string: Query string to narrow down the response. See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details. :param sort: string: Name of a response property to sort results. See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.

:return: A generator for the Ref objects

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/refs.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def each(self, q=None, sort=None):
    """
    Returns the list of refs in this repository.

    :param q: string: Query string to narrow down the response.
                      See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
    :param sort: string: Name of a response property to sort results.
                         See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.

    :return: A generator for the Ref objects
    """
    params = {}
    if sort is not None:
        params["sort"] = sort
    if q is not None:
        params["q"] = q
    for ref in self._get_paged(None, trailing=True, params=params):
        yield self._get_object(super(Refs, self).get(ref.get("name")))

    return

get(name)

Returns the Ref with the requested name in the repository.

:param name: string: The requested name

:return: The requested Ref object

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/refs.py
56
57
58
59
60
61
62
63
64
def get(self, name):
    """
    Returns the Ref with the requested name in the repository.

    :param name: string: The requested name

    :return: The requested Ref object
    """
    return self._get_object(super(Refs, self).get(name))

Tag

Bases: Ref

Bitbucket Cloud tags endpoint.

See https://developer.atlassian.com/cloud/bitbucket/rest/api-group-refs/#api-repositories-workspace-repo-slug-refs-tags-name-get

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/refs.py
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
class Tag(Ref):
    """
    Bitbucket Cloud tags endpoint.

    See https://developer.atlassian.com/cloud/bitbucket/rest/api-group-refs/#api-repositories-workspace-repo-slug-refs-tags-name-get
    """

    def __init__(self, data, *args, **kwargs):
        """See BitbucketCloudBase."""
        super(Tag, self).__init__(None, *args, data=data, expected_type="tag", **kwargs)

    @property
    def author(self):
        """User object of the author."""
        return User(None, self.get_data("tagger"))

author property

User object of the author.

__init__(data, *args, **kwargs)

See BitbucketCloudBase.

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/refs.py
129
130
131
def __init__(self, data, *args, **kwargs):
    """See BitbucketCloudBase."""
    super(Tag, self).__init__(None, *args, data=data, expected_type="tag", **kwargs)

Tags

Bases: Refs

BitBucket Cloud tags endpoint.

See https://developer.atlassian.com/cloud/bitbucket/rest/api-group-refs/#api-repositories-workspace-repo-slug-refs-tags-get

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/refs.py
78
79
80
81
82
83
84
85
86
class Tags(Refs):
    """
    BitBucket Cloud tags endpoint.

    See https://developer.atlassian.com/cloud/bitbucket/rest/api-group-refs/#api-repositories-workspace-repo-slug-refs-tags-get
    """

    def _get_object(self, data):
        return Tag(data, **self._new_session_args)