fluent-plugin-github-activities 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby; coding: utf-8 -*-
3
+ #
4
+ # This file is part of fluent-plugin-github-activities.
5
+ #
6
+ # fluent-plugin-github-activities is free software: you can
7
+ # redistribute it and/or modify it under the terms of the GNU Lesser
8
+ # General Public License as published by the Free Software
9
+ # Foundation, either version 3 of the License, or (at your option)
10
+ # any later version.
11
+ #
12
+ # fluent-plugin-github-activities is distributed in the hope that
13
+ # it will be useful, but WITHOUT ANY WARRANTY; without even the
14
+ # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
+ # PURPOSE. See the GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public
18
+ # License along with fluent-plugin-github-activities. If not, see
19
+ # <http://www.gnu.org/licenses/>.
20
+
21
+ base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
22
+ lib_dir = File.join(base_dir, "lib")
23
+ test_dir = File.join(base_dir, "test")
24
+
25
+ require "test-unit"
26
+ require "test/unit/notify"
27
+
28
+ $LOAD_PATH.unshift(lib_dir)
29
+
30
+ require_relative "fixture"
31
+ class Test::Unit::TestCase
32
+ include ::Fixture
33
+ end
34
+
35
+ exit(Test::Unit::AutoRunner.run(true, test_dir))
@@ -0,0 +1,260 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+ #
3
+ # This file is part of fluent-plugin-github-activities.
4
+ #
5
+ # fluent-plugin-github-activities is free software: you can
6
+ # redistribute it and/or modify it under the terms of the GNU Lesser
7
+ # General Public License as published by the Free Software
8
+ # Foundation, either version 3 of the License, or (at your option)
9
+ # any later version.
10
+ #
11
+ # fluent-plugin-github-activities is distributed in the hope that
12
+ # it will be useful, but WITHOUT ANY WARRANTY; without even the
13
+ # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14
+ # PURPOSE. See the GNU Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with fluent-plugin-github-activities. If not, see
18
+ # <http://www.gnu.org/licenses/>.
19
+
20
+ require "json"
21
+
22
+ require "fluent/plugin/github-activities"
23
+
24
+ class CrawlerTest < Test::Unit::TestCase
25
+ def setup
26
+ @emitted_records = []
27
+
28
+ @crawler = ::Fluent::GithubActivities::Crawler.new
29
+ @crawler.on_emit = lambda do |tag, record|
30
+ @emitted_records << { :tag => tag,
31
+ :record => record }
32
+ end
33
+ end
34
+
35
+ REQUEST_PATTERNS = {
36
+ :user_events => {
37
+ :request => { :type => :events,
38
+ :user => "username" },
39
+ :uri => "https://api.github.com/users/username/events/public",
40
+ :headers => {},
41
+ },
42
+ :user_events_with_previous_request => {
43
+ :request => { :type => :events,
44
+ :user => "username",
45
+ :previous_entity_tag => "aaaaa",
46
+ :process_after => 29 },
47
+ :uri => "https://api.github.com/users/username/events/public",
48
+ :headers => {
49
+ "If-None-Match" => "aaaaa",
50
+ },
51
+ },
52
+ }
53
+
54
+ data(REQUEST_PATTERNS)
55
+ def test_request_uri(data)
56
+ uri = @crawler.request_uri(data[:request])
57
+ assert_equal(URI(data[:uri]), uri)
58
+ end
59
+
60
+ data(REQUEST_PATTERNS)
61
+ def extra_request_headers(data)
62
+ headers = @crawler.extra_request_headers(data[:request])
63
+ assert_equal(data[:headers], headers)
64
+ end
65
+
66
+ class ReserveUserEventsTest < self
67
+ def test_without_previous_response
68
+ now = Time.now
69
+ @crawler.reserve_user_events("username",
70
+ :now => now)
71
+ expected_request = {
72
+ :type => :events,
73
+ :user => "username",
74
+ }
75
+ assert_equal([expected_request],
76
+ @crawler.request_queue)
77
+ end
78
+
79
+ def test_with_previous_response
80
+ now = Time.now
81
+ @crawler.reserve_user_events("username",
82
+ :now => now,
83
+ :previous_response => {
84
+ "ETag" => "aaaaa",
85
+ "X-Poll-Interval" => 60,
86
+ })
87
+ expected_request = {
88
+ :type => :events,
89
+ :user => "username",
90
+ :previous_entity_tag => "aaaaa",
91
+ :process_after => now.to_i + 60,
92
+ }
93
+ assert_equal([expected_request],
94
+ @crawler.request_queue)
95
+ end
96
+ end
97
+
98
+ class UserEventTest < self
99
+ def test_generic
100
+ @crawler.process_user_event("username", { "type" => "test" })
101
+ expected = {
102
+ :request_queue => [],
103
+ :emitted_records => [
104
+ { :tag => "test",
105
+ :record => { "type" => "test" } },
106
+ ],
107
+ }
108
+ assert_equal(expected,
109
+ { :request_queue => @crawler.request_queue,
110
+ :emitted_records => @emitted_records })
111
+ end
112
+ end
113
+
114
+ class UserEventsTest < self
115
+ def test_generic
116
+ @crawler.process_user_events("username", [{ "type" => "test" }])
117
+ expected = {
118
+ :request_queue => [],
119
+ :emitted_records => [
120
+ { :tag => "test",
121
+ :record => { "type" => "test" } },
122
+ ],
123
+ }
124
+ assert_equal(expected,
125
+ { :request_queue => @crawler.request_queue,
126
+ :emitted_records => @emitted_records })
127
+ end
128
+ end
129
+
130
+ class PushEventTest < self
131
+ def test_multiple_commits
132
+ event = JSON.parse(fixture_data("push-event-multiple-commits.json"))
133
+ base = "https://api.github.com/repos/clear-code/fluent-plugin-github-activities/commits"
134
+ @crawler.process_user_event("user", event)
135
+ expected = {
136
+ :request_queue => [
137
+ { :type => ::Fluent::GithubActivities::TYPE_COMMIT,
138
+ :uri => "#{base}/8e90721ff5d89f52b5b3adf0b86db01f03dc5588"},
139
+ { :type => ::Fluent::GithubActivities::TYPE_COMMIT,
140
+ :uri => "#{base}/63e085b7607a3043cfbf9a866561807fbdda8a10"},
141
+ { :type => ::Fluent::GithubActivities::TYPE_COMMIT,
142
+ :uri => "#{base}/c85e33bace040b7b42983e14d2b11a491d102072"},
143
+ { :type => ::Fluent::GithubActivities::TYPE_COMMIT,
144
+ :uri => "#{base}/8ce6de7582376187e17e233dbae13575311a8c0b"},
145
+ { :type => ::Fluent::GithubActivities::TYPE_COMMIT,
146
+ :uri => "#{base}/c908f319c7b6d5c5a69c8b675bde40dd990ee364"},
147
+ ],
148
+ :emitted_records => [
149
+ { :tag => "push",
150
+ :record => event }
151
+ ],
152
+ }
153
+ assert_equal(expected,
154
+ { :request_queue => @crawler.request_queue,
155
+ :emitted_records => @emitted_records })
156
+ end
157
+ end
158
+
159
+ class IssuesEventTest < self
160
+ def test_multiple_commits
161
+ event = JSON.parse(fixture_data("issues-event.json"))
162
+ @crawler.process_user_event("user", event)
163
+ expected = {
164
+ :request_queue => [],
165
+ :emitted_records => [
166
+ { :tag => "issues",
167
+ :record => event }
168
+ ],
169
+ }
170
+ assert_equal(expected,
171
+ { :request_queue => @crawler.request_queue,
172
+ :emitted_records => @emitted_records })
173
+ end
174
+ end
175
+
176
+ class IssueCommentEventTest < self
177
+ def test_multiple_commits
178
+ event = JSON.parse(fixture_data("issue-comment-event.json"))
179
+ @crawler.process_user_event("user", event)
180
+ expected = {
181
+ :request_queue => [],
182
+ :emitted_records => [
183
+ { :tag => "issue-comment",
184
+ :record => event }
185
+ ],
186
+ }
187
+ assert_equal(expected,
188
+ { :request_queue => @crawler.request_queue,
189
+ :emitted_records => @emitted_records })
190
+ end
191
+ end
192
+
193
+ class CommitCommentEventTest < self
194
+ def test_multiple_commits
195
+ event = JSON.parse(fixture_data("commit-comment-event.json"))
196
+ @crawler.process_user_event("user", event)
197
+ expected = {
198
+ :request_queue => [],
199
+ :emitted_records => [
200
+ { :tag => "commit-comment",
201
+ :record => event }
202
+ ],
203
+ }
204
+ assert_equal(expected,
205
+ { :request_queue => @crawler.request_queue,
206
+ :emitted_records => @emitted_records })
207
+ end
208
+ end
209
+
210
+ class ForkEventTest < self
211
+ def test_multiple_commits
212
+ event = JSON.parse(fixture_data("fork-event.json"))
213
+ @crawler.process_user_event("user", event)
214
+ expected = {
215
+ :request_queue => [],
216
+ :emitted_records => [
217
+ { :tag => "fork",
218
+ :record => event }
219
+ ],
220
+ }
221
+ assert_equal(expected,
222
+ { :request_queue => @crawler.request_queue,
223
+ :emitted_records => @emitted_records })
224
+ end
225
+ end
226
+
227
+ class PullRequestEventTest < self
228
+ def test_multiple_commits
229
+ event = JSON.parse(fixture_data("pull-request-event.json"))
230
+ @crawler.process_user_event("user", event)
231
+ expected = {
232
+ :request_queue => [],
233
+ :emitted_records => [
234
+ { :tag => "pull-request",
235
+ :record => event }
236
+ ],
237
+ }
238
+ assert_equal(expected,
239
+ { :request_queue => @crawler.request_queue,
240
+ :emitted_records => @emitted_records })
241
+ end
242
+ end
243
+
244
+ class CommitTest < self
245
+ def test_multiple_commits
246
+ commit = JSON.parse(fixture_data("commit.json"))
247
+ @crawler.process_commit(commit)
248
+ expected = {
249
+ :request_queue => [],
250
+ :emitted_records => [
251
+ { :tag => "commit",
252
+ :record => commit }
253
+ ],
254
+ }
255
+ assert_equal(expected,
256
+ { :request_queue => @crawler.request_queue,
257
+ :emitted_records => @emitted_records })
258
+ end
259
+ end
260
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-github-activities
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - YUKI Hiroshi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: packnga
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: test-unit
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: test-unit-notify
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: This provides ability you fluentd to crawl public activities of users.
98
+ email:
99
+ - yuki@clear-code.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - Gemfile
105
+ - README.md
106
+ - fluent-plugin-github-activities.gemspec
107
+ - lib/fluent/plugin/github-activities.rb
108
+ - lib/fluent/plugin/github-activities/crawler.rb
109
+ - lib/fluent/plugin/github-activities/safe_file_writer.rb
110
+ - lib/fluent/plugin/in_github-activities.rb
111
+ - test/fixture.rb
112
+ - test/fixture/accept-pull-request-event.json
113
+ - test/fixture/branch-event.json
114
+ - test/fixture/commit-comment-event.json
115
+ - test/fixture/commit.json
116
+ - test/fixture/fork-event.json
117
+ - test/fixture/issue-comment-event.json
118
+ - test/fixture/issues-event.json
119
+ - test/fixture/line-note-event.json
120
+ - test/fixture/pull-request-accepted-event.json
121
+ - test/fixture/pull-request-comment-event.json
122
+ - test/fixture/pull-request-event.json
123
+ - test/fixture/push-event-multiple-commits.json
124
+ - test/run-test.rb
125
+ - test/test_crawler.rb
126
+ homepage: https://github.com/groonga/fluent-plugin-groonga
127
+ licenses:
128
+ - LGPL-3.0
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 2.4.1
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Fluentd plugin to crawl public activities on the GitHub.
150
+ test_files:
151
+ - test/test_crawler.rb
152
+ - test/fixture.rb
153
+ - test/run-test.rb
154
+ - test/fixture/pull-request-event.json
155
+ - test/fixture/push-event-multiple-commits.json
156
+ - test/fixture/issue-comment-event.json
157
+ - test/fixture/fork-event.json
158
+ - test/fixture/line-note-event.json
159
+ - test/fixture/commit-comment-event.json
160
+ - test/fixture/branch-event.json
161
+ - test/fixture/accept-pull-request-event.json
162
+ - test/fixture/issues-event.json
163
+ - test/fixture/commit.json
164
+ - test/fixture/pull-request-comment-event.json
165
+ - test/fixture/pull-request-accepted-event.json
166
+ has_rdoc: