Skip to content

Commit f9e1578

Browse files
committed
bitbucket : repo functions handle create of repo better
1 parent 4046ea8 commit f9e1578

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

bitbucket/_bitbucket_repo_functions.sh

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
curl_PUT_cmd="curl --fail -D- --insecure --netrc-file ${netrc_file} -X PUT"
44
curl_DELETE_cmd="curl --fail -D- --insecure --netrc-file ${netrc_file} -X DELETE"
55
curl_POST_cmd="curl --fail -D- --insecure --netrc-file ${netrc_file} -X POST -H Content-Type:application/json "
6+
curl_POST_nofail_cmd="curl --insecure --netrc-file ${netrc_file} -X POST -H Content-Type:application/json "
67

78
function generate_restriction_json {
89
local _restriction_type=$1
@@ -154,8 +155,23 @@ function create_repo {
154155
else
155156
local _push_type=$4
156157
fi
157-
158-
${curl_POST_cmd} ${_bitbucket_url}/rest/api/1.0/projects/${_bitbucket_project}/repos -d "{ \"name\":\"${_repo_name}\", \"forkable\":true }"
158+
#-w "%{stderr}{\"status\": \"%{http_code}\", \"body\":\"%{stdout}\"}"
159+
reponse_json=$(${curl_POST_nofail_cmd} -sS -w ",{ \"status\": \"%{http_code}\" }" ${_bitbucket_url}/rest/api/1.0/projects/${_bitbucket_project}/repos -d "{ \"name\":\"${_repo_name}\", \"forkable\":true }" )
160+
reponse_code=$(echo "[$reponse_json]" | jq -r .[1].status )
161+
case $reponse_code in
162+
201)
163+
echo "All good - repo created"
164+
;;
165+
409)
166+
echo "Skip - repo already exists"
167+
echo "[$reponse_json]" | jq -r .[0].errors[]
168+
;;
169+
*)
170+
echo "ERROR - something when wrong"
171+
echo "[$reponse_json]" | jq -r .[0].errors[]
172+
exit 1
173+
;;
174+
esac
159175

160176
# Fill repo
161177
if [ -d ${_repo_name} ]; then

0 commit comments

Comments
 (0)