fluent-plugin-github-activities 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 890661f8c3f6d0ba720cfe6ffaabfb69d6396c76
4
- data.tar.gz: c7db01ecf49764a715a5f325c3cdd1c0f3cd0c91
3
+ metadata.gz: 86e9e9a0a689ec6d7ad2c9e0f9dcaa05d932ce69
4
+ data.tar.gz: c7a2502403c7cc773fced9752fa1590fc616cba6
5
5
  SHA512:
6
- metadata.gz: e59f0b3d9ce18f8ccd38e425523fc4a5a78612d3ffd4e5fa46f6620b541c4ee3c04213199cf37f97ccbb1f283762c6dd14951739bd3355dd0b9c047efb408c3d
7
- data.tar.gz: e642b72842ea663e14bb93ce1ef56869787956b0db982dbd1bbc1e09a6ecab79e059392a1bb6b9d6d609d64f7f17ca4a517b7de07d93694dcdff09366ee89a55
6
+ metadata.gz: a7abc34e2f2bd886d51c46b21c7b304647f58682234f2f5f62f66d811cf8b9450966d3f7b773475c22a0890f2ecac6654b6d2531abc071ecbb09837cc5a82730
7
+ data.tar.gz: 5515a6b80db99bc93ffdea84a1d62059fc6762c1c84716b57d8efc468fa48cde3816901ad9e2b513643baf2a059b109cd75801991231e35abd5965d686c87fb5
data/README.md CHANGED
@@ -36,8 +36,43 @@ Notes:
36
36
  * Because a "push" activity doesn't include full information of each commit, commits are separately forwarded [commits](https://developer.github.com/v3/git/commits/) as pseudo `commit` activities.
37
37
  * All forwarded records have an extra property `$github-activities-related-avatar`.
38
38
  It will be useful to get the URI of the avatar image easily, for both activity events and commits.
39
+ * All forwarded records have an extra property `$github-activities-related-organization-icon`.
40
+ It will be useful to get the URI of the logo image of the organization easily, for both activity events and commits.
39
41
  * Unsupported activities are also forwarded with their raw event type like `StatusEvent`.
40
42
 
43
+ ## Authentication
44
+
45
+ The configuration item `access_token` is optional but strongly recommended to be configured, because there is a rate limit: 60requests/hour by default.
46
+ By an authenticated crawler, you can crawl 5000requests/hour (means about 80requests/minute).
47
+
48
+ A new access token for your instance can be generated by a simple BASIC authentication, like:
49
+
50
+ ~~~
51
+ $ curl -u 'your-account' -d '{"scopes":[],"note":"Sharetary"}' https://api.github.com/authorizations
52
+ Enter host password for user 'your-account':
53
+ {
54
+ "id": 1234567,
55
+ "url": "https://api.github.com/authorizations/1234567",
56
+ "app": {
57
+ "name": "Sharetary (API)",
58
+ "url": "https://developer.github.com/v3/oauth_authorizations/",
59
+ "client_id": "00000000000000000000"
60
+ },
61
+ "token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
62
+ "hashed_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
63
+ "token_last_eight": "xxxxxxxx",
64
+ "note": "Sharetary",
65
+ "note_url": null,
66
+ "created_at": "2015-06-02T03:17:46Z",
67
+ "updated_at": "2015-06-02T03:17:46Z",
68
+ "scopes": [
69
+
70
+ ],
71
+ "fingerprint": null
72
+ }
73
+ ~~~
74
+
75
+ Then the value of the `token` field is the access key to be written to the configuration file.
41
76
 
42
77
  ## Configurations
43
78
 
@@ -45,13 +80,8 @@ Notes:
45
80
  <source>
46
81
  type github-activities
47
82
 
48
- # Authentication settings.
49
- # They are optional but strongly recommended to be configured,
50
- # because there is a rate limit: 60requests/hour by default.
51
- # By an authenticated crawler, you can crawl 5000requests/hour
52
- # (means about 80requests/minute).
53
- basic_username your-user-name-of-github
54
- basic_password your-password-of-github
83
+ # Access token for this instance. See also the previous section.
84
+ access_token access-token-for-this-instance
55
85
 
56
86
  # Interval seconds for requests. This is `1` by default.
57
87
  interval 1
@@ -19,7 +19,7 @@
19
19
 
20
20
  Gem::Specification.new do |spec|
21
21
  spec.name = "fluent-plugin-github-activities"
22
- spec.version = "0.2.0"
22
+ spec.version = "0.3.0"
23
23
  spec.authors = ["YUKI Hiroshi"]
24
24
  spec.email = ["yuki@clear-code.com"]
25
25
  spec.summary = "Fluentd plugin to crawl public activities on the GitHub."
@@ -21,6 +21,7 @@ require "uri"
21
21
  require "net/https"
22
22
  require "json"
23
23
  require "pathname"
24
+ require "time"
24
25
 
25
26
  require "fluent/plugin/github-activities/safe_file_writer"
26
27
 
@@ -36,13 +37,13 @@ module Fluent
36
37
  DEFAULT_LAST_EVENT_TIMESTAMP = -1
37
38
 
38
39
  RELATED_USER_IMAGE_KEY = "$github-activities-related-avatar"
40
+ RELATED_ORGANIZATION_IMAGE_KEY = "$github-activities-related-organization-logo"
39
41
 
40
42
  attr_writer :on_emit
41
43
  attr_reader :request_queue, :interval_for_next_request
42
44
 
43
45
  def initialize(options={})
44
- @username = options[:username]
45
- @password = options[:password]
46
+ @access_token = options[:access_token]
46
47
 
47
48
  @watching_users = options[:watching_users] || []
48
49
 
@@ -54,14 +55,11 @@ module Fluent
54
55
  @pos_file = Pathname(@pos_file) if @pos_file
55
56
  load_positions
56
57
 
57
- @avatars = {}
58
-
59
58
  @request_queue = options[:request_queue] || []
60
59
 
61
60
  @default_interval = options[:default_interval] || DEFAULT_INTERVAL
62
61
 
63
62
  @watching_users.each do |user|
64
- fetch_avatar(user)
65
63
  reserve_user_events(user)
66
64
  end
67
65
  end
@@ -70,7 +68,7 @@ module Fluent
70
68
  raise EmptyRequestQueue.new if @request_queue.empty?
71
69
 
72
70
  request = @request_queue.shift
73
- $log.info("GithubActivities::Crawler: processing request: #{request.inspect}")
71
+ $log.info("GithubActivities::Crawler: processing request: #{request.inspect}") if $log
74
72
  if request[:process_after] and
75
73
  Time.now.to_i < request[:process_after]
76
74
  @request_queue.push(request)
@@ -81,18 +79,18 @@ module Fluent
81
79
  uri = request_uri(request)
82
80
  extra_headers = extra_request_headers(request)
83
81
 
84
- $log.info("GithubActivities::Crawler: requesting to #{uri.inspect}")
82
+ $log.info("GithubActivities::Crawler: requesting to #{uri.inspect}") if $log
85
83
  response = http_get(uri, extra_headers)
86
- $log.info("GithubActivities::Crawler: response: #{response.inspect}")
84
+ $log.info("GithubActivities::Crawler: response: #{response.inspect}") if $log
87
85
 
88
86
  case response
89
87
  when Net::HTTPSuccess
90
88
  body = JSON.parse(response.body)
91
- $log.info("GithubActivities::Crawler: request type: #{request[:type]}")
89
+ $log.info("GithubActivities::Crawler: request type: #{request[:type]}") if $log
92
90
  case request[:type]
93
91
  when TYPE_EVENTS
94
92
  events = body
95
- $log.info("GithubActivities::Crawler: events size: #{events.size}")
93
+ $log.info("GithubActivities::Crawler: events size: #{events.size}") if $log
96
94
  process_user_events(request[:user], events)
97
95
  reserve_user_events(request[:user], :previous_response => response)
98
96
  save_user_position(request[:user], :entity_tag => response["ETag"])
@@ -108,6 +106,15 @@ module Fluent
108
106
  end
109
107
  @interval_for_next_request = NO_INTERVAL
110
108
  return true
109
+ when Net::HTTPNotFound
110
+ case request[:type]
111
+ when TYPE_COMMIT
112
+ fake_body = {
113
+ "sha" => request[:sha],
114
+ "author" => {},
115
+ }
116
+ process_commit(fake_body, request[:push])
117
+ end
111
118
  end
112
119
  @interval_for_next_request = @default_interval
113
120
  return true
@@ -169,7 +176,10 @@ module Fluent
169
176
 
170
177
  def process_user_event(user, event)
171
178
  # see also: https://developer.github.com/v3/activity/events/types/
172
- event[RELATED_USER_IMAGE_KEY] = @avatars[user]
179
+ event[RELATED_USER_IMAGE_KEY] = event["actor"]["avatar_url"]
180
+ if event["org"]
181
+ event[RELATED_ORGANIZATION_IMAGE_KEY] = event["org"]["avatar_url"]
182
+ end
173
183
  case event["type"]
174
184
  when "PushEvent"
175
185
  process_push_event(event)
@@ -200,23 +210,27 @@ module Fluent
200
210
  commit_refs.reverse.each do |commit_ref|
201
211
  @request_queue.unshift(:type => TYPE_COMMIT,
202
212
  :uri => commit_ref["url"],
213
+ :sha => commit_ref["sha"],
203
214
  :push => event)
204
215
  end
205
216
  # emit("push", event)
206
217
  end
207
218
 
208
219
  def process_commit(commit, push_event)
220
+ $log.info("GithubActivities::Crawler: processing commit #{commit["sha"]}") if $log
209
221
  user = commit["author"]["login"]
210
- fetch_avatar(user)
211
222
 
212
- if @include_foreign_commits or watching_user?(user)
213
- commit[RELATED_USER_IMAGE_KEY] = @avatars[user]
223
+ if user and (@include_foreign_commits or watching_user?(user))
224
+ commit[RELATED_USER_IMAGE_KEY] = push_event["actor"]["avatar_url"]
225
+ if push_event["org"]
226
+ commit[RELATED_ORGANIZATION_IMAGE_KEY] = push_event["org"]["avatar_url"]
227
+ end
214
228
  emit("commit", commit)
215
229
  end
216
230
 
217
231
  commit_refs = push_event["payload"]["commits"]
218
232
  target_commit_ref = commit_refs.find do |commit_ref|
219
- commit_ref["url"] == commit["url"]
233
+ commit_ref["sha"] == commit["sha"]
220
234
  end
221
235
  target_commit_ref["commit"] = commit if target_commit_ref
222
236
 
@@ -227,7 +241,7 @@ module Fluent
227
241
  end
228
242
 
229
243
  def watching_user?(user)
230
- @watching_users.include(user)
244
+ @watching_users.include?(user)
231
245
  end
232
246
 
233
247
  def process_issue_event(event)
@@ -299,13 +313,6 @@ module Fluent
299
313
  end
300
314
  end
301
315
 
302
- def fetch_avatar(user)
303
- return if @avatars.key?(user)
304
- response = http_get(user_info(user))
305
- fetched_user_info = JSON.parse(response.body)
306
- @avatars[user] = fetched_user_info["avatar_url"]
307
- end
308
-
309
316
  private
310
317
  def user_activities(user)
311
318
  "https://api.github.com/users/#{user}/events/public"
@@ -316,7 +323,7 @@ module Fluent
316
323
  end
317
324
 
318
325
  def emit(tag, record)
319
- $log.trace("GithubActivities::Crawler: emit => #{tag}, #{record.inspect}")
326
+ $log.trace("GithubActivities::Crawler: emit => #{tag}, #{record.inspect}") if $log
320
327
  @on_emit.call(tag, record) if @on_emit
321
328
  end
322
329
 
@@ -327,8 +334,8 @@ module Fluent
327
334
  http.use_ssl = parsed_uri.is_a?(URI::HTTPS)
328
335
  http.start do |http|
329
336
  http_request = Net::HTTP::Get.new(parsed_uri.path, extra_headers)
330
- if @username and @password
331
- http_request.basic_auth(@username, @password)
337
+ if @access_token
338
+ extra_headers["Authorization"] = "token #{@access_token}"
332
339
  end
333
340
  response = http.request(http_request)
334
341
  end
@@ -23,8 +23,7 @@ module Fluent
23
23
 
24
24
  Plugin.register_input("github-activities", self)
25
25
 
26
- config_param :basic_username, :string, :default => nil
27
- config_param :basic_password, :string, :default => nil
26
+ config_param :access_token, :string, :default => nil
28
27
  config_param :users, :string, :default => nil
29
28
  config_param :users_list, :string, :default => nil
30
29
  config_param :include_commits_from_pull_request, :bool, :default => false
@@ -45,8 +44,7 @@ module Fluent
45
44
  @base_tag = @base_tag.sub(/\.\z/, "")
46
45
  @thread = Thread.new do
47
46
  crawler_options = {
48
- :username => @basic_username,
49
- :password => @basic_password,
47
+ :access_token => @access_token,
50
48
  :watching_users => prepare_users_list,
51
49
  :include_commits_from_pull_request => @include_commits_from_pull_request,
52
50
  :include_foreign_commits => @include_foreign_commits,
@@ -0,0 +1,45 @@
1
+ {
2
+ "id": "2823041920",
3
+ "type": "PushEvent",
4
+ "actor": {
5
+ "id": 70062,
6
+ "login": "piroor",
7
+ "gravatar_id": "",
8
+ "url": "https://api.github.com/users/piroor",
9
+ "avatar_url": "https://avatars.githubusercontent.com/u/70062?"
10
+ },
11
+ "repo": {
12
+ "id": 35922279,
13
+ "name": "clear-code/fluent-plugin-github-activities",
14
+ "url": "https://api.github.com/repos/clear-code/fluent-plugin-github-activities"
15
+ },
16
+ "payload": {
17
+ "push_id": 670478406,
18
+ "size": 1,
19
+ "distinct_size": 1,
20
+ "ref": "refs/heads/master",
21
+ "head": "c908f319c7b6d5c5a69c8b675bde40dd990ee364",
22
+ "before": "e77acc068b5568f8ea55605db2e3a9005805c898",
23
+ "commits": [
24
+ {
25
+ "sha": "8e90721ff5d89f52b5b3adf0b86db01f03dc5588",
26
+ "author": {
27
+ "email": "shimoda@clear-code.com",
28
+ "name": "YUKI Hiroshi"
29
+ },
30
+ "message": "Add missing constant",
31
+ "distinct": true,
32
+ "url": "https://api.github.com/repos/clear-code/fluent-plugin-github-activities/commits/8e90721ff5d89f52b5b3adf0b86db01f03dc5588"
33
+ }
34
+ ]
35
+ },
36
+ "public": true,
37
+ "created_at": "2015-05-21T05:37:34Z",
38
+ "org": {
39
+ "id": 176515,
40
+ "login": "clear-code",
41
+ "gravatar_id": "",
42
+ "url": "https://api.github.com/orgs/clear-code",
43
+ "avatar_url": "https://avatars.githubusercontent.com/u/176515?"
44
+ }
45
+ }
@@ -25,11 +25,38 @@ class CrawlerTest < Test::Unit::TestCase
25
25
  def setup
26
26
  @emitted_records = []
27
27
 
28
- @crawler = ::Fluent::GithubActivities::Crawler.new
28
+ @crawler = ::Fluent::GithubActivities::Crawler.new(crawler_options)
29
29
  @crawler.on_emit = lambda do |tag, record|
30
30
  @emitted_records << { :tag => tag,
31
31
  :record => record }
32
32
  end
33
+ @crawler.request_queue.clear
34
+ end
35
+
36
+ def crawler_options
37
+ {
38
+ :include_commits_from_pull_request => false,
39
+ :include_foreign_commits => false,
40
+ :watching_users => [
41
+ 'piroor',
42
+ ],
43
+ }
44
+ end
45
+
46
+ def fill_extra_fields(event, parent_event=nil)
47
+ parent_event ||= event
48
+
49
+ event = event.merge(
50
+ "$github-activities-related-avatar" => parent_event["actor"]["avatar_url"],
51
+ )
52
+
53
+ if parent_event["org"]
54
+ event = event.merge(
55
+ "$github-activities-related-organization-logo" => parent_event["org"]["avatar_url"],
56
+ )
57
+ end
58
+
59
+ event
33
60
  end
34
61
 
35
62
  REQUEST_PATTERNS = {
@@ -54,7 +81,7 @@ class CrawlerTest < Test::Unit::TestCase
54
81
  data(REQUEST_PATTERNS)
55
82
  def test_request_uri(data)
56
83
  uri = @crawler.request_uri(data[:request])
57
- assert_equal(URI(data[:uri]), uri)
84
+ assert_equal(data[:uri], uri)
58
85
  end
59
86
 
60
87
  data(REQUEST_PATTERNS)
@@ -97,12 +124,17 @@ class CrawlerTest < Test::Unit::TestCase
97
124
 
98
125
  class UserEventTest < self
99
126
  def test_generic
100
- @crawler.process_user_event("username", { "type" => "test" })
127
+ event = {
128
+ "type" => "test",
129
+ "actor" => {},
130
+ "created_at" => "2015-05-21T05:37:34Z",
131
+ }
132
+ @crawler.process_user_event("username", event)
101
133
  expected = {
102
134
  :request_queue => [],
103
135
  :emitted_records => [
104
136
  { :tag => "test",
105
- :record => { "type" => "test" } },
137
+ :record => fill_extra_fields(event) },
106
138
  ],
107
139
  }
108
140
  assert_equal(expected,
@@ -113,12 +145,17 @@ class CrawlerTest < Test::Unit::TestCase
113
145
 
114
146
  class UserEventsTest < self
115
147
  def test_generic
116
- @crawler.process_user_events("username", [{ "type" => "test" }])
148
+ event = {
149
+ "type" => "test",
150
+ "actor" => {},
151
+ "created_at" => "2015-05-21T05:37:34Z",
152
+ }
153
+ @crawler.process_user_events("username", [event])
117
154
  expected = {
118
155
  :request_queue => [],
119
156
  :emitted_records => [
120
157
  { :tag => "test",
121
- :record => { "type" => "test" } },
158
+ :record => fill_extra_fields(event) },
122
159
  ],
123
160
  }
124
161
  assert_equal(expected,
@@ -128,26 +165,69 @@ class CrawlerTest < Test::Unit::TestCase
128
165
  end
129
166
 
130
167
  class PushEventTest < self
168
+ def test_single_commit
169
+ push = JSON.parse(fixture_data("push-event.json"))
170
+ push = fill_extra_fields(push)
171
+ base = "https://api.github.com/repos/clear-code/fluent-plugin-github-activities/commits"
172
+ @crawler.process_user_event("user", push)
173
+
174
+ expected_commit = JSON.parse(fixture_data("commit.json"))
175
+ expected_push = JSON.parse(fixture_data("push-event.json"))
176
+
177
+ expected_commit = fill_extra_fields(expected_commit, expected_push)
178
+
179
+ expected_push = fill_extra_fields(expected_push)
180
+ expected = {
181
+ :request_queue => [
182
+ { :type => ::Fluent::GithubActivities::TYPE_COMMIT,
183
+ :uri => "#{base}/8e90721ff5d89f52b5b3adf0b86db01f03dc5588",
184
+ :sha => "8e90721ff5d89f52b5b3adf0b86db01f03dc5588",
185
+ :push => expected_push },
186
+ ],
187
+ :emitted_records => [
188
+ ],
189
+ }
190
+ assert_equal(expected,
191
+ { :request_queue => @crawler.request_queue,
192
+ :emitted_records => @emitted_records })
193
+ end
194
+
131
195
  def test_multiple_commits
132
- event = JSON.parse(fixture_data("push-event-multiple-commits.json"))
196
+ push = JSON.parse(fixture_data("push-event-multiple-commits.json"))
197
+ push = fill_extra_fields(push)
133
198
  base = "https://api.github.com/repos/clear-code/fluent-plugin-github-activities/commits"
134
- @crawler.process_user_event("user", event)
199
+ @crawler.process_user_event("user", push)
200
+
201
+ expected_commit = JSON.parse(fixture_data("commit.json"))
202
+ expected_push = JSON.parse(fixture_data("push-event-multiple-commits.json"))
203
+
204
+ expected_commit = fill_extra_fields(expected_commit, expected_push)
205
+
206
+ expected_push = fill_extra_fields(expected_push)
135
207
  expected = {
136
208
  :request_queue => [
137
209
  { :type => ::Fluent::GithubActivities::TYPE_COMMIT,
138
- :uri => "#{base}/8e90721ff5d89f52b5b3adf0b86db01f03dc5588"},
210
+ :uri => "#{base}/8e90721ff5d89f52b5b3adf0b86db01f03dc5588",
211
+ :sha => "8e90721ff5d89f52b5b3adf0b86db01f03dc5588",
212
+ :push => expected_push },
139
213
  { :type => ::Fluent::GithubActivities::TYPE_COMMIT,
140
- :uri => "#{base}/63e085b7607a3043cfbf9a866561807fbdda8a10"},
214
+ :uri => "#{base}/63e085b7607a3043cfbf9a866561807fbdda8a10",
215
+ :sha => "63e085b7607a3043cfbf9a866561807fbdda8a10",
216
+ :push => expected_push },
141
217
  { :type => ::Fluent::GithubActivities::TYPE_COMMIT,
142
- :uri => "#{base}/c85e33bace040b7b42983e14d2b11a491d102072"},
218
+ :uri => "#{base}/c85e33bace040b7b42983e14d2b11a491d102072",
219
+ :sha => "c85e33bace040b7b42983e14d2b11a491d102072",
220
+ :push => expected_push },
143
221
  { :type => ::Fluent::GithubActivities::TYPE_COMMIT,
144
- :uri => "#{base}/8ce6de7582376187e17e233dbae13575311a8c0b"},
222
+ :uri => "#{base}/8ce6de7582376187e17e233dbae13575311a8c0b",
223
+ :sha => "8ce6de7582376187e17e233dbae13575311a8c0b",
224
+ :push => expected_push },
145
225
  { :type => ::Fluent::GithubActivities::TYPE_COMMIT,
146
- :uri => "#{base}/c908f319c7b6d5c5a69c8b675bde40dd990ee364"},
226
+ :uri => "#{base}/c908f319c7b6d5c5a69c8b675bde40dd990ee364",
227
+ :sha => "c908f319c7b6d5c5a69c8b675bde40dd990ee364",
228
+ :push => expected_push },
147
229
  ],
148
230
  :emitted_records => [
149
- { :tag => "push",
150
- :record => event }
151
231
  ],
152
232
  }
153
233
  assert_equal(expected,
@@ -157,14 +237,14 @@ class CrawlerTest < Test::Unit::TestCase
157
237
  end
158
238
 
159
239
  class IssuesEventTest < self
160
- def test_multiple_commits
240
+ def test_issue_open
161
241
  event = JSON.parse(fixture_data("issues-event.json"))
162
242
  @crawler.process_user_event("user", event)
163
243
  expected = {
164
244
  :request_queue => [],
165
245
  :emitted_records => [
166
- { :tag => "issues",
167
- :record => event }
246
+ { :tag => "issue-open",
247
+ :record => fill_extra_fields(event) }
168
248
  ],
169
249
  }
170
250
  assert_equal(expected,
@@ -174,14 +254,14 @@ class CrawlerTest < Test::Unit::TestCase
174
254
  end
175
255
 
176
256
  class IssueCommentEventTest < self
177
- def test_multiple_commits
257
+ def test_issue_comment
178
258
  event = JSON.parse(fixture_data("issue-comment-event.json"))
179
259
  @crawler.process_user_event("user", event)
180
260
  expected = {
181
261
  :request_queue => [],
182
262
  :emitted_records => [
183
263
  { :tag => "issue-comment",
184
- :record => event }
264
+ :record => fill_extra_fields(event) }
185
265
  ],
186
266
  }
187
267
  assert_equal(expected,
@@ -198,7 +278,7 @@ class CrawlerTest < Test::Unit::TestCase
198
278
  :request_queue => [],
199
279
  :emitted_records => [
200
280
  { :tag => "commit-comment",
201
- :record => event }
281
+ :record => fill_extra_fields(event) }
202
282
  ],
203
283
  }
204
284
  assert_equal(expected,
@@ -215,7 +295,7 @@ class CrawlerTest < Test::Unit::TestCase
215
295
  :request_queue => [],
216
296
  :emitted_records => [
217
297
  { :tag => "fork",
218
- :record => event }
298
+ :record => fill_extra_fields(event) }
219
299
  ],
220
300
  }
221
301
  assert_equal(expected,
@@ -232,7 +312,7 @@ class CrawlerTest < Test::Unit::TestCase
232
312
  :request_queue => [],
233
313
  :emitted_records => [
234
314
  { :tag => "pull-request",
235
- :record => event }
315
+ :record => fill_extra_fields(event) }
236
316
  ],
237
317
  }
238
318
  assert_equal(expected,
@@ -242,14 +322,29 @@ class CrawlerTest < Test::Unit::TestCase
242
322
  end
243
323
 
244
324
  class CommitTest < self
245
- def test_multiple_commits
325
+ def test_commit
246
326
  commit = JSON.parse(fixture_data("commit.json"))
247
- @crawler.process_commit(commit)
327
+ push = JSON.parse(fixture_data("push-event.json"))
328
+ push = fill_extra_fields(push)
329
+ @crawler.process_commit(commit, push)
330
+
331
+ expected_commit = JSON.parse(fixture_data("commit.json"))
332
+ expected_push = JSON.parse(fixture_data("push-event.json"))
333
+
334
+ expected_commit = fill_extra_fields(expected_commit, expected_push)
335
+
336
+ expected_push["payload"]["commits"].each do |commit|
337
+ commit["commit"] = expected_commit
338
+ end
339
+ expected_push = fill_extra_fields(expected_push)
340
+
248
341
  expected = {
249
342
  :request_queue => [],
250
343
  :emitted_records => [
251
344
  { :tag => "commit",
252
- :record => commit }
345
+ :record => expected_commit },
346
+ { :tag => "push",
347
+ :record => expected_push }
253
348
  ],
254
349
  }
255
350
  assert_equal(expected,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-github-activities
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - YUKI Hiroshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-29 00:00:00.000000000 Z
11
+ date: 2015-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -121,6 +121,7 @@ files:
121
121
  - test/fixture/pull-request-comment-event.json
122
122
  - test/fixture/pull-request-event.json
123
123
  - test/fixture/push-event-multiple-commits.json
124
+ - test/fixture/push-event.json
124
125
  - test/run-test.rb
125
126
  - test/test_crawler.rb
126
127
  homepage: https://github.com/groonga/fluent-plugin-groonga
@@ -153,6 +154,7 @@ test_files:
153
154
  - test/run-test.rb
154
155
  - test/fixture/pull-request-event.json
155
156
  - test/fixture/push-event-multiple-commits.json
157
+ - test/fixture/push-event.json
156
158
  - test/fixture/issue-comment-event.json
157
159
  - test/fixture/fork-event.json
158
160
  - test/fixture/line-note-event.json