bitbucket-api - Bitbucket Rest API 用于获取项目下的 Repo 名称
问题描述
我正在尝试使用 Bitbucket API 获取项目下的存储库名称。文档上的当前链接说要使用
curl -u 用户名:密码 http://${bitbucket-url}/rest/api/1.0/projects/${projectkey}/repos/
回复:
{ "size": 1, "limit": 25, "isLastPage": true, "values": [ { "slug": "my-repo", "id": 1, "name": "My repo", “scmId”:“git”,“state”:“AVAILABLE”,“statusMessage”:“Available”,“forkable”:true,“project”:{“key”:“PRJ”,“id”:1,“ name": "My Cool Project", "description": "The description for my cool project.", "public": true, "type": "NORMAL", "links": { "self": [ { "href ": "http://link/to/project" } ] } }, "public": true, "links": { "clone": [ { "href": "ssh://git@/PRJ/my-repo.git", "name": "ssh" }, { "href": "https:///scm/PRJ/my-repo.git", "name": " http" } ], "self": [ { "href": "http://link/to/repository" } ] } } ], "start": 0 }
但我只需要响应中的 repo 名称
解决方案
from subprocess import call
import configparser
import subprocess
import json
import os
base_dir = os.getcwd()
DETACHED_PROCESS = 0x00000008
cmd = 'curl --url "' + bb_url + '?pagelen=100&page=' + str(page) + '" --user ' + bb_user + ':' + bb_pwd + ' --request GET --header "Accept: application/json"'
output = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, creationflags=DETACHED_PROCESS).communicate()
datastore = json.loads(output[0].decode("utf-8"))
size = datastore.get("size")
values = datastore.get("values")
if(len(values)) == 0:
break
for repos in range(size):
repo_name = values[repos]["values"]["slug"]
f_initial = open (base_dir+"\\repositoryList.txt", "a+")
f_initial.write(repo_name)
f_initial.write("\n")
f_initial.close()
page = page + 1
此脚本将帮助您获取项目中所有存储库的列表,并将其写入文件 repositoryList.txt 下
推荐阅读
- ios - 在 ViewController 出现之前加载数据/图形/背景的方法
- javascript - 剑道网格截断小数
- eclipse - Eclipse,mvn eclipse:clean eclipse:eclipse,错误:找不到或加载主类
- php - PHP检测是否正在设置或更改公共属性
- android - Flutter Android Build 失败并出现异常“火炬:verifyReleaseResources”
- javascript - 当我尝试从文件夹中执行要求时,我得到错误
- ios - 目标为 iOS 9 的 iOS 应用的 Intune SDK 集成
- c# - 如何获得统一资产包清单?
- ruby-on-rails - 将 chromdriver 上传到 AWS Lambda 层(Ruby 2.5)
- python - 来自按组分组的 DataFrame 数据中的完整天数