本文總結如何調用Altassian的Bitbucket API及相關任務自動化的實現。
Updated: 2022 / 6 / 22
目前可行的Bitbucket API 1’ 2
根據用戶名和密碼登錄Bitbucket Server
from stashy
stash = stashy.connect()
url = 'http://YourServerAddr:7990',
username = 'YourUsername',
password = 'YourPassword')
根據用戶名和密碼登錄Bitbucket Server
from atlassian import Bitbucket
bitbucket = Bitbucket(
url = 'http://YourServerAddr:7990',
username = 'YourUsername',
password = 'YourPassword')
bitbucket.project.list()
bitbucket.project.list()
# {'key': ..., 'id': ..., 'name': ..., 'description': ..., 'public': ..., 'type': ..., 'links': {'self': [{'href': 'http://YourServerAdd:7990/projects/'key''}]}}
bitbucket.repo_list()
bitbucket.repo_list('YourProjectKey')
# {'slug': ..., 'id': ..., 'name': ..., 'description': ..., 'scmId': ..., 'state': ..., 'statusMessage': ..., 'forkable': ..., 'project': {'key': ..., 'id': ..., 'name': ..., 'description': ..., 'public': ..., 'type': ..., 'links': {'self': [{'href': 'http://YourServerAddr:7990/projects/YourProjectKey'}]}}, 'public': ..., 'links': {'clone': ..., [{'href': 'ssh://[email protected]: 7999/YourProjectKey/YourRepoSlug.git', 'name': 'ssh'}, {'href: 'http://YourServerAddr:7990/scm/YourProjectKey/YourReposlug.git', 'name': 'http'}], 'self': [{'href': 'http://YourServerAddr:7990/projects/YourProjectKey/repos/YourReposlug/browse'}]}
FileList = bitbucket.get_file_list(project_key = YourProjectKey, repository_slug = YourRepoSlug, sub_folder = YourFilePath, query = YourBranchName, start = FromwhereStart, limit=None)
# list(FileList)可列出在該Project該Repo該Branch該Subfolder下從start開始的所有file name
FileCont = bitbucket.get_content_file(YourProjectKey, YourRepoSlug, YourFilePath&Name, YourBranch, markup=None)
type(FileCont)
# <class 'bytes'>
FILE = open('./FILE.csv', 'wb').write(FileCont)
with open('./File', mode='wb') as Yourfd:
bitbucket.download_repo_archive(
project_key = YourProjectKey,
repository_slug = YourRepoSlug,
dest_fd = Yourfd,
at = YourBranch,
path = YourFilePath&Name,
format = zip)
# 或者
# fd = open('./File', mode = 'wb')
# bitbucket.download_repo_archive(
# project_key = YourProjectKey,
# repository_slug = YourRepoSlug,
# dest_fd = Yourfd,
# at = YourBranch,
# path = YourFilePath&Name,
# format = zip)
# dest_fd.close()
python api for bitbucket︎
Bitbucket API︎
stashy︎
stashy Github︎
python-bitbucket︎
atlassian-python-api︎
atlassian-python-api Github︎