如何通过 Github API 创建组织名称而不是手动创建?

How to create Organization name through Github API instead of creating manually?

我正在尝试使用 github api 创建组织和存储库,而不是手动创建它们。我在看这个 site,它讨论了如何在特定组织下创建存储库。

我的github实例url是这样的-https://github.host.com

我希望我的存储库在创建后是这样的 -

https://github.host.com/Mobile/CustomerSystem

这里 Mobile 是组织名称,CustomerSystem 是存储库名称。就我而言,我之前没有创建 Mobile 组织名称,因为我想通过 Github API 以及存储库创建它。

所以我在 curl url 下面执行,认为它也会在它们下面创建组织名称和存储库,但每次我得到 404 Not Found -

curl -i -u david -d '{ "name": "CustomerSystem", "auto_init": true, "private": true, "gitignore_template": "nanoc" }' https://github.host.com/api/v3/orgs/Mobile/repos

下面是我得到的结果 -

HTTP/1.1 404 Not Found
Server: GitHub.com
Date: Sat, 07 Feb 2015 20:43:32 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 102
Status: 404 Not Found
X-GitHub-Media-Type: github.v3
X-XSS-Protection: 1; mode=block
X-Frame-Options: deny
Content-Security-Policy: default-src 'none'
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
Access-Control-Allow-Origin: *
X-GitHub-Request-Id: fv4af52e-617c-4ga1-br2f-5cb51b1df3bb
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
X-Content-Type-Options: nosniff

{
  "message": "Not Found",
  "documentation_url": "https://developer.github.com/enterprise/2.0/v3"
}

我做错了什么吗?

在我看来,如果组织名称已经创建,那么我上面的 CURL 调用工作正常,并且存储库创建正常,没有任何问题。但是,如果组织名称不存在,则会给我 404 错误消息。

有什么方法可以通过 github API 创建组织名称吗?在某些情况下,我可能之前已经创建了组织名称,所以我会在它们下面创建新的存储库,但在某些情况下,我可能之前没有创建组织名称,所以我需要通过 Github API.

您可以查看 go-gihub proposes to manage an organization, reflecting the Organization API 这样的包装器。

您可以列出、获取或编辑组织,但显然不能创建

Is there any way to create organization name as well through github API?

目前无法通过 GitHub API.

创建组织或用户帐户

你可以试试这样的

curl --include -u victor-raul-hernandez-contreras:your-personal-access-token-here -X POST https://github.hpe.com/api/v3/admin/organizations --data '{"login":"loko200","profile_name":"lokosoft, inc.", "admin":"victor-raul-hernandez-contreras"}'

它在 github 企业对我有用。

GitHub 并没有为此提供 public api。

但是说如果你想自动化组织创建过程,你可以检查网络 activity(在你的浏览器中按 F12 并导航到网络选项卡)在这个页面

https://github.com/account/organizations/new

找出用于检查名称可用性和创建组织的私有 api,然后将请求导出为 curl 命令,将其放入 shell 脚本并参数化组织名称。

我不会在这里详细介绍或 post 我的脚本,因为脚本编写起来相当简单,它会泄露我的浏览器 cookie 和会话信息

顺便说一句,如果您使用的是 GitHub 企业版,那么它会记录在此处

https://developer.github.com/enterprise/2.16/v3/enterprise-admin/orgs/ https://github.com/aws-quickstart/quickstart-github-enterprise/blob/master/scripts/adminuser_org_repo.sh

更新:

警告!!! 注意不要创建太多组织。我目前已经使用我的个人帐户创建了 500 多个组织。现在,每次我登录帐户访问 github 上的页面时,它要么需要几秒钟加载,要么根本不加载,显示 https://github.com/503.html 之类的独角兽页面。如果我注销我的帐户,该页面会再次加载 quickly。我几乎已经放弃使用 github 网络 ui。