Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

ग़ྗΛࣗ෼޷Έʹม͑ͯɺ * [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!**

Slide 7

Slide 7 text

RubyGems.orgʹϦϦʔε΍ʂ • 2014೥12݄7೔ • https://rubygems.org/gems/github-nippou/versions/0.0.1 • commitίϝϯτʹҾ༻ݩॻ͍ͯ㽂 • https://github.com/masutaka/github-nippou/commit/ 4f408a6d

Slide 8

Slide 8 text

ͩ·ͩ͠·͠࢖͏೔ʑ

Slide 9

Slide 9 text

• ࠓ೔׆ಈͨ͠Issue΍PullRequestΛऔಘͰ͖ͳ͍͕࣌ ͋Δ • λΠτϧ΍εςʔλε͕ݹ͍͕࣌͋Δ • IssueͷΫϩʔζ΍commit΁ͷίϝϯτΛݕ஌Ͱ͖ͳ ͍ • ͳΜ͔஗͍ • ΍Δؾͷͳ͍ʢϦϑΝΫλϦϯάͯ͠ͳ͍ʣίʔυ

Slide 10

Slide 10 text

̍೥͔݄̏์ஔ…

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

͜Μͳײ͡ʂ

Slide 13

Slide 13 text

վળ͸΄΅׬ྃ

Slide 14

Slide 14 text

✓ ࠓ೔׆ಈͨ͠Issue΍PullRequestΛ΋Εͳ͘औಘ ✓ ظؒΛࢦఆ͢Δ͜ͱ΋Մೳʹͳͬͨ ✓ λΠτϧ΍εςʔλε΋ݱࡏͷ஋Λऔಘ ✓ IssueͷΫϩʔζΛݕ஌ɻcommit΁ͷίϝϯτ͸ࠓ ճݟૹΓ ✓ ύϑΥʔϚϯε͸ݶք·Ͱ্͛ΒΕͨ ✓ ຬ଍ߦ͘ఔ౓·ͰϦϑΝΫλϦϯάͨ͠

Slide 15

Slide 15 text

ॱΛ௥ͬͯ࿩͠·͢ɻ

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

͜͜Ͱ࢖ΘΕ͍ͯΔͱࢥ͏

Slide 19

Slide 19 text

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).

Slide 20

Slide 20 text

curlͰͷऔಘྫ $ curl -s -u : 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)

Slide 21

Slide 21 text

pagination $ curl -I : https:// api.github.com/users/:username/events (snip) Link: ; rel="next", ; rel=“last" (snip)

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

UserEventsऔಘํ๏ client = Octokit::Client.new(login: 'masutaka', access_token: 'xxx') user_events = client.user_events(‘masutaka') σϑΥϧτͰ͸࠷େͰ30ݸऔಘ

Slide 24

Slide 24 text

UserEventsͷϋϚΓͲ͜Ζ

Slide 25

Slide 25 text

• client.user_events͕ฦ͢Πϕϯτ͸σϑΥϧτ30ݸ • λΠτϧ΍εςʔλε͸Πϕϯτൃੜ࣌ͷ΋ͷɻ ݱࡏͱ͸ҧ͏Մೳੑ͋Γ • ࠓճั֫͢΂͖ΠϕϯτλΠϓʢ˞ʣ͸4ͭ • IssuesEvent, IssueCommentEvent, PullRequestEvent, PullRequestReviewCommentEvent • Issueͷ;ΓΛͨ͠PullRequest͕͋Δ ※ https://developer.github.com/v3/activity/events/types/

Slide 26

Slide 26 text

࠷ॳͷεΫϦϓτ

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

• ࠓ೔׆ಈͨ͠Issue΍PullRequestΛऔಘͰ͖ͳ͍͕࣌ ͋Δ • λΠτϧ΍εςʔλε͕ݹ͍͕࣌͋Δ • IssueͷΫϩʔζ΍commit΁ͷίϝϯτΛݕ஌Ͱ͖ͳ ͍ • ͳΜ͔஗͍ • ΍Δؾͷͳ͍ʢϦϑΝΫλϦϯάͯ͠ͳ͍ʣίʔυ ͜ΕΒͷݪҼ

Slide 29

Slide 29 text

৘ใΛ࿙Εͳ͘׬ᘳʹऔಘ

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

׬ᘳʹͳΓ·ͨ͠ʂ

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

GitHub API΁ͷΞΫηεʹ࣌ ͕͔͔͍ؒͬͯͨ

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

1. UserEventsऔಘʢ100ݸʣ… ໿1.8ඵ 2. 1೔100ݸʹऩ·Δ͜ͱ͕΄ͱΜͲͳͷͰɺ ࣍ͷϖʔδऔಘ͕ඞཁͳ֬཰͸௿͍ 3. ඞཁͳUserEventҎ֎ࣺͯΔ 4. ࢒ͬͨUserEventsͷݱࡏͷλΠτϧ΍εςʔ λεΛऔಘͭͭ͠ɺඪ४ग़ྗʹ੔ܗͯ͠ද ࣔ … ໿1.0ඵ x UserEvent਺ ↑վળʂ

Slide 38

Slide 38 text

ύϑΥʔϚϯεվળ̎(मਖ਼લ) def list lines = [] user_events.each do |user_event| line << format_line(user_event) end puts sort(lines) end ฒྻԽͯ͠ΈΑ͏

Slide 39

Slide 39 text

ύϑΥʔϚϯεվળ̎(मਖ਼ޙ) 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

Slide 40

Slide 40 text

ύϑΥʔϚϯεվળͷ݁Ռ मਖ਼લ: 17.531ඵ ↓ मਖ਼ޙ: 7.660ඵʢσϑΥϧτ: 5ฒྻʣ मਖ਼ޙ: 6.655ඵʢ10ฒྻʣ ※ 2016೥3݄30೔Ͱܭଌ

Slide 41

Slide 41 text

1. UserEventsऔಘʢ100ݸʣ… ໿1.8ඵ 2. 1೔100ݸʹऩ·Δ͜ͱ͕΄ͱΜͲͳͷͰɺ࣍ ͷϖʔδऔಘ͕ඞཁͳ֬཰͸௿͍ 3. ඞཁͳUserEventҎ֎ࣺͯΔ 4. ࢒ͬͨUserEventsͷݱࡏͷλΠτϧ΍εςʔλ εΛ̑ฒྻͰऔಘͭͭ͠➰➰➰➰➰ɺඪ४ग़ ྗʹ੔ܗͯ͠දࣔ … ໿1.0ඵ x UserEvent਺ ÷ 5 ↓վળʂ

Slide 42

Slide 42 text

࢖͍ํ $ 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

Slide 43

Slide 43 text

σϞ

Slide 44

Slide 44 text

ϦϦʔε

Slide 45

Slide 45 text

·ͱΊ

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

ޙչ ☓ github-nippou ̋ github_nippou

Slide 50

Slide 50 text

ฒྻԽͱ͍͑͹ɺ

Slide 51

Slide 51 text

Goݴޠɾɾɾʂ