fluent-plugin-github-activities 0.6.1 → 0.7.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: 5dd3655e789cb8a28e01800ea4830c625e51448e
4
- data.tar.gz: b1340b9cdbf980e093042c4a9337fe3d4ad17e14
3
+ metadata.gz: 5566e97e3de09ccc09711e64cf7fae99072925f5
4
+ data.tar.gz: b114642700ecda10abe35598ce12bbc988879176
5
5
  SHA512:
6
- metadata.gz: cba2954b4c6014fc8623d7303a53b890f1d809ebcd8b1b52a24fd9978be6bdc06e806cf31f1a7bc977dcfa07965f42c8f0b6bfe9e85551ff662666fd2600ac55
7
- data.tar.gz: 6d21cf6f0243a5b0d4f184b45eee9ce926a2e48902f53c4ab96580c65789c13d794f04d235bde8f5fae36907aac2b6776d627ad363d0209185e516f468bd133a
6
+ metadata.gz: 1f2a08171cf6e4dbf37163a41d1d77185e60123377b3bfcda9f75a53e203b29eee3d6f30d50da607c6fda7dde13162028ab01ef14bf4871f5738fa1a161b7dd1
7
+ data.tar.gz: f85cc6dc814b6349c1f86d8ecd74b1f30c484aed23bb9000a011cbb43ab0e58c3af6d7d47ade7ce705a958cce6bd5735c2ea61508324491bfec5f2ef057305c7
data/README.md CHANGED
@@ -6,6 +6,29 @@
6
6
  Provides ability to watch public activities on GitHub.
7
7
  This crawls GitHub activities of specified users and forward each activity as a record.
8
8
 
9
+ ## Requirements
10
+
11
+ | fluent-plugin-github-activities | fluentd | ruby |
12
+ |---------------------------------|------------|--------|
13
+ | >= 0.7.0 | >= v0.14.0 | >= 2.1 |
14
+ | < 0.7.0 | >= v0.12.0 | >= 1.9 |
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'fluent-plugin-github-activities'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install fluent-plugin-github-activities
31
+
9
32
  ## Supported activity types
10
33
 
11
34
  * Activities related to commits
@@ -94,11 +117,6 @@ Then the value of the `token` field is the access key to be written to the confi
94
117
  # Number of clients. This is `4` by default.
95
118
  clients 1
96
119
 
97
- # Path to a file to store timestamp of last crawled activity
98
- # for each user. If you don't specify this option, same records
99
- # can be forwarded after the fluentd is restarted.
100
- pos_file /tmp/github-activities.json
101
-
102
120
  # Base tag of forwarded records. It will be used as
103
121
  # <base_tag>.<activity type>, like: "github-activity.push",
104
122
  # "github-activity.StatusEvent", etc.
@@ -123,3 +141,20 @@ Then the value of the `token` field is the access key to be written to the confi
123
141
  #include_foreign_commits true
124
142
  </source>
125
143
  ~~~
144
+
145
+ ### Breaking changes
146
+
147
+ `pos_file` is obsoleted since 0.7.0. Use storage instead as following:
148
+
149
+ ```
150
+ <source>
151
+ @type github-activities
152
+ <storage>
153
+ @type local
154
+ persistent true
155
+ # or if you want to take over old pos_file,
156
+ # path parameter must be end with ".json".
157
+ # path /path/to/pos_file.json
158
+ </storage>
159
+ </source>
160
+ ```
@@ -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.6.1"
22
+ spec.version = "0.7.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."
@@ -33,11 +33,12 @@ Gem::Specification.new do |spec|
33
33
  spec.test_files += Dir.glob("test/**/*")
34
34
  spec.require_paths = ["lib"]
35
35
 
36
- spec.add_runtime_dependency("fluentd", [">= 0.12.0", "< 0.14.0"])
36
+ spec.add_runtime_dependency("fluentd", [">= 0.14.13", "< 2"])
37
37
 
38
38
  spec.add_development_dependency("rake")
39
39
  spec.add_development_dependency("bundler")
40
40
  spec.add_development_dependency("packnga", ">= 1.0.1")
41
41
  spec.add_development_dependency("test-unit")
42
42
  spec.add_development_dependency("test-unit-notify")
43
+ spec.add_development_dependency("webmock")
43
44
  end
@@ -21,8 +21,10 @@ require "fluent/plugin/github-activities/users_manager"
21
21
  require "fluent/plugin/github-activities/crawler"
22
22
 
23
23
  module Fluent
24
- module GithubActivities
25
- TYPE_EVENTS = :events
26
- TYPE_COMMIT = :commit
24
+ module Plugin
25
+ module GithubActivities
26
+ TYPE_EVENTS = :events
27
+ TYPE_COMMIT = :commit
28
+ end
27
29
  end
28
30
  end
@@ -25,311 +25,322 @@ require "time"
25
25
  require "fluent/plugin/github-activities/users_manager"
26
26
 
27
27
  module Fluent
28
- module GithubActivities
29
- class Crawler
30
- class EmptyRequestQueue < StandardError
31
- end
28
+ module Plugin
29
+ module GithubActivities
30
+ class Crawler
31
+ class EmptyRequestQueue < StandardError
32
+ end
32
33
 
33
- NO_INTERVAL = 0
34
- DEFAULT_INTERVAL = 1
34
+ NO_INTERVAL = 0
35
+ DEFAULT_INTERVAL = 1
35
36
 
36
- RELATED_USER_IMAGE_KEY = "$github-activities-related-avatar"
37
- RELATED_ORGANIZATION_IMAGE_KEY = "$github-activities-related-organization-logo"
38
- RELATED_EVENT = "$github-activities-related-event"
37
+ RELATED_USER_IMAGE_KEY = "$github-activities-related-avatar"
38
+ RELATED_ORGANIZATION_IMAGE_KEY = "$github-activities-related-organization-logo"
39
+ RELATED_EVENT = "$github-activities-related-event"
39
40
 
40
- attr_writer :on_emit
41
- attr_reader :request_queue, :interval_for_next_request
41
+ attr_writer :on_emit
42
+ attr_reader :request_queue, :interval_for_next_request, :log, :running
42
43
 
43
- def initialize(options={})
44
- @users_manager = UsersManager.new(:users => options[:watching_users],
45
- :pos_file => options[:pos_file])
44
+ def initialize(options={})
45
+ @users_manager = UsersManager.new(users: options[:watching_users],
46
+ pos_storage: options[:pos_storage])
46
47
 
47
- @access_token = options[:access_token]
48
+ @access_token = options[:access_token]
48
49
 
49
- @watching_users = options[:watching_users] || []
50
+ @watching_users = options[:watching_users] || []
50
51
 
51
- @include_commits_from_pull_request = options[:include_commits_from_pull_request]
52
- @include_foreign_commits = options[:include_foreign_commits]
52
+ @include_commits_from_pull_request = options[:include_commits_from_pull_request]
53
+ @include_foreign_commits = options[:include_foreign_commits]
53
54
 
54
- @request_queue = options[:request_queue] || []
55
+ @request_queue = options[:request_queue] || []
55
56
 
56
- @default_interval = options[:default_interval] || DEFAULT_INTERVAL
57
- end
58
-
59
- def process_request
60
- request = @request_queue.shift
61
- $log.debug("GithubActivities::Crawler: processing request: #{request.inspect}") if $log
62
- if request[:process_after] and
63
- Time.now.to_i < request[:process_after]
64
- @request_queue.push(request)
65
- @interval_for_next_request = NO_INTERVAL
66
- return false
57
+ @default_interval = options[:default_interval] || DEFAULT_INTERVAL
58
+ @interval_for_next_request = @default_interval
59
+ # Fluent::PluginLogger instance
60
+ @log = options[:log]
61
+ @running = true
67
62
  end
68
63
 
69
- uri = request_uri(request)
70
- extra_headers = extra_request_headers(request)
71
-
72
- $log.debug("GithubActivities::Crawler: requesting to #{uri.inspect}") if $log
73
- response = http_get(uri, extra_headers)
74
- $log.debug("GithubActivities::Crawler: response: #{response.inspect}") if $log
75
-
76
- case response
77
- when Net::HTTPSuccess
78
- $log.trace("GithubActivities::Crawler: Net::HTTPSuccess / request type: #{request[:type]}") if $log
79
- body = JSON.parse(response.body)
80
- case request[:type]
81
- when TYPE_EVENTS
82
- events = body
83
- $log.trace("GithubActivities::Crawler: events size: #{events.size}") if $log
84
- process_user_events(request[:user], events)
85
- reserve_user_events(request[:user], :previous_response => response)
86
- @users_manager.save_position_for(request[:user], :entity_tag => response["ETag"])
87
- when TYPE_COMMIT
88
- process_commit(body, request[:push])
64
+ def process_request
65
+ request = @request_queue.shift
66
+ log.debug("GithubActivities::Crawler: processing request: #{request.inspect}")
67
+ if request[:process_after] and
68
+ Time.now.to_i < request[:process_after]
69
+ @request_queue.push(request)
70
+ @interval_for_next_request = NO_INTERVAL
71
+ return false
89
72
  end
90
- when Net::HTTPNotModified
91
- $log.trace("GithubActivities::Crawler: Net::HTTPNotModified / request type: #{request[:type]}") if $log
92
- case request[:type]
93
- when TYPE_EVENTS
94
- reserve_user_events(request[:user],
95
- :previous_response => response,
96
- :previous_entity_tag => extra_headers["If-None-Match"])
73
+
74
+ uri = request_uri(request)
75
+ extra_headers = extra_request_headers(request)
76
+
77
+ log.debug("GithubActivities::Crawler: requesting to #{uri.inspect}")
78
+ response = http_get(uri, extra_headers)
79
+ log.debug("GithubActivities::Crawler: response: #{response.inspect}")
80
+
81
+ case response
82
+ when Net::HTTPSuccess
83
+ log.trace("GithubActivities::Crawler: Net::HTTPSuccess / request type: #{request[:type]}")
84
+ body = JSON.parse(response.body)
85
+ case request[:type]
86
+ when TYPE_EVENTS
87
+ events = body
88
+ log.trace("GithubActivities::Crawler: events size: #{events.size}")
89
+ process_user_events(request[:user], events)
90
+ reserve_user_events(request[:user], previous_response: response)
91
+ @users_manager.save_position_for(request[:user], entity_tag: response["ETag"])
92
+ when TYPE_COMMIT
93
+ process_commit(body, request[:push])
94
+ end
95
+ when Net::HTTPNotModified
96
+ log.trace("GithubActivities::Crawler: Net::HTTPNotModified / request type: #{request[:type]}")
97
+ case request[:type]
98
+ when TYPE_EVENTS
99
+ reserve_user_events(request[:user],
100
+ previous_response: response,
101
+ previous_entity_tag: extra_headers["If-None-Match"])
102
+ end
103
+ @interval_for_next_request = @default_interval
104
+ return true
105
+ else
106
+ log.trace("GithubActivities::Crawler: UnknownType / request type: #{request[:type]}")
107
+ case request[:type]
108
+ when TYPE_COMMIT
109
+ fake_body = {
110
+ "sha" => request[:sha],
111
+ "author" => {},
112
+ }
113
+ process_commit(fake_body, request[:push])
114
+ end
97
115
  end
98
116
  @interval_for_next_request = @default_interval
99
117
  return true
100
- else
101
- $log.trace("GithubActivities::Crawler: UnknownType / request type: #{request[:type]}") if $log
102
- case request[:type]
103
- when TYPE_COMMIT
104
- fake_body = {
105
- "sha" => request[:sha],
106
- "author" => {},
107
- }
108
- process_commit(fake_body, request[:push])
109
- end
118
+ rescue StandardError => error
119
+ log.error(error.inspect)
110
120
  end
111
- @interval_for_next_request = @default_interval
112
- return true
113
- rescue StandardError => error
114
- $log.error(error.inspect)
115
- end
116
121
 
117
- def request_uri(request)
118
- uri = nil
119
- case request[:type]
120
- when TYPE_EVENTS
121
- uri = user_activities(request[:user])
122
- else
123
- uri = request[:uri]
122
+ def request_uri(request)
123
+ uri = nil
124
+ case request[:type]
125
+ when TYPE_EVENTS
126
+ uri = user_activities(request[:user])
127
+ else
128
+ uri = request[:uri]
129
+ end
124
130
  end
125
- end
126
131
 
127
- def extra_request_headers(request)
128
- headers = {}
129
- if request[:previous_entity_tag]
130
- headers["If-None-Match"] = request[:previous_entity_tag]
131
- elsif request[:type] == TYPE_EVENTS
132
- position = @users_manager.position_for(request[:user])
133
- if position
134
- entity_tag = position["entity_tag"]
135
- headers["If-None-Match"] = entity_tag if entity_tag
132
+ def extra_request_headers(request)
133
+ headers = {}
134
+ if request[:previous_entity_tag]
135
+ headers["If-None-Match"] = request[:previous_entity_tag]
136
+ elsif request[:type] == TYPE_EVENTS
137
+ position = @users_manager.position_for(request[:user])
138
+ if position
139
+ entity_tag = position["entity_tag"]
140
+ headers["If-None-Match"] = entity_tag if entity_tag
141
+ end
136
142
  end
143
+ headers
137
144
  end
138
- headers
139
- end
140
-
141
- def reserve_user_events(user, options={})
142
- request = @users_manager.new_events_request(user, options)
143
- @request_queue.push(request)
144
- end
145
145
 
146
- def process_user_events(user, events)
147
- last_event_timestamp = UsersManager::DEFAULT_LAST_EVENT_TIMESTAMP
148
- position = @users_manager.position_for(user)
149
- if position and position["last_event_timestamp"]
150
- last_event_timestamp = position["last_event_timestamp"]
146
+ def reserve_user_events(user, options={})
147
+ request = @users_manager.new_events_request(user, options)
148
+ @request_queue.push(request) if @running
151
149
  end
152
150
 
153
- events = events.sort do |a, b|
154
- b["created_at"] <=> a["created_at"]
155
- end
156
- events.each do |event|
157
- timestamp = Time.parse(event["created_at"]).to_i
158
- next if timestamp <= last_event_timestamp
159
- process_user_event(user, event)
160
- @users_manager.save_position_for(user, :last_event_timestamp => timestamp)
161
- end
162
- end
151
+ def process_user_events(user, events)
152
+ last_event_timestamp = UsersManager::DEFAULT_LAST_EVENT_TIMESTAMP
153
+ position = @users_manager.position_for(user)
154
+ if position and position["last_event_timestamp"]
155
+ last_event_timestamp = position["last_event_timestamp"]
156
+ end
163
157
 
164
- def process_user_event(user, event)
165
- # see also: https://developer.github.com/v3/activity/events/types/
166
- event[RELATED_USER_IMAGE_KEY] = event["actor"]["avatar_url"]
167
- if event["org"]
168
- event[RELATED_ORGANIZATION_IMAGE_KEY] = event["org"]["avatar_url"]
158
+ events = events.sort do |a, b|
159
+ b["created_at"] <=> a["created_at"]
160
+ end
161
+ events.each do |event|
162
+ timestamp = Time.parse(event["created_at"]).to_i
163
+ next if timestamp <= last_event_timestamp
164
+ process_user_event(user, event)
165
+ @users_manager.save_position_for(user, last_event_timestamp: timestamp)
166
+ end
169
167
  end
170
- case event["type"]
171
- when "PushEvent"
172
- process_push_event(event)
173
- when "CommitCommentEvent"
174
- emit("commit-comment", event)
175
- when "IssuesEvent"
176
- process_issue_event(event)
177
- when "IssueCommentEvent"
178
- process_issue_or_pull_request_comment_event(event)
179
- when "ForkEvent"
180
- emit("fork", event)
181
- when "PullRequestEvent"
182
- process_pull_request_event(event)
183
- when "CreateEvent"
184
- process_create_event(event)
185
- else
186
- emit(event["type"], event)
168
+
169
+ def process_user_event(user, event)
170
+ # see also: https://developer.github.com/v3/activity/events/types/
171
+ event[RELATED_USER_IMAGE_KEY] = event["actor"]["avatar_url"]
172
+ if event["org"]
173
+ event[RELATED_ORGANIZATION_IMAGE_KEY] = event["org"]["avatar_url"]
174
+ end
175
+ case event["type"]
176
+ when "PushEvent"
177
+ process_push_event(event)
178
+ when "CommitCommentEvent"
179
+ emit("commit-comment", event)
180
+ when "IssuesEvent"
181
+ process_issue_event(event)
182
+ when "IssueCommentEvent"
183
+ process_issue_or_pull_request_comment_event(event)
184
+ when "ForkEvent"
185
+ emit("fork", event)
186
+ when "PullRequestEvent"
187
+ process_pull_request_event(event)
188
+ when "CreateEvent"
189
+ process_create_event(event)
190
+ else
191
+ emit(event["type"], event)
192
+ end
193
+ rescue StandardError => error
194
+ log.fatal(error)
187
195
  end
188
- rescue StandardError => error
189
- $log.exception(error)
190
- end
191
196
 
192
- def process_push_event(event)
193
- payload = event["payload"]
194
- commit_refs = payload["commits"]
195
- if !@include_commits_from_pull_request and
197
+ def process_push_event(event)
198
+ return unless @running
199
+ payload = event["payload"]
200
+ commit_refs = payload["commits"]
201
+ if !@include_commits_from_pull_request and
196
202
  push_event_from_merged_pull_request?(event)
197
- return
198
- end
199
- commit_refs.reverse.each do |commit_ref|
200
- @request_queue.push(:type => TYPE_COMMIT,
201
- :uri => commit_ref["url"],
202
- :sha => commit_ref["sha"],
203
- :push => event)
203
+ return
204
+ end
205
+ commit_refs.reverse.each do |commit_ref|
206
+ @request_queue.push(type: TYPE_COMMIT,
207
+ uri: commit_ref["url"],
208
+ sha: commit_ref["sha"],
209
+ push: event)
210
+ end
211
+ # emit("push", event)
204
212
  end
205
- # emit("push", event)
206
- end
207
213
 
208
- def process_commit(commit, push_event)
209
- $log.debug("GithubActivities::Crawler: processing commit #{commit["sha"]}") if $log
210
- user = commit["author"]["login"]
214
+ def process_commit(commit, push_event)
215
+ log.debug("GithubActivities::Crawler: processing commit #{commit["sha"]}")
216
+ user = commit["author"]["login"]
217
+
218
+ if user and (@include_foreign_commits or watching_user?(user))
219
+ commit[RELATED_USER_IMAGE_KEY] = push_event["actor"]["avatar_url"]
220
+ if push_event["org"]
221
+ commit[RELATED_ORGANIZATION_IMAGE_KEY] = push_event["org"]["avatar_url"]
222
+ end
223
+ commit[RELATED_EVENT] = push_event.reject {|k, _| k == "payload" }
224
+ emit("commit", commit)
225
+ end
211
226
 
212
- if user and (@include_foreign_commits or watching_user?(user))
213
- commit[RELATED_USER_IMAGE_KEY] = push_event["actor"]["avatar_url"]
214
- if push_event["org"]
215
- commit[RELATED_ORGANIZATION_IMAGE_KEY] = push_event["org"]["avatar_url"]
227
+ commit_refs = push_event["payload"]["commits"]
228
+ target_commit_ref = commit_refs.find do |commit_ref|
229
+ commit_ref["sha"] == commit["sha"]
216
230
  end
217
- commit[RELATED_EVENT] = push_event.reject {|k, _| k == "payload" }
218
- emit("commit", commit)
219
- end
231
+ target_commit_ref["commit"] = commit if target_commit_ref
220
232
 
221
- commit_refs = push_event["payload"]["commits"]
222
- target_commit_ref = commit_refs.find do |commit_ref|
223
- commit_ref["sha"] == commit["sha"]
233
+ completely_fetched = commit_refs.all? do |commit_ref|
234
+ commit_ref["commit"]
235
+ end
236
+ emit("push", push_event) if completely_fetched
224
237
  end
225
- target_commit_ref["commit"] = commit if target_commit_ref
226
238
 
227
- completely_fetched = commit_refs.all? do |commit_ref|
228
- commit_ref["commit"]
239
+ def watching_user?(user)
240
+ @watching_users.include?(user)
229
241
  end
230
- emit("push", push_event) if completely_fetched
231
- end
232
-
233
- def watching_user?(user)
234
- @watching_users.include?(user)
235
- end
236
242
 
237
- def process_issue_event(event)
238
- payload = event["payload"]
239
- case payload["action"]
240
- when "opened"
241
- emit("issue-open", event)
242
- when "closed"
243
- emit("issue-close", event)
244
- when "reopened"
245
- emit("issue-reopen", event)
246
- when "assigned"
247
- emit("issue-assign", event)
248
- when "unassigned"
249
- emit("issue-unassign", event)
250
- when "labeled"
251
- emit("issue-label", event)
252
- when "unlabeled"
253
- emit("issue-unlabel", event)
243
+ def process_issue_event(event)
244
+ payload = event["payload"]
245
+ case payload["action"]
246
+ when "opened"
247
+ emit("issue-open", event)
248
+ when "closed"
249
+ emit("issue-close", event)
250
+ when "reopened"
251
+ emit("issue-reopen", event)
252
+ when "assigned"
253
+ emit("issue-assign", event)
254
+ when "unassigned"
255
+ emit("issue-unassign", event)
256
+ when "labeled"
257
+ emit("issue-label", event)
258
+ when "unlabeled"
259
+ emit("issue-unlabel", event)
260
+ end
254
261
  end
255
- end
256
262
 
257
- def process_pull_request_event(event)
258
- payload = event["payload"]
259
- case payload["action"]
260
- when "opened"
261
- emit("pull-request", event)
262
- when "closed"
263
- if payload["pull_request"]["merged"]
264
- emit("pull-request-merged", event)
265
- else
266
- emit("pull-request-cancelled", event)
263
+ def process_pull_request_event(event)
264
+ payload = event["payload"]
265
+ case payload["action"]
266
+ when "opened"
267
+ emit("pull-request", event)
268
+ when "closed"
269
+ if payload["pull_request"]["merged"]
270
+ emit("pull-request-merged", event)
271
+ else
272
+ emit("pull-request-cancelled", event)
273
+ end
274
+ when "reopened"
275
+ emit("pull-request-reopen", event)
267
276
  end
268
- when "reopened"
269
- emit("pull-request-reopen", event)
270
277
  end
271
- end
272
278
 
273
- MERGE_COMMIT_MESSAGE_PATTERN = /\AMerge pull request #\d+ from [^\/]+\/[^\/]+\n\n/
279
+ MERGE_COMMIT_MESSAGE_PATTERN = /\AMerge pull request #\d+ from [^\/]+\/[^\/]+\n\n/
274
280
 
275
- def push_event_from_merged_pull_request?(event)
276
- payload = event["payload"]
277
- inserted_requests = []
278
- commit_refs = payload["commits"]
279
- if MERGE_COMMIT_MESSAGE_PATTERN =~ commit_refs.last["message"]
280
- true
281
- else
282
- false
281
+ def push_event_from_merged_pull_request?(event)
282
+ payload = event["payload"]
283
+ inserted_requests = []
284
+ commit_refs = payload["commits"]
285
+ if MERGE_COMMIT_MESSAGE_PATTERN =~ commit_refs.last["message"]
286
+ true
287
+ else
288
+ false
289
+ end
283
290
  end
284
- end
285
291
 
286
- def process_issue_or_pull_request_comment_event(event)
287
- payload = event["payload"]
288
- if payload["issue"]["pull_request"]
289
- emit("pull-request-comment", event)
292
+ def process_issue_or_pull_request_comment_event(event)
293
+ payload = event["payload"]
294
+ if payload["issue"]["pull_request"]
295
+ emit("pull-request-comment", event)
290
296
  # emit("pull-request.cancel", event)
291
- else
292
- emit("issue-comment", event)
297
+ else
298
+ emit("issue-comment", event)
299
+ end
293
300
  end
294
- end
295
301
 
296
- def process_create_event(event)
297
- payload = event["payload"]
298
- case payload["ref_type"]
299
- when "branch"
300
- emit("branch", event)
301
- when "tag"
302
- emit("tag", event)
302
+ def process_create_event(event)
303
+ payload = event["payload"]
304
+ case payload["ref_type"]
305
+ when "branch"
306
+ emit("branch", event)
307
+ when "tag"
308
+ emit("tag", event)
309
+ end
303
310
  end
304
- end
305
311
 
306
- private
307
- def user_activities(user)
308
- "https://api.github.com/users/#{user}/events/public"
309
- end
312
+ def stop
313
+ @running = false
314
+ end
310
315
 
311
- def user_info(user)
312
- "https://api.github.com/users/#{user}"
313
- end
316
+ private
317
+ def user_activities(user)
318
+ "https://api.github.com/users/#{user}/events/public"
319
+ end
314
320
 
315
- def emit(tag, record)
316
- $log.trace("GithubActivities::Crawler: emit => #{tag}, #{record.inspect}") if $log
317
- @on_emit.call(tag, record) if @on_emit
318
- end
321
+ def user_info(user)
322
+ "https://api.github.com/users/#{user}"
323
+ end
319
324
 
320
- def http_get(uri, extra_headers={})
321
- parsed_uri = URI(uri)
322
- if @access_token
323
- extra_headers["Authorization"] = "token #{@access_token}"
325
+ def emit(tag, record)
326
+ log.trace("GithubActivities::Crawler: emit => #{tag}, #{record.inspect}")
327
+ @on_emit.call(tag, record) if @on_emit
324
328
  end
325
- response = nil
326
- http = Net::HTTP.new(parsed_uri.host, parsed_uri.port)
327
- http.use_ssl = parsed_uri.is_a?(URI::HTTPS)
328
- http.start do |http|
329
- http_request = Net::HTTP::Get.new(parsed_uri.path, extra_headers)
330
- response = http.request(http_request)
329
+
330
+ def http_get(uri, extra_headers={})
331
+ parsed_uri = URI(uri)
332
+ if @access_token
333
+ extra_headers["Authorization"] = "token #{@access_token}"
334
+ end
335
+ response = nil
336
+ http = Net::HTTP.new(parsed_uri.host, parsed_uri.port)
337
+ http.use_ssl = parsed_uri.is_a?(URI::HTTPS)
338
+ http.start do |http|
339
+ http_request = Net::HTTP::Get.new(parsed_uri.path, extra_headers)
340
+ response = http.request(http_request)
341
+ end
342
+ response
331
343
  end
332
- response
333
344
  end
334
345
  end
335
346
  end