概要
GitHub API を叩くとき、 https://api.github.com/~
といったURLにアクセスしますが、
Enerprise版で自前でサーバーを立てて独自ドメインで運営しており、どう置き換えればよいか分からなかったのでメモ。
認証API
curl -u "ユーザー名:パスワード" \
-d '{"scopes":["repo"],"note":"Hoge"}' \
https://自前のドメイン/api/v3/authorizations
こんな感じで、
https://api.github.com/~
は基本的には https://自前のドメイン/api/v3/~
に置き換えればOKな模様。
二要素認証を導入している場合は、
-H 'X-GitHub-OTP: 080673'
こんな感じでワンタイムパスワードをcurlのヘッダーオプションに指定。
(本当はワンタイムパスワードを使わずにトークン利用する方法もあると思うのですがうまくいかなかったので一旦)
{
"id": "xxx",
"url": "https://ドメイン/api/v3/authorizations/xxx",
"app": {
"name": "Hoge",
"url": "https://developer.github.com/enterprise/2.21/v3/oauth_authorizations/",
"client_id": "00000000000000000000"
},
"token": "xxxxxxxxxxxxxxxxxxxxxxxx",
"hashed_token": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"token_last_eight": "bbbbbbbbb",
"note": "Hoge",
"note_url": null,
"created_at": "2020-07-13T06:52:13Z",
"updated_at": "2020-07-13T06:52:13Z",
"scopes": [
"repo"
],
"fingerprint": null
}
このような結果が返ってくるので token
をメモ。
目的のAPIにアクセス
今回は、List pull requests のAPIでプルリクエスト一覧を取得しました。
URLが https://api.github.com/repos/:owner/:repo/pulls
となっているため、前述の方法でURLを置き換え。
curl -H "Authorization: token さっき取得したtoken値" \
"https://ドメイン/api/v3/repos/オーナー/リポジトリ名/pulls?page=1&state=all"
結果を取得できました。