Skip to content

commits

Commit

Bases: BitbucketCloudBase

Bitbucket Cloud commit endpoint.

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

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/commits.py
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
class Commit(BitbucketCloudBase):
    """
    Bitbucket Cloud commit endpoint.

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

    def __init__(self, data, *args, **kwargs):
        super(Commit, self).__init__(None, *args, data=data, expected_type="commit", **kwargs)

    @property
    def hash(self):
        """Commit id."""
        return self.get_data("hash")

    @property
    def message(self):
        """Commit message."""
        return self.get_data("message")

    @property
    def date(self):
        """Commit date."""
        return self.get_time("date")

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

    def parents(self):
        """Return a generator object of parent commits."""
        for commit in self.get_data("parents"):
            yield Commit(commit, **self._new_session_args)

    def statuses(self):
        """
        Return generator object of the status's endpoint.
        API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commit-statuses/#api-repositories-workspace-repo-slug-commit-commit-statuses-get
        """
        return self._get_paged("statuses")

    def participants(self):
        """Return a generator object of participants."""
        for participant in self.get_data("participants"):
            yield Participant(participant, **self._new_session_args)

    def builds(self):
        """Return the Build objects for the commit."""
        builds = [b for b in self.statuses() if b["type"] == "build"]
        for build in builds:
            yield Build(build, **self._new_session_args)

    def add_build(
        self,
        key,
        url=None,
        description=None,
        refname=None,
        state=Build.STATE_INPROGRESS,
    ):
        """
        Add new build status to commit.

        API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commit-statuses/#api-repositories-workspace-repo-slug-commit-commit-statuses-build-post
        """
        data = {
            "key": key,
            "state": state,
            "description": description,
            "url": url,
            "refname": refname,
        }

        return self.post("statuses/build", data)

    def get_build(self, key):
        """
        Return a specific build for the commit.

        API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commit-statuses/#api-repositories-workspace-repo-slug-commit-commit-statuses-build-key-get
        """
        return Build(
            super(Commit, self).get(self.url_joiner("statuses/build", key)),
            **self._new_session_args
        )  # fmt: skip

    def comments(self):
        """
        Return generator object endpoint of the comment.
        API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-comments-get
        """
        for comment in self._get_paged("comments"):
            yield Comment(comment, **self._new_session_args)

    def comment(self, raw_message):
        """
        Add a comment to the pull request in raw format.

        API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-comments-post
        """
        if not raw_message:
            raise ValueError("No message set")

        data = {
            "content": {
                "raw": raw_message,
            }
        }

        return self.post("comments", data)

    def approve(self):
        """
        Approve a commit.

        API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-approve-post
        """
        data = {"approved": True}
        return self.post("approve", data)

    def unapprove(self):
        """
        Unapprove a commit.

        API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-approve-delete
        """
        return super(BitbucketCloudBase, self).delete("approve")

author property

User object of the author.

date property

Commit date.

hash property

Commit id.

message property

Commit message.

add_build(key, url=None, description=None, refname=None, state=Build.STATE_INPROGRESS)

Add new build status to commit.

API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commit-statuses/#api-repositories-workspace-repo-slug-commit-commit-statuses-build-post

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/commits.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
def add_build(
    self,
    key,
    url=None,
    description=None,
    refname=None,
    state=Build.STATE_INPROGRESS,
):
    """
    Add new build status to commit.

    API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commit-statuses/#api-repositories-workspace-repo-slug-commit-commit-statuses-build-post
    """
    data = {
        "key": key,
        "state": state,
        "description": description,
        "url": url,
        "refname": refname,
    }

    return self.post("statuses/build", data)

approve()

Approve a commit.

API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-approve-post

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/commits.py
173
174
175
176
177
178
179
180
def approve(self):
    """
    Approve a commit.

    API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-approve-post
    """
    data = {"approved": True}
    return self.post("approve", data)

builds()

Return the Build objects for the commit.

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/commits.py
108
109
110
111
112
def builds(self):
    """Return the Build objects for the commit."""
    builds = [b for b in self.statuses() if b["type"] == "build"]
    for build in builds:
        yield Build(build, **self._new_session_args)

comment(raw_message)

Add a comment to the pull request in raw format.

API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-comments-post

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/commits.py
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
def comment(self, raw_message):
    """
    Add a comment to the pull request in raw format.

    API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-comments-post
    """
    if not raw_message:
        raise ValueError("No message set")

    data = {
        "content": {
            "raw": raw_message,
        }
    }

    return self.post("comments", data)

comments()

Return generator object endpoint of the comment. API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-comments-get

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/commits.py
148
149
150
151
152
153
154
def comments(self):
    """
    Return generator object endpoint of the comment.
    API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-comments-get
    """
    for comment in self._get_paged("comments"):
        yield Comment(comment, **self._new_session_args)

get_build(key)

Return a specific build for the commit.

API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commit-statuses/#api-repositories-workspace-repo-slug-commit-commit-statuses-build-key-get

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/commits.py
137
138
139
140
141
142
143
144
145
146
def get_build(self, key):
    """
    Return a specific build for the commit.

    API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commit-statuses/#api-repositories-workspace-repo-slug-commit-commit-statuses-build-key-get
    """
    return Build(
        super(Commit, self).get(self.url_joiner("statuses/build", key)),
        **self._new_session_args
    )  # fmt: skip

parents()

Return a generator object of parent commits.

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/commits.py
91
92
93
94
def parents(self):
    """Return a generator object of parent commits."""
    for commit in self.get_data("parents"):
        yield Commit(commit, **self._new_session_args)

participants()

Return a generator object of participants.

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/commits.py
103
104
105
106
def participants(self):
    """Return a generator object of participants."""
    for participant in self.get_data("participants"):
        yield Participant(participant, **self._new_session_args)

statuses()

Return generator object of the status's endpoint. API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commit-statuses/#api-repositories-workspace-repo-slug-commit-commit-statuses-get

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/commits.py
 96
 97
 98
 99
100
101
def statuses(self):
    """
    Return generator object of the status's endpoint.
    API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commit-statuses/#api-repositories-workspace-repo-slug-commit-commit-statuses-get
    """
    return self._get_paged("statuses")

unapprove()

Unapprove a commit.

API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-approve-delete

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/commits.py
182
183
184
185
186
187
188
def unapprove(self):
    """
    Unapprove a commit.

    API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-approve-delete
    """
    return super(BitbucketCloudBase, self).delete("approve")

Commits

Bases: BitbucketCloudBase

Bitbucket Cloud commits.

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/commits.py
 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
class Commits(BitbucketCloudBase):
    """Bitbucket Cloud commits."""

    def __init__(self, url, *args, **kwargs):
        super(Commits, self).__init__(url, *args, **kwargs)

    def __get_object(self, data):
        return Commit(data, **self._new_session_args)

    def each(self, top=None, q=None, sort=None):
        """
        Return the list of commits in this repository.

        :param top: string: Hash of commit to get the history for.
        :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 Commit objects

        API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commits-get
        """
        params = {}
        if sort is not None:
            params["sort"] = sort
        if q is not None:
            params["q"] = q
        trailing = True
        if top is not None:
            trailing = False
        for commit in self._get_paged(top, trailing=trailing, params=params):
            yield self.__get_object(commit)

    def get(self, commit_hash):
        """
        Return the commit with the requested commit id in this repository.

        :param commit_hash: str: The requested commit id

        :return: The requested Commit object

        API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-get
        """
        return self.__get_object(
            super(Commits, self).get(
                self.url_joiner(self.get_link("commit"), commit_hash),
                absolute=True,
            )
        )

each(top=None, q=None, sort=None)

Return the list of commits in this repository.

:param top: string: Hash of commit to get the history for. :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 Commit objects

API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commits-get

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/commits.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
def each(self, top=None, q=None, sort=None):
    """
    Return the list of commits in this repository.

    :param top: string: Hash of commit to get the history for.
    :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 Commit objects

    API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commits-get
    """
    params = {}
    if sort is not None:
        params["sort"] = sort
    if q is not None:
        params["q"] = q
    trailing = True
    if top is not None:
        trailing = False
    for commit in self._get_paged(top, trailing=trailing, params=params):
        yield self.__get_object(commit)

get(commit_hash)

Return the commit with the requested commit id in this repository.

:param commit_hash: str: The requested commit id

:return: The requested Commit object

API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-get

Source code in server/vendor/atlassian/bitbucket/cloud/repositories/commits.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def get(self, commit_hash):
    """
    Return the commit with the requested commit id in this repository.

    :param commit_hash: str: The requested commit id

    :return: The requested Commit object

    API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-get
    """
    return self.__get_object(
        super(Commits, self).get(
            self.url_joiner(self.get_link("commit"), commit_hash),
            absolute=True,
        )
    )