drone.io APIドキュメント

この記事は drone.io Advent Calendar 2017 - Adventar20日目の記事です。

drone.io は Goで作られたオープンソースのCD (Continuous Delivery)環境です。

github.com

drone.io にはそこそこしっかりしたAPIがあるのですが、http://docs.drone.io/api-overview/ をみてがっかりしたかもしれません。

暫定的なAPIドキュメントを起こしておいたので公式サイトが整備されるまではご利用ください。

APIキーは https://drone.exmaple.com/account/token から取得してください。

Drone API

Current User
  • GET /api/user
    • アクセスしているユーザの情報
{
  "id": 1,
  "login": "ashphy",
  "email": "ashphy@ashphy.com",
  "avatar_url": "https://avatars3.githubusercontent.com/u/413896?",
  "active": false,
  "synced": 1513512678,
  "admin": true
}
Users (admin専用)
  • GET /api/users
    • ユーザ一覧
  • POST /api/users
    • ユーザ作成
  • GET /:login
    • 特定のユーザ情報
  • PATCH /:login
    • ユーザ情報の更新
  • DELETE /:login
    • ユーザの削除
Repos
{
  "id": 1,
  "owner": "hoge",
  "name": "drone-test",
  "full_name": "hoge/drone-test",
  "avatar_url": "https://drone.example.com/avatars/u/9999?",
  "link_url": "https://drone.example.com/hoge/drone-test",
  "scm": "git",
  "clone_url": "https://drone.example.com/hoge/drone-test.git",
  "default_branch": "master",
  "timeout": 60,
  "visibility": "public",
  "private": false,
  "trusted": true,
  "gated": true,
  "active": true,
  "allow_pr": true,
  "allow_push": true,
  "allow_deploys": true,
  "allow_tags": true,
  "last_build": 999,
  "config_file": ".drone.yml"
}
Builds
  • GET /api/repos/:owner/:name/builds
    • ビルドの一覧
[{
  "id": 1,
  "number": 1,
  "parent": 0,
  "event": "push",
  "status": "success",
  "error": "",
  "enqueued_at": 1513007740,
  "created_at": 1513007740,
  "started_at": 1513007740,
  "finished_at": 1513007754,
  "deploy_to": "",
  "commit": "91b0c8f8ea9a479cab3708ca40273df8",
  "branch": "master",
  "ref": "refs/heads/master",
  "refspec": "",
  "remote": "https://drone.example.com/ci/drone-test.git",
  "title": "",
  "message": "commit massage",
  "timestamp": 0,
  "sender": "ashphy",
  "author": "ashphy",
  "author_avatar": "https://drone.example.com/avatars/u/17?",
  "author_email": "ashphy@ashphy.com",
  "link_url": "https://drone.example.com/hoge/drone-test/commit/91b0c8f8ea9a479cab3708ca40273df8",
  "signed": false,
  "verified": true,
  "reviewed_by": "",
  "reviewed_at": 0
}]
  • GET /api/repos/:owner/:name/builds/:number
    • 特定のビルド情報
  • POST /api/repos/:owner/:name/builds/:number
    • ビルドの再実行
  • DELETE /api/repos/:owner/:name/builds/:number
    • admin専用 実行中のまま終わらなくなってしまったビルドのゾンビプロセスを殺す。
Logs
  • GET /api/repos/:owner/:name/logs/:number/:pid
    • ビルド中の出力
[{
  "proc": "rebuild-cache",
  "pos": 57,
  "out": "time=\"2017-12-11T15:55:49Z\" level=debug msg=\"Directory found at vendor/bundle"\n"
}]
  • GET /api/repos/:owner/:name/logs/:number/:pid/:proc
    • プロセスごとの出力
Files

なんか成果物を保存できる機能があるらしい? Enterprise専用かもしれない。

  • GET /api/repos/:owner/:name/files/:number
  • GET /api/repos/:owner/:name/files/:number/:proc/*file
Secrets
  • GET /api/repos/:owner/:name/secrets
    • secretの一覧
  {
    "id": 9999,
    "name": "downstream_token",
    "image": null,
    "event": [
      "push",
      "tag",
      "deployment"
    ]
  }
]
  • POST /api/repos/:owner/:name/secrets
    • secretの設定
  • GET /api/repos/:owner/:name/secrets/:secret
    • secret情報
  • PATCH /api/repos/:owner/:name/secrets/:secret
    • secret更新
  • DELETE /api/repos/:owner/:name/secrets/:secret
    • secret削除
Registry
  • GET /api/repos/:owner/:name/registry
  • POST /api/repos/:owner/:name/registry
  • GET /api/repos/:owner/:name/registry/:registry
  • PATCH /api/repos/:owner/:name/registry/:registry
  • DELETE /api/repos/:owner/:name/registry/:registry
Repo設定変更 (admin専用)
  • PATCH /api/repos/:owner/:name
  • DELETE /api/repos/:owner/:name
  • POST /api/repos/:owner/:name/chown
  • POST /api/repos/:owner/:name/repair
    • DeactivateしてからActivateし直す。リポジトリ側との連携がおかしくなった場合に直せるかもしれない。
  • POST /api/repos/:owner/:name/move
Gated Builds

おそらくGated Build用。ただGated Buildがうまく動かないので未検証。  - POST /api/repos/:owner/:name/builds/:number/approve - POST /api/repos/:owner/:name/builds/:number/decline

Job
  • DELETE /api/repos/:owner/:name/builds/:number/:job
    • 実行中ビルドのキャンセル
Badges
  • GET /api/badges/:owner/:name/status.svg
    • ビルドステータス表示用のバッジ
  • GET /api/badges/:owner/:name/cc.xml
    • CCMenu用の設定ファイル
Queue (admin専用)
  • GET /api/info/queue
    • ビルドキューの情報
{
  "pending": null,
  "running": null,
  "stats": {
    "worker_count": 4,
    "pending_count": 0,
    "running_count": 0,
    "completed_count": 0
  }
}
Builds (admin専用)
  • GET /api/builds
    • 実行中のビルド情報
[
  {
    "owner": "hoge",
    "name": "drone-test",
    "full_name": "hoge/drone-test",
    "number": 9999,
    "event": "push",
    "status": "running",
    "created_at": 1513595666,
    "started_at": 1513595666,
    "commit": "91b0c8f8ea9a479cab3708ca40273df8",
    "branch": "master",
    "ref": "refs/heads/master",
    "remote": "https://drone.example.com/foo/bar.git",
    "message": "commit log",
    "author": "ashphy",
    "author_avatar": "https://drone.example.com/avatars/u/9999?",
    "author_email": "ashphy@ashphy.com"
  }
]

リクエストパラメータは要望があれば調べます...