/docs/bitbucket.rst

https://github.com/atlassian-api/atlassian-python-api · ReStructuredText · 326 lines · 225 code · 101 blank · 0 comment · 0 complexity · 4367a28d59ad52a7e54df282d077a127 MD5 · raw file

  1. BitBucket module
  2. ================
  3. Manage projects
  4. ---------------
  5. .. code-block:: python
  6. # Project list
  7. bitbucket.project_list()
  8. # Repo list
  9. bitbucket.repo_list(project_key)
  10. # Project info
  11. bitbucket.project(key)
  12. # Create project
  13. bitbucket.create_project(key, name, description="My pretty project")
  14. # Get users who has permission in project
  15. bitbucket.project_users(key, limit=99999, filter_str=None)
  16. # Get project administrators for project
  17. butbucket.project_users_with_administrator_permissions(key)
  18. # Get Project Groups
  19. bitbucket.project_groups(key, limit=99999, filter_str=None)
  20. # Get groups with admin permissions
  21. bitbucket.project_groups_with_administrator_permissions(key)
  22. # Project summary
  23. bitbucket.project_summary(key)
  24. # Grant project permission to an specific user
  25. bitbucket.project_grant_user_permissions(project_key, username, permission)
  26. # Grant project permission to an specific group
  27. bitbucket.project_grant_group_permissions(project_key, groupname, permission)
  28. Manage repositories
  29. -------------------
  30. .. code-block:: python
  31. # Get single repository
  32. bitbucket.get_repo(project_key, repository_slug)
  33. # Disable branching model
  34. bitbucket.disable_branching_model(project_key, repo_key)
  35. # Enable branching model
  36. bitbucket.enable_branching_model(project_key, repo_key)
  37. # Get branching model
  38. bitbucket.get_branching_model(project_key, repo_key)
  39. # Set branching model
  40. data = {'development': {'refId': None, 'useDefault': True},
  41. 'types': [{'displayName': 'Bugfix',
  42. 'enabled': True,
  43. 'id': 'BUGFIX',
  44. 'prefix': 'bugfix-'},
  45. {'displayName': 'Feature',
  46. 'enabled': True,
  47. 'id': 'FEATURE',
  48. 'prefix': 'feature-'},
  49. {'displayName': 'Hotfix',
  50. 'enabled': True,
  51. 'id': 'HOTFIX',
  52. 'prefix': 'hotfix-'},
  53. {'displayName': 'Release',
  54. 'enabled': True,
  55. 'id': 'RELEASE',
  56. 'prefix': 'release/'}]}
  57. bitbucket.set_branching_model(project_key, repo_key, data)
  58. bitbucket.repo_users(project_key, repo_key, limit=99999, filter_str=None)
  59. bitbucket.repo_groups(project_key, repo_key, limit=99999, filter_str=None)
  60. # Grant repository permission to an specific user
  61. bitbucket.repo_grant_user_permissions(project_key, repo_key, username, permission)
  62. # Grant repository permission to an specific group
  63. bitbucket.repo_grant_group_permissions(project_key, repo_key, groupname, permission)
  64. # Delete a repository (DANGER!)
  65. bitbucket.delete_repo(project_key, repository_slug)
  66. Groups and admins
  67. -----------------
  68. .. code-block:: python
  69. # Get group of members
  70. bitbucket.group_members(group, limit=99999)
  71. # All project administrators
  72. bitbucket.all_project_administrators()
  73. # Get users. Use 'user_filter' parameter to get specific users.
  74. bitbucket.get_users(user_filter="username")
  75. Manage code
  76. -----------
  77. .. code-block:: python
  78. # Get repositories list from project
  79. bitbucket.repo_list(project_key, limit=25)
  80. # Create a new repository.
  81. # Requires an existing project in which this repository will be created. The only parameters which will be used
  82. # are name and scmId.
  83. # The authenticated user must have PROJECT_ADMIN permission for the context project to call this resource.
  84. bitbucket.create_repo(project_key, repository, forkable=False, is_private=True)
  85. # Get branches from repo
  86. bitbucket.get_branches(project, repository, filter='', limit=99999, details=True)
  87. # Creates a branch using the information provided in the request.
  88. # The authenticated user must have REPO_WRITE permission for the context repository to call this resource.
  89. bitbucket.create_branch(project_key, repository, name, start_point, message)
  90. # Delete branch from related repo
  91. bitbucket.delete_branch(project, repository, name, end_point)
  92. # Get pull requests
  93. bitbucket.get_pull_requests(project, repository, state='OPEN', order='newest', limit=100, start=0)
  94. # Get pull request activities
  95. bitbucket.get_pull_requests_activities(project, repository, pull_request_id)
  96. # Get pull request changes
  97. bitbucket.get_pull_requests_changes(project, repository, pull_request_id)
  98. # Get pull request commits
  99. bitbucket.get_pull_requests_commits(project, repository, pull_request_id)
  100. # Add comment into pull request
  101. bitbucket.add_pull_request_comment(project, repository, pull_request_id, text)
  102. # Create a new pull request between two branches.
  103. bitbucket.open_pull_request(source_project, source_repo, dest_project, dest_repo, source_branch, destination_branch, title, description)
  104. # Create a new pull request between two branches with one reviewer
  105. bitbucket.open_pull_request(source_project, source_repo, dest_project, dest_repo, source_branch, destination_branch, title, description, reviewers='name')
  106. # Create a new pull request between two branches with multiple reviewers.
  107. bitbucket.open_pull_request(source_project, source_repo, dest_project, dest_repo, source_branch, destination_branch, title, description, reviewers=['name1', 'name2'])
  108. # Delete a pull request
  109. bitbucket.delete_pull_request(project, repository, pull_request_id, pull_request_version)
  110. # Get tags for related repo
  111. bitbucket.get_tags(project, repository, filter='', limit=99999)
  112. # Get project tags
  113. # The authenticated user must have REPO_READ permission for the context repository to call this resource
  114. bitbucket.get_project_tags(project, repository, tag_name)
  115. # Set tag
  116. # The authenticated user must have REPO_WRITE permission for the context repository to call this resource
  117. bitbucket.set_tag(project, repository, tag_name, commit_revision, description=None)
  118. # Delete tag
  119. # The authenticated user must have REPO_WRITE permission for the context repository to call this resource
  120. bitbucket.delete_tag(project, repository, tag_name)
  121. # Get diff
  122. bitbucket.get_diff(project, repository, path, hash_oldest, hash_newest)
  123. # Get commit list from repo
  124. bitbucket.get_commits(project, repository, hash_oldest, hash_newest, limit=99999)
  125. # Get change log between 2 refs
  126. bitbucket.get_changelog(project, repository, ref_from, ref_to, limit=99999)
  127. # Get raw content of the file from repo
  128. bitbucket.get_content_of_file(project, repository, filename, at=None, markup=None)
  129. """
  130. Retrieve the raw content for a file path at a specified revision.
  131. The authenticated user must have REPO_READ permission for the specified repository to call this resource.
  132. """
  133. Branch permissions
  134. ------------------
  135. .. code-block:: python
  136. # Set branches permissions
  137. bitbucket.set_branches_permissions(project_key, multiple_permissions=False, matcher_type=None, matcher_value=None, permission_type=None, repository=None, except_users=[], except_groups=[], except_access_keys=[], start=0, limit=25)
  138. # Delete a single branch permission by premission id
  139. bitbucket.delete_branch_permission(project_key, permission_id, repository=None)
  140. # Get a single branch permission by permission id
  141. bitbucket.get_branch_permission(project_key, permission_id, repository=None)
  142. Pull Request management
  143. -----------------------
  144. .. code-block:: python
  145. # Decline pull request
  146. bitbucket.decline_pull_request(project_key, repository, pr_id, pr_version)
  147. # Check if pull request can be merged
  148. bitbucket.is_pull_request_can_be_merged(project_key, repository, pr_id)
  149. # Merge pull request
  150. bitbucket.merge_pull_request(project_key, repository, pr_id, pr_version)
  151. # Reopen pull request
  152. bitbucket.reopen_pull_request(project_key, repository, pr_id, pr_version)
  153. Conditions-Reviewers management
  154. -------------------------------
  155. .. code-block:: python
  156. # Get all project conditions with reviewers list for specific project
  157. bitbucket.get_project_conditions(project_key)
  158. # Get a project condition with reviewers list for specific project
  159. bitbucket.get_project_condition(project_key, id_condition)
  160. # Create project condition with reviewers for specific project
  161. # :example condition: '{"sourceMatcher":{"id":"any","type":{"id":"ANY_REF"}},"targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}},"reviewers":[{"id": 12}],"requiredApprovals":"0"}'
  162. bitbucket.create_project_condition(project_key, condition)
  163. # Update a project condition with reviewers for specific project
  164. # :example condition: '{"sourceMatcher":{"id":"any","type":{"id":"ANY_REF"}},"targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}},"reviewers":[{"id": 12}],"requiredApprovals":"0"}'
  165. bitbucket.update_project_condition(project_key, condition, id_condition)
  166. # Delete a project condition for specific project
  167. bitbucket.delete_project_condition(project_key, id_condition)
  168. # Get all repository conditions with reviewers list for specific repository in project
  169. bitbucket.get_repo_conditions(project_key, repo_key)
  170. # Get repository conditions with reviewers list only only conditions type PROJECT for specific repository in project
  171. bitbucket.get_repo_project_conditions(project_key, repo_key)
  172. # Get repository conditions with reviewers list only conditions type REPOSITORY for specific repository in project
  173. bitbucket.get_repo_repo_conditions(project_key, repo_key)
  174. # Get a project condition with reviewers list for specific repository in project
  175. bitbucket.get_repo_condition(project_key, repo_key, id_condition)
  176. # Create project condition with reviewers for specific repository in project
  177. # :example condition: '{"sourceMatcher":{"id":"any","type":{"id":"ANY_REF"}},"targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}},"reviewers":[{"id": 12}],"requiredApprovals":"0"}'
  178. bitbucket.create_repo_condition(project_key, repo_key, condition)
  179. # Update a project condition with reviewers for specific repository in project
  180. # :example condition: '{"sourceMatcher":{"id":"any","type":{"id":"ANY_REF"}},"targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}},"reviewers":[{"id": 12}],"requiredApprovals":"0"}'
  181. bitbucket.update_repo_condition(project_key, repo_key, condition, id_condition)
  182. # Delete a project condition for specific repository in project
  183. bitbucket.delete_repo_condition(project_key, repo_key, id_condition)
  184. Pipelines management
  185. --------------------
  186. .. code-block:: python
  187. # Get most recent Pipelines results for repository
  188. bitbucket.get_pipelines(workspace, repository)
  189. # Trigger default Pipeline on the latest revision of the master branch
  190. bitbucket.trigger_pipeline(workspace, repository)
  191. # Trigger default Pipeline on the latest revision of the develop branch
  192. bitbucket.trigger_pipeline(workspace, repository, branch="develop")
  193. # Trigger default Pipeline on a specific revision of the develop branch
  194. bitbucket.trigger_pipeline(workspace, repository, branch="develop", revision="<40-char hash>")
  195. # Trigger specific Pipeline on a specific revision of the master branch
  196. bitbucket.trigger_pipeline(workspace, repository, revision="<40-char hash>", name="style-check")
  197. # Get specific Pipeline by UUID
  198. bitbucket.get_pipeline(workspace, repository, "{7d6c327d-6336-4721-bfeb-c24caf25045c}")
  199. # Stop specific Pipeline by UUID
  200. bitbucket.stop_pipeline(workspace, repository, "{7d6c327d-6336-4721-bfeb-c24caf25045c}")
  201. # Get steps of Pipeline specified by UUID
  202. bitbucket.get_pipeline_steps(workspace, repository, "{7d6c327d-6336-4721-bfeb-c24caf25045c}")
  203. # Get step of Pipeline specified by UUIDs
  204. bitbucket.get_pipeline_step(workspace, repository, "{7d6c327d-6336-4721-bfeb-c24caf25045c}", "{56d2d8af-6526-4813-a22c-733ec6ecabf3}")
  205. # Get log of step of Pipeline specified by UUIDs
  206. bitbucket.get_pipeline_step_log(workspace, repository, "{7d6c327d-6336-4721-bfeb-c24caf25045c}", "{56d2d8af-6526-4813-a22c-733ec6ecabf3}")
  207. Manage issues
  208. -------------
  209. .. code-block:: python
  210. # Get all tracked issues
  211. bitbucket.get_issues(workspace, repository)
  212. # Get all unassigned issues and sort them by priority
  213. bitbucket.get_issues(workspace, repository, sort_by="priority", query='assignee = null')
  214. # Create a new issue
  215. bitbucket.create_issue(workspace, repository, "The title", "The description")
  216. # Create a new issue of kind 'enhancement' and priority 'minor'
  217. bitbucket.create_issue(workspace, repository, "New idea", "How about this", kind="enhancement", priority="minor")
  218. # Update the 'priority' field of the issue 42
  219. bitbucket.update_issue(workspace, repository, 42, priority="blocker")
  220. # Mark issue 42 as resolved
  221. bitbucket.update_issue(workspace, repository, 42, state="resolved")
  222. # Get information about issue 1
  223. bitbucket.get_issue(workspace, repository, 1)
  224. # Delete issue 123
  225. bitbucket.delete_issue(workspace, repository, 123)