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

日報を支える技術

 日報を支える技術

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

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

Takashi Masuda

April 08, 2016
Tweet

More Decks by Takashi Masuda

Other Decks in Programming

Transcript

  1. ग़ྗΛࣗ෼޷Έʹม͑ͯɺ * [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!**
  2. 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
  3. 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).
  4. 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)
  5. 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)
  6. • client.user_events͕ฦ͢Πϕϯτ͸σϑΥϧτ30ݸ • λΠτϧ΍εςʔλε͸Πϕϯτൃੜ࣌ͷ΋ͷɻ ݱࡏͱ͸ҧ͏Մೳੑ͋Γ • ࠓճั֫͢΂͖ΠϕϯτλΠϓʢ˞ʣ͸4ͭ • IssuesEvent, IssueCommentEvent,

    PullRequestEvent, PullRequestReviewCommentEvent • Issueͷ;ΓΛͨ͠PullRequest͕͋Δ ※ https://developer.github.com/v3/activity/events/types/
  7. 1. UserEventsऔಘʢ30ݸʣ… ໿1.4ඵ 2. ࣍ͷϖʔδऔಘ͕·ͩඞཁͳΒUserEventsΛऔ ಘ͠ଓ͚Δ➰ … ໿1.5ඵ x ࠷େ9ճ

    3. ඞཁͳUserEventҎ֎ࣺͯΔ 4. ࢒ͬͨUserEventsͷݱࡏͷλΠτϧ΍εςʔλ εΛऔಘͭͭ͠➰ɺඪ४ग़ྗʹ੔ܗͯ͠ද ࣔ … ໿1.0ඵ x ࢒ͬͨUserEvent਺
  8. ύϑΥʔϚϯεվળ̎(मਖ਼લ) def list lines = [] user_events.each do |user_event| line

    << format_line(user_event) end puts sort(lines) end ฒྻԽͯ͠ΈΑ͏
  9. ύϑΥʔϚϯεվળ̎(मਖ਼ޙ) 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
  10. ࢖͍ํ $ 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