我正在尝试使用github api在特定组织下创建存储库。我在看这个site,讨论如何在特定组织下创建存储库。
Create a new repository in this organization. The authenticated user must be a member of the specified organization.
POST /orgs/:org/repos
现在我无法理解在特定组织下创建存储库需要使用的完整URL是什么?我有我的用户名和密码,可用于通过https url在组织下创建存储库。
我的github实例网址就像这样 - https://github.host.com
我希望我的存储库在创建之后就像这样 -
https://github.host.com/Database/ClientService
我的curl命令会在组织下创建存储库吗?
答案 0 :(得分:6)
第1步:创建个人access token
并使用它代替密码
步骤2:在命令行上使用给定的API作为POST
请求
https://api.github.com/orgs/<organisation_name>/repos?access_token=<generated token>
或
https://api.github.com/users/<username>/repos?access_token=<generated token>
在正文中,将其作为有效载荷传递:
{
"name": "<Repo Name>",
"description": "<Some message>",
"homepage": "https://github.com",
"private": false,
}
您可以根据要求传递其他详细信息。
更多详情:click here
答案 1 :(得分:2)
cli.github.com有一位新的解决方案官员。不建议使用其他答案。
首先安装GitHub CLI。运行:
brew install github/gh/gh
然后创建一个具有特定名称的存储库(默认:private)输入以下命令:
gh repo create my-project
这是创建存储库的官方文档link。
答案 2 :(得分:1)
基于以上两个答案,这是一个bash >=4.2
脚本,用于创建仓库的克隆。
#!/usr/bin/env bash
TOKEN=0000000000000000000000000000000000000000
if [[ $# < 3 ]]; then
echo "arguments: $0 <RepoName> <RepoDescription>"
exit 1
fi
REPO_NAME=$1; shift
REPO_DESCRIPTION="$@"
echo "Name: $REPO_NAME"
echo "Description: $REPO_DESCRIPTION"
echo "Calling GitHub to create repo"
read -r -d '' PAYLOAD <<EOP
{
"name": "$REPO_NAME",
"description": "$REPO_DESCRIPTION",
"homepage": "https://github.com/$REPO_NAME",
"private": false
}
EOP
shopt -s lastpipe
curl -H "Authorization: token $TOKEN" --data "$PAYLOAD" \
https://api.github.com/user/repos | readarray output
url=''
for line in "${output[@]}"; do
echo -n "$line"
# "html_url": "https://github.com/sfinktah/vim-hex-sum",
if [[ $line == *html_url* ]]; then
l=${line#*\"}; l=${l#*\"}; l=${l#*\"}; url=${l%\"*}
fi
done
count=0
[[ $url == http*://*github.com/* ]] &&
until git clone $url; do
sleep 10; (( count++ > 5 )) && break; echo Waiting...
done
答案 3 :(得分:0)
转到OAuth应用下的设置-> 开发人员设置-> 个人访问令牌。现在,生成一个启用了“必需”特权的新访问令牌。 如果您已经有一个,则忽略它。
在以下命令中,将ACCESS_TOKEN
替换为Token
,并将NEW_REPO_NAME
替换为新存储库Name
:
curl -H "Authorization: token ACCESS_TOKEN" --data '{"name":"NEW_REPO_NAME"}' https://api.github.com/user/repos
curl -H "Authorization: token ACCESS_TOKEN" --data '{"name":"NEW_REPO_NAME"}' https://api.github.com/orgs/ORGANISATION_NAME/repos
答案 4 :(得分:0)
答案 5 :(得分:0)
在企业热的 github 中创建 repo..为我工作
,请在执行前更改尖括号中的值
-put username:token after -u
curl -u https://github.com/api/v3/orgs//repos -d '{"name":""}
答案 6 :(得分:0)
推荐Github SDK Octokit。要创建存储库:
const octokit = new Octokit({ auth: `personal-access-token123` });
// Create a repo for user.
octokit.rest.repos.createForAuthenticatedUser({
name,
});
// Create a repo in an organization.
octokit.rest.repos.createInOrg({
org,
name,
});