Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
PHP + GitHub + Azure Functions = ?
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
sakuragawa
February 28, 2017
Programming
270
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
PHP + GitHub + Azure Functions = ?
sakuragawa
February 28, 2017
Transcript
24 slides
PHP + GitHub + Azure Functions = ?
自己紹介 株式会社Fusic マネージャー 技術開発部 基盤ユニット 櫻川 幸三 https://github.com/kozo https://github.com/fusic http://qiita.com/kozo
http://qiita.com/organizations/fusic http://fusic-kiban.hatenablog.com/ 2
3 PHP?GitHub?Azure? 何をしたいの?
4
5 で、どうやって作るの?
6 実はものすごく簡単
作り方の流れ 1. GitHubアプリケーションの設定 2. OAuth認証 3. WebHookの設定 4. GitHubAPIの実行 7
GitHubアプリケーションの設定 8 [GitHub] - [Settings] - [OAuth applications] - [Register
a new application]
GitHubアプリケーションの設定 9 ※Client ID、Client Secretを控えておく
作り方の流れ 1. GitHubアプリケーションの設定 2. OAuth認証 3. WebHookの設定 4. GitHubAPIの実行 10
2. OAuth認証1 11 https://github.com/login/oauth/authorize? client_id={Client ID}&scope=repo,admin:repo_hook - client_id : アプリケーションの作成をしたときに取得したもの
- scope : 取得したい権限(複数ある場合はカンマで区切る) - repo : ソースコードへのread,write、ステータス、コメント等 - admin:repo_hook : read,write,delete等のHook用 ※scopeは最低限を設定するようにする
2. OAuth認証1 12 「Authorize application」ボタンをクリックすることで、 アプリ作成したときに入力した「callback url」に戻ってくる。
2. OAuth認証2 13 http://example.com/oauths/callback?code={コード} - code : GitHubからcallback URLにコードが戻ってくる
2. OAuth認証3 14 https://github.com/login/oauth/access_token? code={コード}& client_id={Client ID}& client_secret={Client Secret} -
code : GitHubからcallback URLに戻ってきたコード - client_id : GitHubのアプリ作成で控えておいたClinet ID - client_secret : GitHubのアプリ作成で控えておいたClient Secret URLを作成したら、file_get_contents等を利用してURLをたたくと、 AccessTokenが取得できる。 AccessTokenを利用して、GitHub APIを実行します。
15 これで準備完了
3. Web Hookの設定 16 /repos/{:owner}/{:repo}/hooks $data = [ 'name' =>
'web', "active" => true, "events" => [ "push", "pull_request" ], "config" => [ "url" => "https://gitfusic.azurewebsites.net/api/hook2", "content_type" => "json" ] ]; APIを実行して、Hookの設定を行う。 ※プルリク作成、pushしたタイミングでHookする等 JSON化してPOSTする - events : hookしたい処理 - url : hookしたときに実行されたいURL
3. GitHub APIの実行 17 /repos/{:owner}/{:repo}/statuses/{:sha} $data = [ 'state' =>
'success', "target_url" => "https://example.com/build/status", "description" => "いいコード書いたね!", "context" => "LGTM!!" ]; APIを実行することで、ステータスを切り替える。 JSON化してPOSTする - status : “pending”,“success”,“error”,“failure”のいづれかを指定 - sha : hookしたときにGitHubからPOSTで飛んでくる
3. その他API 18 /repos/{:owner}/{:repo}/issues/{:num}/comments - プルリクにコメントをつける /repos/{:owner}/{:repo}/issues/{:num}/assignees -プルリクのアサインを追加する /repos/{:owner}/{:repo}/labels /repos/{:owner}/{:repo}/issues/{:num}/labels
- ラベルの作成・追加する
3. API注意点 19 - User-Agentにアプリケーションの名前を設定する - ヘッダーにAccessTokenを設定する
他にも色々できそう - リポジトリを作成したときに、自動でラベルを 作成しておく。 - プルリク作ったタイミングで、アサインやラベ ルを自動で登録しておく。 - いいね!の数をランキングする 20
21 で、Azureはどうなん?
24 URLを作る ファイルを修正 ファイルをアップ
Azure Functions注意点 - echo等標準出力はすべてログに出力される - レスポンスを返すには以下を利用する - file_put_contents(getenv('res'), json_encode($resList)); -
リクエストを受け取るには以下を利用する - $post = file_get_contents(getenv('req')); - $_POST等は利用できない 25
ご清聴ありがとうございました Fusicはテクノロジーが 好きなエンジニアを募集しています https://fusic.github.io 26
More Decks by sakuragawa
See All by sakuragawa
CircleCI APIでプチ効率化
sakuragawa
1
610
今こそCakePHP3に乗り換えよう!/php_conference_fukuoka_2016
sakuragawa
0
1.2k
CakePHP2と3の違い
sakuragawa
8
4.9k
Other Decks in Programming
See All in Programming
AIがコードを書いてくれる時代、我々は何を確かめるのか
yosuke_furukawa
PRO
13
6.1k
imagewebp()の向こう側: WebPはなぜ JPEG・PNGより軽いのか
yuzneri
0
130
Enforcing Your Architecture with Unit Tests in the AI Era (Swift Connection X)
steliosf
PRO
1
190
コード生成時代のAPI定義を支えるRequest Spec移行
pvcresin
0
260
手の動かし方がわからなかった私が個人開発者になるまで
usagi0920_pochi
0
260
はじめてのPLATEAU
nokonoko1203
1
660
動画プレイヤーはなぜカクつくのか 〜Flutterのレンダリングとネイティブの境界を解剖する〜
naruogram
0
340
protojson における文字化けの扱い
kazuki1023
0
440
疎結合とは何か?ソフトウェア設計における結合バランスについて考える #phpcon_niigata
kajitack
2
320
学びを記事・スライド・Xへ高速展開する― AI-assisted Learning Loopで回すコンテンツ生成術
ochtum
0
210
まずはコードより業務と向き合う:テーブル解体のためにPdMを呼んだ話
sakawe_ee
0
250
Debian JP Projectのサーバー構成
uwabami
1
130
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
3k
What the history of the web can teach us about the future of AI
inesmontani
PRO
3
810
Making the Leap to Tech Lead
cromwellryan
135
10k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
690
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
3k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
350
RailsConf 2023
tenderlove
30
1.6k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.4k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Practical Orchestrator
shlominoach
192
12k