1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【CakePHP】github webhookとの連携

Last updated at Posted at 2018-04-12

github webhookとcakephpを連携させる手順を簡単にまとめておきます

やりたいこと

  • githubにpushされたら何かしらのアクションを起こしたい

github側での手順

  • 連携したいリモートリポジトリの「settings」を開く
    image.png
  • 左のメニューからwebhookをクリック
    image.png
  • add webhookをクリック
    image.png
  • payLoad URLには飛ばしたいコントローラのアクションまでのパスを書く
  • Which events would you like to trigger this webhook?の項だが今回はプッシュでのみ反応させたいので一番上を選ぶ
  • それ以外の項目は今回特に設定しない
  • 最後にadd webhook
    image.png
  • webhook一覧に先ほど作成したwebhookが表示されている。
    • クリックすると編集画面にいけるのだが、画面下部に通信履歴が表示される。
    • 通信成功していれば緑のチェックマークが出るので覚えておきましょう

cakephp側の設定

  • コントローラ側で適当な処理を書いてやればいいだけ
  • githubから送信される内容は$this->request->data['payload']で拾えます
    • payloadの見方は下記URLのEventsを参照
    • サーバーにIP制限をかけている場合はgithubからのアクセスを許可してやる必要があります。
      • https://api.github.com/meta
      • こちらのhooksに書かれているアドレスがgithubの外部向けIPアドレスとなっています
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?