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

日報を支える技術

 日報を支える技術

「Octokit を使った日報スクリプト」を改善しまくったお話です。

https://masutaka.net/chalow/2016-04-09-1.html でももう少し詳しく書きました。

D6c5403c0b6ef2f9fd51910ea38323a3?s=128

Takashi Masuda

April 08, 2016
Tweet

More Decks by Takashi Masuda

Other Decks in Programming

Transcript

  1. ̋̋Λࢧ͑Δٕज़ 2016.04.08 ૿ాو࢜(@masutaka)

  2. ೔̋Λࢧ͑Δٕज़ 2016.04.08 ૿ాو࢜(@masutaka)

  3. ೔ใΛࢧ͑Δٕज़ 2016.04.08 ૿ాو࢜(@masutaka)

  4. ϚελΧͷ೔ใ • ং൫͸ΤϯδχΞͰͳ͘ ͯ΋෼͔Δ࿩Λ • த൫͸ϓϩμΫτ͝ͱʹ ηΫγϣϯ෼͚ • ऴ൫͸ཌӦۀ೔ʹ΍Δ͜ ͱΛશ෦ྻڍɻ೔ใۦಈ

    ։ൃͷͨΊ
  5. ͱ͋ΔεΫϦϓτͱͷग़ձ͍ http://kitak.hatenablog.jp/ entry/2014/04/22/013849

  6. ग़ྗΛࣗ෼޷Έʹม͑ͯɺ * [Bundle Update on 2016-03-24 - masutaka/awesome-github- feed](https://github.com/masutaka/awesome-github-feed/pull/ 38)

    by deppbot **merged!** * [Fix performance - masutaka/github-nippou](https:// github.com/masutaka/github-nippou/pull/44) by masutaka **merged!**
  7. RubyGems.orgʹϦϦʔε΍ʂ • 2014೥12݄7೔ • https://rubygems.org/gems/github-nippou/versions/0.0.1 • commitίϝϯτʹҾ༻ݩॻ͍ͯ㽂 • https://github.com/masutaka/github-nippou/commit/ 4f408a6d

  8. ͩ·ͩ͠·͠࢖͏೔ʑ

  9. • ࠓ೔׆ಈͨ͠Issue΍PullRequestΛऔಘͰ͖ͳ͍͕࣌ ͋Δ • λΠτϧ΍εςʔλε͕ݹ͍͕࣌͋Δ • IssueͷΫϩʔζ΍commit΁ͷίϝϯτΛݕ஌Ͱ͖ͳ ͍ • ͳΜ͔஗͍

    • ΍Δؾͷͳ͍ʢϦϑΝΫλϦϯάͯ͠ͳ͍ʣίʔυ
  10. ̍೥͔݄̏์ஔ…

  11. ઌʑिʢ2016-03-21ʣ ͳ͔ͥ΍Δؾʹͳͬͨ ※ ษڧձͷ͜ͱ͸ҙ͍ࣝͯ͠ͳ͔ͬͨ

  12. ͜Μͳײ͡ʂ

  13. վળ͸΄΅׬ྃ

  14. ✓ ࠓ೔׆ಈͨ͠Issue΍PullRequestΛ΋Εͳ͘औಘ ✓ ظؒΛࢦఆ͢Δ͜ͱ΋Մೳʹͳͬͨ ✓ λΠτϧ΍εςʔλε΋ݱࡏͷ஋Λऔಘ ✓ IssueͷΫϩʔζΛݕ஌ɻcommit΁ͷίϝϯτ͸ࠓ ճݟૹΓ ✓

    ύϑΥʔϚϯε͸ݶք·Ͱ্͛ΒΕͨ ✓ ຬ଍ߦ͘ఔ౓·ͰϦϑΝΫλϦϯάͨ͠
  15. ॱΛ௥ͬͯ࿩͠·͢ɻ

  16. Octokit https://github.com/octokit/octokit.rb

  17. GitHub Events API List events performed by a user https://developer.github.com/v3/activity/events/#list-events-

    performed-by-a-user If you are authenticated as the given user, you will see your private events. Otherwise, you'll only see public events. GET /users/:username/events
  18. ͜͜Ͱ࢖ΘΕ͍ͯΔͱࢥ͏

  19. pagination͋Γ㽂 https://developer.github.com/v3/activity/events/ Events support pagination, however the per_page option is

    unsupported. The fixed page size is 30 items. Fetching up to ten pages is supported, for a total of 300 events. Only events created within the past 90 days will be included in timelines. Events older than 90 days will not be included (even if the total number of events in the timeline is less than 300).
  20. curlͰͷऔಘྫ $ curl -s -u <username>:<personal access token> https:// api.github.com/users/:username/events

    [ { "id": "3825680181", "type": "PullRequestEvent", "actor": { "id": 170014, "login": "masutaka", "gravatar_id": "", "url": "https://api.github.com/users/masutaka", "avatar_url": "https://avatars.githubusercontent.com/u/170014?" }, (snip)
  21. pagination $ curl -I <username>:<personal access token> https:// api.github.com/users/:username/events (snip)

    Link: <https://api.github.com/user/170014/events?page=2>; rel="next", <https://api.github.com/user/170014/events?page=10>; rel=“last" (snip)
  22. Octokit https://github.com/octokit/octokit.rb

  23. UserEventsऔಘํ๏ client = Octokit::Client.new(login: 'masutaka', access_token: 'xxx') user_events = client.user_events(‘masutaka')

    σϑΥϧτͰ͸࠷େͰ30ݸऔಘ
  24. UserEventsͷϋϚΓͲ͜Ζ

  25. • client.user_events͕ฦ͢Πϕϯτ͸σϑΥϧτ30ݸ • λΠτϧ΍εςʔλε͸Πϕϯτൃੜ࣌ͷ΋ͷɻ ݱࡏͱ͸ҧ͏Մೳੑ͋Γ • ࠓճั֫͢΂͖ΠϕϯτλΠϓʢ˞ʣ͸4ͭ • IssuesEvent, IssueCommentEvent,

    PullRequestEvent, PullRequestReviewCommentEvent • Issueͷ;ΓΛͨ͠PullRequest͕͋Δ ※ https://developer.github.com/v3/activity/events/types/
  26. ࠷ॳͷεΫϦϓτ

  27. 1. UserEventsऔಘʢ30ݸ͚ͩʣ 2. ඞཁͳUserEventҎ֎ࣺͯͭͭɺඪ४ग़ྗ ʹ੔ܗͯ͠දࣔ

  28. • ࠓ೔׆ಈͨ͠Issue΍PullRequestΛऔಘͰ͖ͳ͍͕࣌ ͋Δ • λΠτϧ΍εςʔλε͕ݹ͍͕࣌͋Δ • IssueͷΫϩʔζ΍commit΁ͷίϝϯτΛݕ஌Ͱ͖ͳ ͍ • ͳΜ͔஗͍

    • ΍Δؾͷͳ͍ʢϦϑΝΫλϦϯάͯ͠ͳ͍ʣίʔυ ͜ΕΒͷݪҼ
  29. ৘ใΛ࿙Εͳ͘׬ᘳʹऔಘ

  30. 1. UserEventsऔಘʢ30ݸʣ 2. ࣍ͷϖʔδऔಘ͕·ͩඞཁͳΒUserEventsΛऔ ಘ͠ଓ͚Δ➰ 3. ඞཁͳUserEventҎ֎ࣺͯΔ 4. ࢒ͬͨUserEventsͷݱࡏͷλΠτϧ΍εςʔλ εΛऔಘͭͭ͠➰ɺඪ४ग़ྗʹ੔ܗͯ͠දࣔ

  31. ׬ᘳʹͳΓ·ͨ͠ʂ

  32. Ͱ΋஗͘ͳΓ·ͨ͠ʗ(^o^)ʘ ਺ඵͩͬͨͷ͕ɺ஗͍࣌Ͱ20ඵҎ্ʹ…

  33. ύϑΥʔϚϯε෼ੳ͢Δͧʂ

  34. 1. UserEventsऔಘʢ30ݸʣ… ໿1.4ඵ 2. ࣍ͷϖʔδऔಘ͕·ͩඞཁͳΒUserEventsΛऔ ಘ͠ଓ͚Δ➰ … ໿1.5ඵ x ࠷େ9ճ

    3. ඞཁͳUserEventҎ֎ࣺͯΔ 4. ࢒ͬͨUserEventsͷݱࡏͷλΠτϧ΍εςʔλ εΛऔಘͭͭ͠➰ɺඪ४ग़ྗʹ੔ܗͯ͠ද ࣔ … ໿1.0ඵ x ࢒ͬͨUserEvent਺
  35. GitHub API΁ͷΞΫηεʹ࣌ ͕͔͔͍ؒͬͯͨ

  36. ύϑΥʔϚϯεվળ̍ @client.user_events(@user) ! @client.user_events(@user, per_page: 100) fetch਺Λ30͔Β100ʹ૿΍͢

  37. 1. UserEventsऔಘʢ100ݸʣ… ໿1.8ඵ 2. 1೔100ݸʹऩ·Δ͜ͱ͕΄ͱΜͲͳͷͰɺ ࣍ͷϖʔδऔಘ͕ඞཁͳ֬཰͸௿͍ 3. ඞཁͳUserEventҎ֎ࣺͯΔ 4. ࢒ͬͨUserEventsͷݱࡏͷλΠτϧ΍εςʔ

    λεΛऔಘͭͭ͠ɺඪ४ग़ྗʹ੔ܗͯ͠ද ࣔ … ໿1.0ඵ x UserEvent਺ ↑վળʂ
  38. ύϑΥʔϚϯεվળ̎(मਖ਼લ) def list lines = [] user_events.each do |user_event| line

    << format_line(user_event) end puts sort(lines) end ฒྻԽͯ͠ΈΑ͏
  39. ύϑΥʔϚϯεվળ̎(मਖ਼ޙ) def list lines = [] mutex = Mutex::new #

    https://github.com/grosser/parallel Parallel.each(user_events, in_threads: 5) do |user_event| line = format_line(user_event) mutex.synchronize { lines << line } # ഉଞ੍ޚ end puts sort(lines) end
  40. ύϑΥʔϚϯεվળͷ݁Ռ मਖ਼લ: 17.531ඵ ↓ मਖ਼ޙ: 7.660ඵʢσϑΥϧτ: 5ฒྻʣ मਖ਼ޙ: 6.655ඵʢ10ฒྻʣ ※

    2016೥3݄30೔Ͱܭଌ
  41. 1. UserEventsऔಘʢ100ݸʣ… ໿1.8ඵ 2. 1೔100ݸʹऩ·Δ͜ͱ͕΄ͱΜͲͳͷͰɺ࣍ ͷϖʔδऔಘ͕ඞཁͳ֬཰͸௿͍ 3. ඞཁͳUserEventҎ֎ࣺͯΔ 4. ࢒ͬͨUserEventsͷݱࡏͷλΠτϧ΍εςʔλ

    εΛ̑ฒྻͰऔಘͭͭ͠➰➰➰➰➰ɺඪ४ग़ ྗʹ੔ܗͯ͠දࣔ … ໿1.0ඵ x UserEvent਺ ÷ 5 ↓վળʂ
  42. ࢖͍ํ $ github-nippou help Commands: github-nippou help [COMMAND] # Describe

    available commands or one specific command github-nippou list # Displays today's GitHub events formatted for Nippou github-nippou version # Displays version Options: s, [--since-date=SINCE_DATE] # Retrieves GitHub user_events since the date # Default: 20160406 u, [--until-date=UNTIL_DATE] # Retrieves GitHub user_events until the date # Default: 20160406
  43. σϞ

  44. ϦϦʔε

  45. ·ͱΊ

  46. ύϑΥʔϚϯενϡʔχϯά ͍͚ͨͩ͠ͷਓੜͩͬͨɻ

  47. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ

  48. • $ github-nippou | sed -e "s@- feedforce/@- @g" >>

    ~/tmp/nippou.md
  49. ޙչ ☓ github-nippou ̋ github_nippou

  50. ฒྻԽͱ͍͑͹ɺ

  51. Goݴޠɾɾɾʂ