我有以下脚本,我正在尝试在 bash 中测试它,使用curl 做几件事,一是创建一个新的存储库,第二个 - 尚未实现 - 是从 json 中获取 git_url返回,我不确定我的是否parse_json
函数将让我这样做,然后最后将示例提交消息推送到该存储库。
脚本如下:
#!/usr/bin/env bash
set -eux
# Json Function: parse_json 'json string' key
function parse_json()
{
echo $1 | sed -e 's/[{}]/''/g' | awk -F=':' -v RS=',' "\$1~/\"$2\"/ {print}" | sed -e "s/\"$2\"://" | tr -d "\n\t" | sed -e 's/\\"/"/g' | sed -e 's/\\\\/\\/g' | sed -e 's/^[ \t]*//g' | sed -e 's/^"//' -e 's/"$//'
}
git_create_repo() {
read -e -p "Please enter your API Key: " apiKey
read -e -p "Repo Name: " repoName
read -e -p "Repo Description: " repoDescription
# Use the API to create a a repository
response=$(curl -i -H 'Authorization: token $apiKey' \
-d '{ \
"name": "$repoName", \
"description": "$repoDescription", \
"private": false, \
"license_template": "mit" \
}' \
https://api.github.com/AdamKyle/repos)
echo $response
}
git_create_repo
当我完成所有步骤时,我得到:
{
"message": "Bad credentials",
"documentation_url": "https://developer.github.com/v3"
}
我想知道这是否是因为我输入 api 密钥的方式:curl -i -H 'Authorization: token $apiKey ...'
我努力了"$apiKey"
但即使这样也行不通。
Ideas?
我这样使用它:
curl -X 'POST' -u $MY_AUTH https://api.github.com/...
其中 $MY_AUTH 是在 github 网站中生成的。看起来像:
export MY_AUTH="...hash...:x-oauth-basic"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)