Check if BitBucket Repository Exist via Command Line

时间:2019-04-08 13:33:47

标签: bash git shell curl bitbucket

I know how to create a repo in BitBucket by doing this.

Let email = john@outlook.com, and password 123

curl -k -X POST --user john@outlook.com:123 "https://api.bitbucket.org/1.0/repositories" -d "name=test"

But how would one check if a repo exist in BitBucket programmatically ?

1 个答案:

答案 0 :(得分:1)

这是我接到公开,私人和不存在的回购协议的电话:

私人(状态代码403):

> curl -k -X GET https://api.bitbucket.org/1.0/repositories/padawin/some-private-repo
Forbidden

不存在(状态代码404):

> curl -k -X GET https://api.bitbucket.org/1.0/repositories/padawin/travels1
{"type": "error", "error": {"message": "Repository padawin/travels1 not found"}}

公开(状态码200):

> curl -k -X GET https://api.bitbucket.org/1.0/repositories/padawin/travels
{"scm": "git", "has_wiki": false, "last_updated": "2015-08-02T14:09:42.134", "no_forks": false, "forks_count": 0, "created_on": "2014-06-08T23:48:28.483", "owner": "padawin", "logo": "https://bytebucket.org/ravatar/%7Bb56f8d55-4821-4c89-abbc-7c1838fb68a3%7D?ts=default", "email_mailinglist": "", "is_mq": false, "size": 1194864, "read_only": false, "fork_of": null, "mq_of": null, "followers_count": 1, "state": "available", "utc_created_on": "2014-06-08 21:48:28+00:00", "website": "", "description": "", "has_issues": false, "is_fork": false, "slug": "travels", "is_private": false, "name": "travels", "language": "", "utc_last_updated": "2015-08-02 12:09:42+00:00", "no_public_forks": false, "creator": null, "resource_uri": "/api/1.0/repositories/padawin/travels"}

鉴于正文并非始终是有效的JSON(Forbidden必须为"Forbidden"为有效的JSON),您可以使用状态代码。