程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Altassian | Bitbucket Python API使用及相關任務自動化的實現

編輯:Python

本文總結如何調用Altassian的Bitbucket API及相關任務自動化的實現。
Updated: 2022 / 6 / 22


Altassian | Bitbucket Python API使用及相關任務自動化的實現

  • Bitbucket Python API
  • stashy
  • atlassian-python-api
    • Bitbucket Module
      • Manage Projects
      • Repository
        • File
  • 參考鏈接


Bitbucket Python API

目前可行的Bitbucket API 12

  • stashy 34
  • python-bitbucket 5
  • atlassian-python-api 67

stashy

根據用戶名和密碼登錄Bitbucket Server

from stashy
stash = stashy.connect()
url = 'http://YourServerAddr:7990',
username = 'YourUsername',
password = 'YourPassword')

atlassian-python-api

Bitbucket Module

根據用戶名和密碼登錄Bitbucket Server

from atlassian import Bitbucket
bitbucket = Bitbucket(
url = 'http://YourServerAddr:7990',
username = 'YourUsername',
password = 'YourPassword')

Manage Projects

  • 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'}]}
  • [x]

Repository

File

  • bitbucket.get_file_list(project_key, repository_slug, sub_folder, query, start, limit)
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

  • bitbucket.get_content_file(project, repository, filename, at=None, markup=None)
FileCont = bitbucket.get_content_file(YourProjectKey, YourRepoSlug, YourFilePath&Name, YourBranch, markup=None)
type(FileCont)
# <class 'bytes'>
FILE = open('./FILE.csv', 'wb').write(FileCont)

  • bitbucket.download_repo_archive(project_key, repository_slug, dest_fd, at, filename, format, path, prefix, chunk_size)
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()

參考鏈接


  1. python api for bitbucket︎

  2. Bitbucket API︎

  3. stashy︎

  4. stashy Github︎

  5. python-bitbucket︎

  6. atlassian-python-api︎

  7. atlassian-python-api Github︎


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved