我想用bash腳本和http克隆我所有bitbucket團隊存儲庫。我發現了一些使用Bitbucket api的例子,但它們似乎都沒有返回任何存儲庫。有任何想法嗎?使用mac。Bitbucket克隆所有團隊存儲庫
回答
確保你有你的SSH密鑰設置在到位桶和Git是通過克隆手動一個回購安裝:
這將克隆由你所擁有的所有回購:
USER=bitbucket_username; curl --user ${USER} https://api.bitbucket.org/2.0/repositories/${USER} | grep -o '"ssh:[^ ,]\+' | xargs -L1 git clone
要備份你的團隊庫使用相同的腳本,但很難代碼的到位桶隊名是這樣的:
USER=bitbucket_username; curl --user ${USER} https://api.bitbucket.org/2.0/repositories/TEAMNAME | grep -o '"ssh:[^ ,]\+' | xargs -L1 git clone
這裏有一個better way:
curl -u ${1} https://api.bitbucket.org/1.0/users/TEAMNAME > repoinfo
for repo_name in `cat repoinfo | sed -r 's/("name":)/\n\1/g' | sed -r 's/"name": "(.*)"/\1/' | sed -e 's/{//' | cut -f1 -d\" | tr '\n' ' '`
do
echo "Cloning " $repo_name
git clone [email protected]:TEAMNAME/$repo_name.git
echo "---"
done
如果您的存儲庫少於100個,並且在查詢中添加'pagelen = 100',那麼只能使用一個簡單的命令,因爲這是bitbucket API一次報告的最多。如果您有超過100個存儲庫,則需要處理返回的JSON中的「下一個」鏈接,以獲取URL以查詢下一組存儲庫,這對於腳本來說更容易。
如果您使用HTTP克隆而不是使用ssh,那麼您可能需要對受保護的資料庫輸入密碼,否則拿到到位桶應用程序的密碼,並修改URL以插入到他們,讓他們看起來像:
https://bitbucketuserhere:[email protected]/teamorusername/repositoryname.git
此外,克隆不會獲得所有版本的git LFS文件,因此請注意這一點。根據bitbucket,使用'git fetch --all'在本地複製所有LFS文件版本。
爲了讓您的個人資料庫列表中,使用URL,如:
https://api.bitbucket.org/2.0/repositories/BITBUCKETUSERNAME?pagelen=100
爲了讓您的團隊庫的列表,使用這樣的網址,讓你的所有存儲庫列表成員:
https://api.bitbucket.org/2.0/repositories/TEAMNAME?pagelen=100&role=member
下面是一個例子Perl腳本,你可以用它來克隆,然後保持你的版本庫的拷貝,使用http而不是ssh來FE TCH。它使 - 克隆克隆而不是完全填充的工作副本(適用於移動或災難恢復)。它沒有而不是備份所有的LFS文件。
#!/usr/bin/env perl
use warnings;
use strict;
use JSON::Parse 'parse_json';
# CONFIGURATION:
# Bitbucket team or user name to get list of repositories from
my $teamORuserName = "myteam";
# Bitbucket app password with access to query the API for the
# list of repositories. Format: "user-name:app-token"
my $appPassword= "frank-james:LAYDxtc8H6FGKUZeHEef";
#------------------------------------------------------------------------------
my $nextPageLink = "https://api.bitbucket.org/2.0/repositories/$teamORuserName?pagelen=100&role=member";
while (defined $nextPageLink)
{
$nextPageLink =~ m/page=(\d+)/;
print "Fetching page " . ($1 || 1). "\n";
my $response = `curl -q --silent --request GET --user '$appPassword' '$nextPageLink'`;
my $json = parse_json($response);
my $values = $json->{values};
foreach my $repo (@$values)
{
die "'$repo->{name}' is not a 'git' repo: $repo->{scm}" unless $repo->{scm} eq "git";
my $links = $repo->{links} || die "no links data for '$repo->{name}'";
my $clones = $links->{clone} || die "no clone data for '$repo->{name}'";
my $url = $clones->[0]->{href} || die "no clone url found for $repo->{name}";
# use uuid as directory name, to survive project name changes
my $uuid = $repo->{uuid}; $uuid =~ s/[\{\}]//g;
if (not -e $uuid)
{
print "cloning '$repo->{name}' into $uuid\n";
# replace user name with token to avoid password prompts
$url =~ s|(https?://).+(\@bitbucket.org)|$1$appPassword$2|;
system("git clone --progress --mirror '$url' $uuid") == 0 or die "clone failed";
# make a human friendly link to current repository name
symlink $uuid, $repo->{slug} or warn "symlink failed: $!";
}
else
{
print "updating '$repo->{name}' in $uuid\n";
system("cd $uuid && git fetch --all --tags --prune") == 0 or die "fetch failed";
}
print "\n";
}
$nextPageLink = $json->{next};
}
exit 0;
這是一個python腳本,用於克隆bitbucket中的所有團隊或用戶的存儲庫。由於團隊存儲庫通常是私有的,因此我在使用bitbucket API時注意到了這一點。因此,只需輸入您的bitbucket用戶名,密碼和團隊的用戶名,它將負責爲您克隆所有團隊存儲庫。
import subprocess
import json
cmd = "curl -u <bitbucket_username>:<bitbucket_password> https://api.bitbucket.org/2.0/repositories/<team_name_or_project_name>"
cmd = cmd.split()
while 1:
from_api = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
from_api = from_api.communicate()
json_from_api = json.loads(from_api[0])
for unit_dict in json_from_api["values"]:
clone_cmd = "git clone " + unit_dict["links"]["clone"][1]["href"]
clone_cmd = clone_cmd.split()
clone_out = subprocess.call(clone_cmd, shell=False)
if "next" not in json_from_api:
break
else:
cmd[-1] = json_from_api["next"]
- 1. Bitbucket Server Api:克隆所有存儲庫
- 2. 無法從bitbucket克隆存儲庫
- 3. 使團隊克隆git倉庫
- 4. 如何使用單個腳本克隆所有git bitbucket存儲庫
- 5. 詹金斯mercurial克隆每個構建的Bitbucket存儲庫
- 6. git在克隆Bitbucket存儲庫時給出錯誤
- 7. 從bitbucket克隆存儲庫後顯示dll丟失錯誤
- 8. 無法從Ubuntu中的bitbucket克隆git存儲庫
- 9. OpenShift 3:無法克隆私人BitBucket存儲庫
- 10. 克隆存儲庫到GitHub
- 11. NGIT:克隆CodeCommit存儲庫
- 12. 克隆存儲庫和refspecs
- 13. Visual Studio團隊服務克隆命令
- 14. Github:克隆存儲庫,更改克隆,並提交原始庫
- 15. 我應該從git存儲庫克隆所有數據嗎?
- 16. 如何克隆所有分支的git存儲庫?
- 17. 如何更改團隊服務中的git存儲庫團隊
- 18. 克隆主存儲庫時未克隆子模塊
- 19. Git克隆 - 無法克隆遠程存儲庫
- 20. 無法使用bitbucket和Github克隆存儲... Java
- 21. 從bitbucket克隆項目
- 22. 無法在開發人員團隊中使用API創建Bitbucket存儲庫
- 23. 克隆和更新來自用戶的所有存儲庫,無需身份驗證在bitbucket
- 24. 克隆遠程git存儲庫問題
- 25. 使git克隆自己的存儲庫
- 26. 從github克隆存儲庫失敗
- 27. 無法克隆LibreOffice git存儲庫
- 28. 維護git存儲庫的克隆
- 29. 用於克隆GIT存儲庫的GUI
- 30. 無法提交到克隆存儲庫
如果您的存儲庫託管在Bitbucket上,爲什麼使用Github API? – larsks
錯字我打算說bitbucket – Imran
你是否認證?您認證的用戶是否可以訪問團隊信息庫?如果不是,我建議您設置一個應用程序密碼(在https:// bitbucket。org/account/user//app-passwords)具有足夠的權限(對帳戶/團隊成員資格/項目/存儲庫的讀取權限應涵蓋您需要的大部分內容)。 –
Dymos