Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
286 changes: 212 additions & 74 deletions atlassian/bamboo.py

Large diffs are not rendered by default.

760 changes: 598 additions & 162 deletions atlassian/bitbucket/__init__.py

Large diffs are not rendered by default.

31 changes: 26 additions & 5 deletions atlassian/bitbucket/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,26 @@ def __init__(self, url, *args, **kwargs):
url = self.get_link("self")
if isinstance(url, list): # Server has a list of links
url = url[0]
self.timeformat_lambda = kwargs.pop("timeformat_lambda", lambda x: self._default_timeformat_lambda(x))
self.timeformat_lambda = kwargs.pop(
"timeformat_lambda", lambda x: self._default_timeformat_lambda(x)
)
self._check_timeformat_lambda()
super(BitbucketBase, self).__init__(url, *args, **kwargs)

def __str__(self):
return PrettyPrinter(indent=4).pformat(self.__data if self.__data else self)
return PrettyPrinter(indent=4).pformat(
self.__data if self.__data else self
)

def _get_paged(self, url, params=None, data=None, flags=None, trailing=None, absolute=False):
def _get_paged(
self,
url,
params=None,
data=None,
flags=None,
trailing=None,
absolute=False,
):
"""
Used to get the paged data

Expand All @@ -56,7 +68,14 @@ def _get_paged(self, url, params=None, data=None, flags=None, trailing=None, abs
params = {}

while True:
response = self.get(url, trailing=trailing, params=params, data=data, flags=flags, absolute=absolute)
response = self.get(
url,
trailing=trailing,
params=params,
data=data,
flags=flags,
absolute=absolute,
)
if "values" not in response:
return

Expand Down Expand Up @@ -101,7 +120,9 @@ def _check_timeformat_lambda(self):
):
return True
else:
ValueError("Expected [None] or [lambda function] for argument [timeformat_func]")
ValueError(
"Expected [None] or [lambda function] for argument [timeformat_func]"
)

def _sub_url(self, url):
"""
Expand Down
8 changes: 6 additions & 2 deletions atlassian/bitbucket/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ def __init__(self, url="https://api.bitbucket.org/", *args, **kwargs):
kwargs["api_version"] = "2.0"
url = url.strip("/") + "/{}".format(kwargs["api_version"])
super(Cloud, self).__init__(url, *args, **kwargs)
self.__workspaces = Workspaces("{}/workspaces".format(self.url), **self._new_session_args)
self.__repositories = Repositories("{}/repositories".format(self.url), **self._new_session_args)
self.__workspaces = Workspaces(
"{}/workspaces".format(self.url), **self._new_session_args
)
self.__repositories = Repositories(
"{}/repositories".format(self.url), **self._new_session_args
)

@property
def workspaces(self):
Expand Down
19 changes: 16 additions & 3 deletions atlassian/bitbucket/cloud/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ def __init__(self, url, *args, **kwargs):
"""
expected_type = kwargs.pop("expected_type", None)
super(BitbucketCloudBase, self).__init__(url, *args, **kwargs)
if expected_type is not None and not expected_type == self.get_data("type"):
raise ValueError("Expected type of data is [{}], got [{}].".format(expected_type, self.get_data("type")))
if expected_type is not None and not expected_type == self.get_data(
"type"
):
raise ValueError(
"Expected type of data is [{}], got [{}].".format(
expected_type, self.get_data("type")
)
)

def get_link(self, link):
"""
Expand All @@ -38,7 +44,14 @@ def get_link(self, link):
return links[link]["href"]

def _get_paged(
self, url, params=None, data=None, flags=None, trailing=None, absolute=False, paging_workaround=False
self,
url,
params=None,
data=None,
flags=None,
trailing=None,
absolute=False,
paging_workaround=False,
):
"""
Used to get the paged data
Expand Down
4 changes: 3 additions & 1 deletion atlassian/bitbucket/cloud/common/builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class Build(BitbucketCloudBase):
STATE_SUCCESSFUL = "SUCCESSFUL"

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

@property
def key(self):
Expand Down
9 changes: 8 additions & 1 deletion atlassian/bitbucket/cloud/common/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

class Comment(BitbucketCloudBase):
def __init__(self, data, *args, **kwargs):
super(Comment, self).__init__(None, None, *args, data=data, expected_type="pullrequest_comment", **kwargs)
super(Comment, self).__init__(
None,
None,
*args,
data=data,
expected_type="pullrequest_comment",
**kwargs
)

@property
def raw(self):
Expand Down
8 changes: 6 additions & 2 deletions atlassian/bitbucket/cloud/common/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

class User(BitbucketCloudBase):
def __init__(self, url, data, *args, **kwargs):
super(User, self).__init__(url, *args, data=data, expected_type="user", **kwargs)
super(User, self).__init__(
url, *args, data=data, expected_type="user", **kwargs
)

@property
def display_name(self):
Expand Down Expand Up @@ -37,7 +39,9 @@ class Participant(BitbucketCloudBase):
CHANGES_REQUESTED = "changes_requested"

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

@property
def user(self):
Expand Down
60 changes: 46 additions & 14 deletions atlassian/bitbucket/cloud/repositories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ def get(self, workspace, repo_slug):
API docs:
https://developer.atlassian.com/cloud/bitbucket/rest/api-group-repositories/#api-repositories-workspace-repo-slug-get
"""
return self._get_object(super(Repositories, self).get("{}/{}".format(workspace, repo_slug)))
return self._get_object(
super(Repositories, self).get("{}/{}".format(workspace, repo_slug))
)


class WorkspaceRepositories(RepositoriesBase):
Expand All @@ -95,7 +97,9 @@ class WorkspaceRepositories(RepositoriesBase):
def __init__(self, url, *args, **kwargs):
super(WorkspaceRepositories, self).__init__(url, *args, **kwargs)

def create(self, repo_slug, project_key=None, is_private=None, fork_policy=None):
def create(
self, repo_slug, project_key=None, is_private=None, fork_policy=None
):
"""
Creates a new repository with the given repo_slug.

Expand All @@ -119,7 +123,9 @@ def create(self, repo_slug, project_key=None, is_private=None, fork_policy=None)
data["is_private"] = is_private
if fork_policy is not None:
if fork_policy not in self.FORK_POLICIES:
raise ValueError("fork_policy must be one of {}".format(self.FORK_POLICIES))
raise ValueError(
"fork_policy must be one of {}".format(self.FORK_POLICIES)
)
data["fork_policy"] = fork_policy
return self._get_object(self.post(repo_slug, data=data))

Expand Down Expand Up @@ -165,13 +171,19 @@ def get(self, repository, by="slug"):
https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D#get
"""
if by == "slug":
return self._get_object(super(WorkspaceRepositories, self).get(repository))
return self._get_object(
super(WorkspaceRepositories, self).get(repository)
)
elif by == "name":
for r in self.each():
if r.name == repository:
return r
else:
ValueError("Unknown value '{}' for argument [by], expected 'key' or 'name'".format(by))
ValueError(
"Unknown value '{}' for argument [by], expected 'key' or 'name'".format(
by
)
)

raise Exception("Unknown repository {} '{}'".format(by, repository))

Expand Down Expand Up @@ -235,32 +247,52 @@ def get(self, repository, by="slug"):
https://developer.atlassian.com/bitbucket/api/2/reference/resource/workspaces/%7Bworkspace%7D/projects/%7Bproject_key%7D#get
"""
if by not in ("slug", "name"):
ValueError("Unknown value '{}' for argument [by], expected 'slug' or 'name'".format(by))
ValueError(
"Unknown value '{}' for argument [by], expected 'slug' or 'name'".format(
by
)
)

for r in self.each():
if ((by == "slug") and (r.slug == repository)) or ((by == "name") and (r.name == repository)):
if ((by == "slug") and (r.slug == repository)) or (
(by == "name") and (r.name == repository)
):
return r

raise Exception("Unknown repository {} '{}'".format(by, repository))


class Repository(BitbucketCloudBase):
def __init__(self, data, *args, **kwargs):
super(Repository, self).__init__(None, *args, data=data, expected_type="repository", **kwargs)
super(Repository, self).__init__(
None, *args, data=data, expected_type="repository", **kwargs
)
self.__branch_restrictions = BranchRestrictions(
"{}/branch-restrictions".format(self.url), **self._new_session_args
)
self.__branches = Branches("{}/refs/branches".format(self.url), **self._new_session_args)
self.__branches = Branches(
"{}/refs/branches".format(self.url), **self._new_session_args
)
self.__commits = Commits(
"{}/commits".format(self.url),
data={"links": {"commit": {"href": "{}/commit".format(self.url)}}},
**self._new_session_args
)
self.__default_reviewers = DefaultReviewers("{}/default-reviewers".format(self.url), **self._new_session_args)
self.__issues = Issues("{}/issues".format(self.url), **self._new_session_args)
self.__pipelines = Pipelines("{}/pipelines".format(self.url), **self._new_session_args)
self.__pullrequests = PullRequests("{}/pullrequests".format(self.url), **self._new_session_args)
self.__tags = Tags("{}/refs/tags".format(self.url), **self._new_session_args)
self.__default_reviewers = DefaultReviewers(
"{}/default-reviewers".format(self.url), **self._new_session_args
)
self.__issues = Issues(
"{}/issues".format(self.url), **self._new_session_args
)
self.__pipelines = Pipelines(
"{}/pipelines".format(self.url), **self._new_session_args
)
self.__pullrequests = PullRequests(
"{}/pullrequests".format(self.url), **self._new_session_args
)
self.__tags = Tags(
"{}/refs/tags".format(self.url), **self._new_session_args
)

def update(self, **kwargs):
"""
Expand Down
4 changes: 3 additions & 1 deletion atlassian/bitbucket/cloud/repositories/branchRestrictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ def get(self, id):

class BranchRestriction(BitbucketCloudBase):
def __init__(self, data, *args, **kwargs):
super(BranchRestriction, self).__init__(None, *args, data=data, expected_type="branchrestriction", **kwargs)
super(BranchRestriction, self).__init__(
None, *args, data=data, expected_type="branchrestriction", **kwargs
)

def update(self, **kwargs):
"""
Expand Down
29 changes: 20 additions & 9 deletions atlassian/bitbucket/cloud/repositories/commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ def get(self, commit_hash):
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)
super(Commits, self).get(
self.url_joiner(self.get_link("commit"), commit_hash),
absolute=True,
)
)


Expand All @@ -60,7 +63,9 @@ class Commit(BitbucketCloudBase):
"""

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

@property
def hash(self):
Expand Down Expand Up @@ -106,7 +111,14 @@ def builds(self):
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):
def add_build(
self,
key,
url=None,
description=None,
refname=None,
state=Build.STATE_INPROGRESS,
):
"""
Add new build status to commit.

Expand All @@ -128,7 +140,10 @@ def get_build(self, key):

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)
return Build(
super(Commit, self).get(self.url_joiner("statuses/build", key)),
**self._new_session_args
)

def comments(self):
"""
Expand All @@ -148,11 +163,7 @@ def comment(self, raw_message):
if not raw_message:
raise ValueError("No message set")

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

return self.post("comments", data)

Expand Down
10 changes: 8 additions & 2 deletions atlassian/bitbucket/cloud/repositories/defaultReviewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ def __init__(self, url, *args, **kwargs):
super(DefaultReviewers, self).__init__(url, *args, **kwargs)

def __get_object(self, data):
return DefaultReviewer(self.url_joiner(self.url, data["uuid"]), data, **self._new_session_args)
return DefaultReviewer(
self.url_joiner(self.url, data["uuid"]),
data,
**self._new_session_args
)

def add(self, user):
"""
Expand Down Expand Up @@ -65,7 +69,9 @@ def get(self, user):
"""
default_reviewer = None
try:
default_reviewer = self.__get_object(super(DefaultReviewers, self).get(user))
default_reviewer = self.__get_object(
super(DefaultReviewers, self).get(user)
)
except HTTPError as e:
# A 404 indicates that the specified user is not a default reviewer.
if not e.response.status_code == 404:
Expand Down
15 changes: 12 additions & 3 deletions atlassian/bitbucket/cloud/repositories/diffstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class DiffStat(BitbucketCloudBase):

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

@property
def lines_removed(self):
Expand Down Expand Up @@ -69,8 +71,15 @@ class CommitFile(BitbucketCloudBase):
def __init__(self, data, *args, **kwargs):
"""See BitbucketCloudBase."""
if data is None: # handles add/remove
data = {"path": None, "escaped_path": None, "links": {}, "type": "commit_file"}
super(CommitFile, self).__init__(None, None, *args, data=data, expected_type="commit_file", **kwargs)
data = {
"path": None,
"escaped_path": None,
"links": {},
"type": "commit_file",
}
super(CommitFile, self).__init__(
None, None, *args, data=data, expected_type="commit_file", **kwargs
)

@property
def path(self):
Expand Down
Loading