我有一个脚本从GitHub的命令行创建一个git存储库, 所以我的问题是当我尝试使用我的脚本在GitLab中创建一个新的repo时,我的脚本不起作用!
repo_name=$1
dir_name=`basename $(pwd)`
if [ "$repo_name" = "" ]; then echo "Repo name (hit enter to use '$dir_name')?" read repo_name fi
if [ "$repo_name" = "" ]; then repo_name=$dir_name fi
username="xxxxxx" if [ "$username" = "" ]; then echo "Could not find username, run 'git config --global github.user <username>'" invalid_credentials=1 fi
token="xxxxxxxx" if [ "$token" = "" ]; then echo "Could not find token, run 'git config --global github.token <token>'" invalid_credentials=1 fi
echo -n "Creating Github repository '$repo_name' ..." curl -u "$username:$token" https://api.github.com/user/repos -d '{"name":"'$repo_name'"}' > /dev/null 2>&1 echo " done."
echo -n "Pushing local code to remote ..." git remote add origin git@github.com:$username/$repo_name.git > /dev/null 2>&1 git push -u origin master > /dev/null 2>&1 echo " done."
所以相当于这个
curl -u“$ username:$ token”https://api.github.com/user/repos -d '{ “名称”: “ '$ repo_name'”}'
在GitLab中?
谢谢你的阅读!答案 0 :(得分:2)
您可以尝试使用curl -H "Content-Type:application/json" https://gitlab.com/api/v3/projects?private_token=<your token> -d "{ \"name\": \"<new repo name>\" }"
(将gitlab url替换为您的服务器实例的url)