簡體   English   中英

如何找到 Repository 的默認分支 - Bitbucket Cloud API

[英]How to find the default branch of Repository - Bitbucket Cloud API

我瀏覽了The Bitbucket Cloud Rest API的完整 API 文檔:

https://developer.atlassian.com/cloud/bitbucket/rest/api-group-repositories/#api-group-repositories

但是我沒有找到任何方法或 API 來獲取 Bitbucket Cloud Repository 的默認分支。

誰能幫我這個

謝謝

REST API 有一個存儲庫所有分支的過濾器,它的響應有一個名為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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM