Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Hubot事例

Affc58cd0f63630fb0c5bcec49902546?s=47 ryonext
January 21, 2015

 Hubot事例

弊社のHubotとSlack連携の活用事例です。

Affc58cd0f63630fb0c5bcec49902546?s=128

ryonext

January 21, 2015
Tweet

Transcript

  1. ฐࣾͷHubotࣄྫ

  2. ࣗݾ঺հ Twitter ID: ryonext Unicon ͱ͍͏ձࣾͰRailsॻ͍ͯ·͢ɻ PS4ങ͍·ͨ͠ 2014೥ՆΠϕΫϦΞ·Ͱ΍͙ͬͨΒ͍ͷఏಜͩ ͚Ͳ͖ͬͺΓ΍ΊͨͷͰ؋͜ΕΞχϝݟͯ·ͤΜ

  3. Hubotࣄྫ

  4. develop ͔Β master΁ ͷ pull request Λ࡞Δ ඞཁͳαʔϏε Circle CI

    ΋ͪΖΜ J但 Ͱ΋͍͚Δ masterʹϚʔδ͞ΕͨΒ ͦͷ··ຊ൪σϓϩ Π·Ͱ૸ΔΑ͏ʹͯ͠Δલఏ
  5. σϓϩΠ͍ͨ͠ͱ͖ʹ develop => master ΁ͷ pull req Λ࡞Δͱ͍͏ϧʔνϯϫʔΫ͕ͳ͘ͳ Γੜ࢈ੑͷ޲্ʹͭͳ͕Δ

  6. pull req ҰཡΛग़͢ hubot show org-pulls ͱ͍͏ίϚϯυ ͜ΕΛ࢖ͬͯΔ hubot-scripts/github-pulls.coffee at

    master · github/hubot-scripts https:/ /github.com/github/ hubot-scripts/blob/master/src/scripts/github- pulls.coffee ࠓ্͕͍ͬͯΔpull requestΛશ෦ग़͢ ޙड़ͷ cron ͱ૊Έ߹Θͤͯ࢖͏΂͖
  7. ΤϯδχΞ͕ࣗൃతʹpull requestΛݟʹߦ͘ඞཁ͕ͳ͘ͳΓɺ͔͠΋଺ཹ͍ͯ͠Δpull request Λݟ͚ͭΔ͜ͱ΋ՄೳʹͳΓੜ࢈ੑͷ޲্ʹͭͳ͕Δ

  8. cron ఆظతʹಛఆͷൃݴΛͤ͞Δ ͜Ε࢖ͬͯΔ ncb000gt/node-cron https:/ / github.com/ncb000gt/node-cron ձٞͷϦϚΠϯυΛͨ͠Γɺલड़ͷpull req ҰཡΛݺͼग़ͨ͠Γɺ࢖͍ํ͸ࣗ༝ࣗࡏ

    ఆظతʹඞཁͳॲཧΛࣗಈ࣮ߦͯ͘͠ΕΔ͜ͱʹΑΓੜ࢈ੑͷ޲্ʹͭͳ͕Δ
  9. cronࣄྫ1 pull requestͷ௨஌ ຖ೔ܾ·ͬͨ࣌ؒʹͳͬͨΒ hubot show org-pulls Λ࣮ߦ͠ɺpull request ҰཡΛ

    ग़͢ ຖ೔ܾ·ͬͨ࣌ؒʹ࢒͍ͬͯΔpull requestΛදࣔ͢Δ͜ͱʹΑΓɺϨϏϡʔ͕ଅਐ͞Εੜ࢈ੑͷ޲ ্ʹͭͳ͕Δ
  10. cronࣄྫ2 ேձ&༦ձ + Google Hangouts URLͷ௨ ஌ ܾ·ͬͨ࣌ؒʹேձ/༦ձͷ௨஌ͱɺϦϞʔτ ۈ຿ऀ༻ʹGoogle HangoutsͷURLΛ౤ߘ

    ͢Δ͜ͱʹΑΓεϜʔζͳձٞͷ։͕࢝Ͱ͖Δ
  11. ேձʗ༦ձʹ஗ΕΔ͜ͱ͕ͳ͘ͳΓɺHangoutsͷURLΛ୳͢ख͕ؒল͚ͯੜ࢈ੑͷ޲্ʹͭͳ͕Δ

  12. cronࣄྫ 3 9࣌ʹͳͬͨΒࠓ೔΋1೔ؤுΔܾҙΛࣔ͢ը૾ ΛషΔ ࠓ೔΋Ұ೔ؤுΕͦ͏ͳը૾ΛݟΔ͜ͱʹΑΓੜ࢈ੑ޲্ʹͭͳ͕Δ ͨͩ͠ϑϨοΫε͔ͩΒ9͔࣌Βಇ͍͍ͯΔਓ͕গͳ͍

  13. cronࣄྫ3 ͓΍ͭͷ࣌ؒΛ௨஌͢Δ 15࣌Λ௨஌͢Δ͜ͱͰɺΤϯδχΞʹ౶෼ิڅΛଅ͠ɺੜ࢈ੑͷ޲্ʹͭͳ͕Δ

  14. cronࣄྫ4 ਐḿͷ֬ೝ ϥϯνΛ৯΂ͯɺ͓΍ͭΛ৯΂ͯɺੜ࢈ੑ͕ۃݶ·Ͱߴ·ͬͨΤϯδχΞ͕ͦͷྗΛ༨͢͜ͱແ͘ൃش͠ ͨ͋ͨΓͰͦͷ੒ՌΛ֬ೝ͢Δ͜ͱͰϞνϕʔγϣϯ͕Ξοϓ͠ɺੜ࢈ੑͷ޲্ʹͭͳ͕Δ

  15. cronࣄྫ5 ՖۚΛ௨஌͢Δ ͨ͠ͳΊΔ ༵ۚ೔ͷָ͠͞Λ௨஌͢Δͱͱ΋ʹɺؾΛҾ͖కΊΔ͜ͱ͕Ͱ͖ੜ࢈ੑͷ޲্ʹͭͳ͕Δ

  16. ͔͜͜Βৄࡉฤ

  17. શମߏ੒ GitHubͷνʔϜΞΧ΢ϯτ͕2ͭ͋ΔͨΊɺऔ ಘ༻ͷhubot͕2ମ Cron༻ͷhubot͕1ମ mention༻ʹslackbotΛ׆༻

  18. શମߏ੒ɺϦϙδτϦͱ ಈ࡞؀ڥฤ GitHub͸cron༻ͷhubotͰ1ϦϙδτϦɺͦ ΕҎ֎ͷhubotͰ1ϦϙδτϦ Herokuʹcron༻Ͱ1, ͦΕҎ֎༻Ͱ2ͭ࢖ͬ ͯɺ؀ڥม਺ͰΞΫηε͢ΔGitHubΛ࢖͍෼ ͚͍ͯΔ

  19. CronҎ֎༻ͷ؀ڥม਺

  20. Cron༻ͷ؀ڥม਺

  21. develop͔Βmaster΁ͷ pull req ͜Μͳײ͡ͷίʔυ 18 module.exports = (robot) -> 19

    github = require("githubot")(robot) 20 robot.respond /deploy ?(.+)/i, (msg) -> 21 repo = msg.match[1] 22 url_api_base = "https://api.github.com" 23 data = { 24 "title": "deploy", 25 "head": "develop", 26 "base": "master" 27 } 28 ghOrg = process.env.HUBOT_GITHUB_ORG 29 url = "#{url_api_base}/repos/#{ghOrg}/#{repo}/pulls" 30 github.post url, data, (response) -> 31 msg.send "ຊ൪ʹσϓϩΠ͢ΔϓϧϦΫΤετΛ࡞੒ͨ͠Αʂ֬ೝͯ͠Ϛʔδͯ͠Ͷʂ" 32 msg.send response.html_url https:/ /gist.github.com/ryonext/2906f7bd9c865c2d8f1b
  22. pull reqҰཡΛग़͢ https:/ /github.com/github/hubot- scripts/blob/master/src/scripts/ github-pulls.coffee

  23. cron Hubotͷslack adapter Ͱ͸ ఆظతʹൃݴ ͤ͞Δ͜ͱ͸Ͱ͖Δ͕ɺbotͷൃݴʹରͯ͠bot ʹ൓Ԡͤ͞Δ͜ͱ͸Ͱ͖ͳ͍ʢ௒ॏཁʣ ͕ͨͬͯ͠ɺxmppΛ࢖ͬͯൃݴͤ͞Δඞཁ͕ ͋Δ

  24. xmpp xmpp Λ࢖͏৔߹ɺhubot ͷslack adapterΛ࢖͏৔߹ͱ͸ҧ͍ɺxmppͰૢ࡞͢ ΔͨΊͷslack accountΛ࡞͓ͬͯ͘ඞཁ͕ ͋Δ

  25. Πϝʔδ slack adapter xmpp adapter slack account

  26. xmpp࢖͏৔߹ͷઃఆ ʢslackଆʣ

  27. hubot x xmpp x slack

  28. None
  29. None
  30. xmpp࢖͏৔߹ͷઃఆ ʢhubotଆʣ ‘hubot-slack’ͷ୅ΘΓʹ’hubot-xmpp’Λ npm install͢Δ heroku ʹ্͛Δ৔߹ɺίϚϯυΛ `web: bin/hubot --adapter

    xmpp -n {bot໊}` ʹ͢Δ
  31. xmppิ଍ xmppͰൃݴͨ͠಺༰͸mentionʹͳΒͳ͍ ʢ௒ॏཁʣ ͔ͤͬ͘ϨϏϡʔ௨஌ͯ͠΋ؾ͔ͮΕͳ͍ slackbot΋࿈ܞͤ͞ΔɻcronͰͷൃݴʹର͠ ͯslackbotʹ൓Ԡͤ͞Δ

  32. ͜͏΍ͬͯ

  33. ͜͏ͳΔͷͰpush௨஌͕ དྷΔ

  34. ͓͠·͍ ࣭໰౳͋Ε͹ؾܰʹฉ͍͍ͯͩ͘͞ɻ HipChatͩͱbotؒ࿈ܞ΋ͬͱָͦ͏ͳؾ͕͠ ͯΔ