bitbucket api的python包装器
pybitbucket的Python项目详细描述
bitbucket云rest api的python包装器。
这在Bitbucket服务器上是不知道的,
以前被称为藏物。
要开始使用此库,请执行以下操作:pip install pybitbucket
采用此库
认证
Authenticator
子类使用凭据准备api请求。
最简单的情况是Anonymous
,它连接时没有凭据。
Anonymous
可以与公共可用资源一起使用。
对于私人资源,
BasicAuthenticator
使用电子邮件、用户名和密码作为凭据。
如果客户端应用程序有自己的机制来处理这些值,
您可以将BasicAuthenticator
子类化以提供自定义行为。
要“插入”您的实现或标准实现,请执行以下操作:
bitbucket = Client( BasicAuthenticator( 'your_username_here', 'your_secret_password_here', 'pybitbucket@mailinator.com'))
如果您启用了two-step verification,
然后你需要用app password和BasicAuthenticator
,
不是你的常规用户密码。
OAuth2Authenticator
用作示例和超类。
它可能适用于某些命令行客户机。
其他客户端,如web应用程序
需要obtain_authorization()
的适当实现
可能需要使用不同的授权类型。
查找
例如,要查找所有代码片段:
for snip in Snippet.find_snippets_for_role(client=bitbucket): print(snip)
该方法称为“for role”,但如果未提供,则将使用owner的默认值。 因此,你所有的片段。
通常,在每种类型的资源上使用静态find方法来完成查找工作。 如果资源是复数的,就像上面的“片段”,那么find方法就是一个生成器。 您可以将它与迭代器或理解一起使用。 您可以找到以下资源:
- 用户和团队
- 存储库和代码片段
- 拉取请求和注释
- 提交和生成状态
- 挂钩和分支限制
创造事物
例如,要创建新代码段:
snip = Snippet.create( files=open_files(["README.rst"]), payload=SnippetPayload().add_title("My New Snippet"), client=bitbucket)
您可以创建的资源是:
- 存储库和代码片段
- 拉取请求和注释
- 生成状态
- 挂钩和分支限制
检查事物
例如,要检查片段上的属性:
snip = Snippet.find_snippet_by_id("Xqoz8", bitbucket) s = '\n'.join([ "id : {}".format(snip.id), "is_private : {}".format(snip.is_private), "title : {}".format(snip.title), "files : {}".format(snip.filenames), "created_on : {}".format(snip.created_on), "updated_on : {}".format(snip.updated_on), "scm : {}".format(snip.scm), ]) if snip else 'Snippet not found.' print(s)
哪些属性可用? 您不会发现它们是用python硬编码的。 它们是从json响应动态填充的。 您可以通过方便的方法查询列表:
snip = Snippet.find_snippet_by_id("Xqoz8", bitbucket) print(snip.attributes())
当心。同一资源的属性可能会根据您对它的访问方式而改变。
开发
python虚拟环境设置(用于os x)
它不像虚拟机那样是虚拟的。更像是python版本和库的专用容器。
brew install python
这将安装最新版本的python 2.7和setuptools和pip。不幸的是,这些版本的setuptools和pip似乎被破坏了。pip install --upgrade --no-use-wheel setuptools
pip install --upgrade --no-use-wheel pip
pip install virtualenvwrapper
项目设置
- 克隆存储库并将其设置为当前工作目录。
- (可选,但良好实践)创建virtual environment:
mkvirtualenv python-bitbucket
创建后,使用workon python-bitbucket
还原虚拟环境。 pip install -r requirements-dev.txt
将所需的库加载到虚拟环境中。paver test_all
运行所有单元测试并分析源代码。
待办事项
PUT
和DELETE
来自snippets Endpoint的snippet.watch
。- 将version 1 endpoints包装为:
- 组
- 组权限
- 邀请