
- 2024年10月
- 2021年5月
- 2020年8月
- 2020年6月
- 2020年5月
- 2019年1月
- 2018年8月
- 2018年6月
- 2018年5月
- 2018年3月
- 2018年1月
- 2017年12月
- 2017年11月
- 2017年10月
- 2017年9月
- 2017年8月
- 2017年7月
- 2017年6月
- 2016年11月
- 2013年9月
- 2013年8月
- 2013年6月
- 2013年5月
- 2013年4月
- 2013年3月
- 2013年2月
- 2013年1月
- 2012年12月
- 2012年11月
- 2012年10月
- 2012年9月
- 2012年6月
- 2012年5月
- 2012年4月
- 2012年2月
- 2011年7月
- 2011年5月
- 2011年4月
- 2011年2月
- 2010年12月
- 2010年11月
- 2010年10月
- 2010年9月
- 2010年8月
- 2010年7月
- 2010年6月
- 2010年5月
- 2010年4月
- 2010年3月
- 2010年2月
- 2010年1月
- 2009年12月
- 2008年2月
- 2008年1月
- 2007年12月
- 2007年5月
- 2007年4月
- 2007年3月
- 2007年2月
GitHub AppsでOrganizationにリポジトリを新規作成する / magicien
GitHub Appsでは、今のところユーザ用リポジトリの作成ができない。Organization用であれば作成できるようなので、作成までの手順をメモしておく。事前準備
Appの作成とJWT生成の準備は「GitHub Appsでリポジトリにファイル追加・更新」と同様に済ませておく。操作対象のOrganizationを決める
これも前回とほぼ同じなので流れだけ簡単に書いておく。ユーザを判別する
ユーザに下記URLへアクセスしてもらう。
https://github.com/login/oauth/authorize?child_id=ChildID&redirect_uri=自分のサイトのどこか&state=ランダムな文字列
戻ってきたリダイレクト先でcodeを取得する。
https://自分のサイト/どこかのページ.html?code=1234567890abcdef&state=先ほどのstate
アクセストークン生成
curl -X POST -d "code=先ほどのcode" -d "client_id=ClientID" -d "client_secret=ClientSecret" https://github.com/login/oauth/access_token
応答からアクセストークン取得
access_token=アクセストークン&scope=&token_type=bearer
ユーザが管理していてAppをインストール済みのOrganizationを取得する
取得方法はユーザのリポジトリを見つけるときと同じ。
curl -H "Authorization: token アクセストークン" -H "Accept: application/vnd.github.machine-man-preview+json" https://api.github.com/user/installations
Organization用のInstallationは、target_typeがOrganizationになっている(ユーザ用はUserになっている)。
{ "total_count": 1, "installations": [ { "id": 56789, "account": { "login": "Organization名", 中略 }, 中略 "integration_id": 1234, "app_id": 1234, "target_type": "Organization", 中略 } ], "integration_installations": [ { "id": 56789, "account": { "login": "Organization名", 中略 }, 中略 "integration_id": 1234, "app_id": 1234, "target_type": "Organization", 中略 } ] }installations[i].app_id が一致し、target_typeがOrganizationのものを見つける。 必要なのは、id(installationのid)とaccount.login(Organization名)。
Installationとしての認証
ここは前回と同じ。
curl -X POST -H "Authorization: Bearer JWTのトークン" -H "Accept: application/vnd.github.machine-man-preview+json" https://api.github.com/installations/先ほど取得したinstallationのid/access_tokens
応答も同じ。
{ "token": "アクセストークンその2", "expires_at": "2017-01-01T00:00:00Z" }
リポジトリを生成する
公式の説明はここ。最低限必要なパラメータはnameだけ。
curl -X POST -H "Authorization: token アクセストークンその2" -H "Accept: application/vnd.github.machine-man-preview+json" -d '{"name": "リポジトリ名"}' https://api.github.com/orgs/Organization名/repos
おしまい!
タグ:
この記事のURL: https://darkhorse2.0spec.jp/236/
2017/09/10(Sun) 17:09:58