2012-06-13
Gists API とコミットメッセージ
どーもこんちわ。Gists API*1はGiHub APIの一部だよ。
ここからコミットメッセージ取れないのが結構不便、っていうはなし
Gists API も統合
GitHub API が v3 に統合。v1, v2 は廃止
で、このAPI変更でGist APIも同じくv1廃止。ちょっと痛い
Gist API v1
こんな感じでアクセスするとJSONが返ってきてた。今は単に404が返ってくる
Get a Gist's Metadata
http://develop.github.com/p/gist.html
GET http://gist.github.com/api/v1/:format/:gist_id
JSONはすごくシンプルにできてる
$ curl http://gist.github.com/api/v1/json/823475{ "gists": [ { "comments": [ { "body": "Great stuff.", "created_at": "2011/03/31 00:19:46 -0700", "gravatar_id": "b8dbb1987e8e5318584865f880036796", "id": 25573, "updated_at": "2011/03/31 00:19:46 -0700", "user": "defunkt" } ], "created_at": "2011/02/11 19:39:21 -0800", "description": "I can't be bothered with all of these fancy…", "files": [ "deploy.rake" ], "owner": "peterc", "public": true, "repo": "823475" } ] }http://develop.github.com/p/gist.html
"files":
だけとりたい場合とか結構あったから使いたかったけど、deprecated ⇒ 廃止になったからあきらめよう
Gists API v3
統合されたv3は https://api.github.com/gists/2370972 な感じでアクセスする。ファイルの中身まで全部入ってる。
イケてないのがコミット履歴で、時間・ユーザ・アバターとか格納されてる割に、コミットメッセージが無い。
Gists API - Comments
Get a single gist
GET /gists/:id
{ "url": "https://api.github.com/gists/1", "id": "1", "description": "description of gist", "public": true, "user": { "login": "octocat", "id": 1, "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "somehexcode", "url": "https://api.github.com/users/octocat" }, "files": { "ring.erl": { "size": 932, "filename": "ring.erl", "raw_url": "https://gist.github.com/raw/365370/8c4d2d43d178df44f4c03a7f2ac0ff512853564e/ring.erl", "content": "contents of gist" } }, "comments": 0, "html_url": "https://gist.github.com/1", "git_pull_url": "git://gist.github.com/1.git", "git_push_url": "git@gist.github.com:1.git", "created_at": "2010-04-14T02:15:15Z", "forks": [ { "user": { "login": "octocat", "id": 1, "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "somehexcode", "url": "https://api.github.com/users/octocat" }, "url": "https://api.github.com/gists/5", "created_at": "2011-04-14T16:00:49Z" } ], "history": [ { "url": "https://api.github.com/gists/1/57a7f021a713b1c5a6a199b54cc514735d2d462f", "version": "57a7f021a713b1c5a6a199b54cc514735d2d462f", "user": { "login": "octocat", "id": 1, "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "somehexcode", "url": "https://api.github.com/users/octocat" }, "change_status": { "deletions": 0, "additions": 180, "total": 180 }, "committed_at": "2010-04-14T02:15:15Z" } ] }http://developer.github.com/v3/gists/
UserScriptとかでAPIアクセスするときにv1で十分だったケースでも、v3統合で必要ないデータもとって来ることになった。
「JSON.parse()
するから同じじゃん」って感じかもしれないけど、
って面もある。それでも、データ的にはv1と後方互換があるからGitHubとしてはずーっと1本化したかったんだろーね
GitHub Mime Types
返してほしいデータ指定はリンク先のようにMIME-typeの指定でやるみたい
こんな風になってる
Raw | application/vnd.github.VERSION.raw+json |
---|---|
Text | application/vnd.github.VERSION.text+json |
Html | application/vnd.github.VERSION.html+json |
Full | application/vnd.github.VERSION.full+json |
んー、全部+json
て付いてるのがよくわからないけど、これは単にデータ種を決定するだけっぽい。
APIからの取得データが部分指定可能なら「取りたいやつだけ指定してリクエスト」とかできてうれしいんだけど、そもそも無いのかまだ見つけれてない
Gistのコミットメッセージ取得
本題だけどGists API v3でもどうにもならないのがこれ。APIからは取れないのでどうするか、っていうところ
どう取得してるか
仕方ないからGM_xmlhttpRequest
で、そのGistが持ってる https://raw.github.com/gist/@GistID@/@rev-SHA-1@ にリクエストバンバン飛ばすしかない。というようなことを前にも書いたし、実際 サーバのリクエスト拒否におびえつつ、最大1 + 10回もリクエストして取得 ていうマヌケな実装になっちゃう。かなしいし、GitHubのサーバにも良くない。
コミットメッセージがAPIで取れるようになれば1リクエストですむかもしれないのに、なぜ入れないんだろうね、という。Issue出すしかないのかなー
Git Data
これはGitHubのrepoのAPIでGistには使えないっぽいんだけども。実はこっちにはちゃんとコミットメッセージがある
Commits API - Commits
Get a Commit
GET /repos/:user/:repo/git/commits/:sha
{ "sha": "7638417db6d59f3c431d3e1f261cc637155684cd", "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/7638417db6d59f3c431d3e1f261cc637155684cd", "author": { "date": "2010-04-10T14:10:01-07:00", "name": "Scott Chacon", "email": "schacon@gmail.com" }, "committer": { "date": "2010-04-10T14:10:01-07:00", "name": "Scott Chacon", "email": "schacon@gmail.com" }, "message": "added readme, because im a good github citizen\n", "tree": { "url": "https://api.github.com/repos/octocat/Hello-World/git/trees/691272480426f78a0138979dd3ce63b77f706feb", "sha": "691272480426f78a0138979dd3ce63b77f706feb" }, "parents": [ { "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/1acc419d4d6a9ce985db7be48c6349a0475975b5", "sha": "1acc419d4d6a9ce985db7be48c6349a0475975b5" } ] }no title
ほらほら、ちゃっかり"message": "added readme, because im a good github citizen\n"
が取れる。ぬおっー
GitHub社的なGistの考え方
おそらくGistはPastebinみたく貼り付けが主眼で、Git越しに使うことを重視してないんじゃないのかなと。
「ブラウザからペトペトするんだからmessage
ってGistの場合description
でしょ?だからAPIにはいらねーんじゃねーの」
って考えてるんじゃないかって想像した