我浏览了 Bitbucket Cloud Rest API 的完整 API 文档:
https://developer.atlassian.com/cloud/bitbucket/rest/api-group-repositories/#api-group-repositories
但是我没有找到任何方法或API来获取Bitbucket Cloud Repository的默认分支。
有人可以帮我吗
谢谢
REST API 对于存储库的所有分支都有一个 filter,其响应有一个名为
isDefault
的属性
curl -s -u $BITBUCKET_KEY $BITBUCKET_URL/rest/api/latest/projects/$PROJECT/repos/$REPO/branches?limit=100 | jq -r '.values[]'
{
"id": "refs/heads/master",
"displayId": "master",
"type": "BRANCH",
"latestCommit": "c2a944ba03ea7c1ab07b3159660c69647229704e",
"latestChangeset": "c2a944ba03ea7c1ab07b3159660c69647229704e",
"isDefault": true
}
{
"id": "refs/heads/release/1.3.5",
"displayId": "release/1.3.5",
"type": "BRANCH",
"latestCommit": "a835d28c8f828610fcc4f0f463b99c4a75039aef",
"latestChangeset": "a835d28c8f828610fcc4f0f463b99c4a75039aef",
"isDefault": false
}
列表可以显示为:
#!/bin/bash
# Get branches in a BitBucket repo
set -euo pipefail
REPO=$1
PROJECT='MYTEAM'
## url of branches in a repo
BITBUCKET_URL="https://bitbucket.example.com/rest/api/latest/projects/$PROJECT/repos/$REPO/branches?limit=100"
# Check BITBUCKET_URL with a http HEAD request
OUT=$(curl --fail --head -u "$BITBUCKET_KEY" "$BITBUCKET_URL" 2>&1)
if [ $? -ne 0 ] ; then
echo "Error: $OUT"| tail -1
exit $?
fi
# Query the JSON output of the request
JSON=$(curl -s -u "$BITBUCKET_KEY" "$BITBUCKET_URL" 2>&1)
echo "$JSON" | jq -r '.values[] | .displayId'
https://developer.atlassian.com/cloud/bitbucket/rest/intro/#filtering
bbaassssiiee 的答案是针对 Bitbucket Server,而不是针对 Bitbucket Cloud。
对于Bitbucket Cloud,查询repo详情并访问$.mainbranch https://developer.atlassian.com/cloud/bitbucket/rest/api-group-repositories/#api-repositories-workspace-repo-slug-get
当前版本文档的示例响应包括 mainbranch 属性,但仅包含子属性“type”($.mainbranch.type)。在实际响应中,“type”值是“branch”(显然),但您也有 $.mainbranch.name 这就是您正在寻找的内容。