|
| 1 | +from ..base import BitbucketCloudBase |
| 2 | + |
| 3 | + |
| 4 | +class DiffStat(BitbucketCloudBase): |
| 5 | + """ |
| 6 | + Bitbucket Cloud repository diffstat entry. |
| 7 | +
|
| 8 | + This represents the changes for one specific file in a diff. |
| 9 | +
|
| 10 | + See https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-diffstat-spec-get |
| 11 | + """ |
| 12 | + |
| 13 | + MODIFIED = "modified" |
| 14 | + ADDED = "added" |
| 15 | + REMOVED = "removed" |
| 16 | + MERGE_CONFLICT = "merge conflict" |
| 17 | + SUBREPO_CONFLICT = "subrepo conflict" |
| 18 | + |
| 19 | + def __init__(self, data, *args, **kwargs): |
| 20 | + """See BitbucketCloudBase.""" |
| 21 | + super(DiffStat, self).__init__(None, None, *args, data=data, expected_type="diffstat", **kwargs) |
| 22 | + |
| 23 | + @property |
| 24 | + def lines_removed(self): |
| 25 | + """Lines removed.""" |
| 26 | + return self.get_data("lines_removed") |
| 27 | + |
| 28 | + @property |
| 29 | + def lines_added(self): |
| 30 | + """Lines added.""" |
| 31 | + return self.get_data("lines_added") |
| 32 | + |
| 33 | + @property |
| 34 | + def old(self): |
| 35 | + """A CommitFile object, representing a file at a commit in a repository.""" |
| 36 | + return CommitFile(self.get_data("old"), **self._new_session_args) |
| 37 | + |
| 38 | + @property |
| 39 | + def new(self): |
| 40 | + """A CommitFile object, representing a file at a commit in a repository.""" |
| 41 | + return CommitFile(self.get_data("new"), **self._new_session_args) |
| 42 | + |
| 43 | + @property |
| 44 | + def has_conflict(self): |
| 45 | + """True if the change causes a conflict.""" |
| 46 | + return str(self.get_data("status")) in (self.MERGE_CONFLICT, self.SUBREPO_CONFLICT) |
| 47 | + |
| 48 | + |
| 49 | +class CommitFile(BitbucketCloudBase): |
| 50 | + """ |
| 51 | + Bitbucket Cloud repository diffstat file. |
| 52 | +
|
| 53 | + File reference from a diffstat entry. |
| 54 | +
|
| 55 | + See https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-diffstat-spec-get |
| 56 | + """ |
| 57 | + |
| 58 | + def __init__(self, data, *args, **kwargs): |
| 59 | + """See BitbucketCloudBase.""" |
| 60 | + if data is None: # handles add/remove |
| 61 | + data = {"path": None, "escaped_path": None, "links": {}, "type": "commit_file"} |
| 62 | + super(CommitFile, self).__init__(None, None, *args, data=data, expected_type="commit_file", **kwargs) |
| 63 | + |
| 64 | + @property |
| 65 | + def path(self): |
| 66 | + """The path in the repository.""" |
| 67 | + return self.get_data("path") |
| 68 | + |
| 69 | + @property |
| 70 | + def escaped_path(self): |
| 71 | + """ |
| 72 | + The escaped version of the path as it appears in a diff. |
| 73 | +
|
| 74 | + If the path does not require escaping this will be the same as path. |
| 75 | + """ |
| 76 | + return self.get_data("escaped_path") |
0 commit comments