jira_cache 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +10 -0
  3. data/.env.example +10 -0
  4. data/.env.test +10 -0
  5. data/.gitignore +15 -0
  6. data/.rspec +2 -0
  7. data/.rubocop.yml +12 -0
  8. data/.ruby-gemset +1 -0
  9. data/.ruby-version +1 -0
  10. data/.travis.yml +15 -0
  11. data/CODE_OF_CONDUCT.md +13 -0
  12. data/Gemfile +21 -0
  13. data/Guardfile +1 -0
  14. data/HISTORY.md +22 -0
  15. data/LICENSE.txt +22 -0
  16. data/README.md +73 -0
  17. data/Rakefile +7 -0
  18. data/VERSION +1 -0
  19. data/bin/console +11 -0
  20. data/bin/db/migrate +7 -0
  21. data/bin/db/psql +7 -0
  22. data/bin/db/reset +7 -0
  23. data/bin/setup +7 -0
  24. data/bin/sync +14 -0
  25. data/config.ru +7 -0
  26. data/config/Guardfile +35 -0
  27. data/config/boot.rb +11 -0
  28. data/config/db_migrations/001_create_issues.rb +21 -0
  29. data/docker-compose.yml +25 -0
  30. data/jira_cache.gemspec +41 -0
  31. data/lib/jira_cache.rb +53 -0
  32. data/lib/jira_cache/client.rb +185 -0
  33. data/lib/jira_cache/data.rb +10 -0
  34. data/lib/jira_cache/data/issue_repository.rb +94 -0
  35. data/lib/jira_cache/notifier.rb +30 -0
  36. data/lib/jira_cache/sync.rb +110 -0
  37. data/lib/jira_cache/version.rb +3 -0
  38. data/lib/jira_cache/webhook_app.rb +55 -0
  39. data/spec/fixtures/responses/get_issue_keys_jql_query_project=/"multiple_requests/"_start_at_0.json +1 -0
  40. data/spec/fixtures/responses/get_issue_keys_jql_query_project=/"multiple_requests/"_start_at_10.json +1 -0
  41. data/spec/fixtures/responses/get_issue_keys_jql_query_project=/"multiple_requests/"_start_at_5.json +1 -0
  42. data/spec/fixtures/responses/get_issue_keys_jql_query_project=/"single_request/"_start_at_0.json +1 -0
  43. data/spec/fixtures/responses/get_issue_many_worklogs.json +1 -0
  44. data/spec/fixtures/responses/get_issue_not_found.json +1 -0
  45. data/spec/fixtures/responses/get_issue_simple.json +1 -0
  46. data/spec/fixtures/responses/get_issue_worklog_many_worklogs.json +1 -0
  47. data/spec/spec_helper.rb +47 -0
  48. data/spec/support/response_fixture.rb +16 -0
  49. data/spec/unit/client_spec.rb +130 -0
  50. data/spec/unit/data/issue_repository_spec.rb +58 -0
  51. data/spec/unit/notifier_spec.rb +18 -0
  52. data/spec/unit/sync_spec.rb +116 -0
  53. data/spec/unit/webhook_app_spec.rb +96 -0
  54. metadata +280 -0
@@ -0,0 +1,96 @@
1
+ require "spec_helper"
2
+ require "jira_cache/webhook_app"
3
+ require "json"
4
+
5
+ describe JiraCache::WebhookApp do
6
+ include Rack::Test::Methods
7
+
8
+ def client_info
9
+ { "domain" => "test_domain", "username" => "test_user" }
10
+ end
11
+
12
+ def client
13
+ @client ||= double("JiraCache::Client", info: client_info, logger: nil)
14
+ end
15
+
16
+ def app
17
+ the_client = client
18
+ Sinatra.new(described_class) do
19
+ set :client, the_client
20
+ end
21
+ end
22
+
23
+ let(:sync_double) { double("Sync") }
24
+ before do
25
+ allow(JiraCache::Sync).to receive(:new).and_return(sync_double)
26
+ end
27
+
28
+ describe "GET /" do
29
+ let(:response) { get "/"; last_response }
30
+
31
+ it "responds a successful response" do
32
+ expect(response.status).to eq(200)
33
+ end
34
+
35
+ it "responds with the application name" do
36
+ expect(JSON.parse(response.body)["app"]).to eq("jira_cache/webhook_app")
37
+ end
38
+
39
+ it "responds with a status" do
40
+ expect(JSON.parse(response.body)["status"]).to eq("ok")
41
+ end
42
+
43
+ it "responds with the client info" do
44
+ expect(JSON.parse(response.body)["client"]).to eq(client_info)
45
+ end
46
+ end
47
+
48
+ describe "POST /" do
49
+
50
+ let(:payload) do
51
+ {
52
+ "webhookEvent": event,
53
+ "issue": issue
54
+ }
55
+ end
56
+ let(:issue) do
57
+ {
58
+ "key" => issue_key
59
+ }
60
+ end
61
+ let(:issue_key) { "issue_key" }
62
+
63
+ context "issue created" do
64
+ let(:event) { "jira:issue_created" }
65
+
66
+ it "syncs the created issue" do
67
+ expect(sync_double)
68
+ .to receive(:sync_issue)
69
+ .with(issue_key)
70
+ post "/", payload.to_json, "CONTENT-TYPE" => "application/json"
71
+ end
72
+ end
73
+
74
+ context "issue updated" do
75
+ let(:event) { "jira:issue_updated" }
76
+
77
+ it "syncs the updated issue" do
78
+ expect(sync_double)
79
+ .to receive(:sync_issue)
80
+ .with(issue_key)
81
+ post "/", payload.to_json, "CONTENT-TYPE" => "application/json"
82
+ end
83
+ end
84
+
85
+ context "issue deleted" do
86
+ let(:event) { "jira:issue_deleted" }
87
+
88
+ it "marks the issues as deleted" do
89
+ expect(sync_double)
90
+ .to receive(:mark_deleted)
91
+ .with([issue_key])
92
+ post "/", payload.to_json, "CONTENT-TYPE" => "application/json"
93
+ end
94
+ end
95
+ end
96
+ end
metadata ADDED
@@ -0,0 +1,280 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jira_cache
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Romain Champourlier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: i18n
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: activesupport-inflector
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: pg
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: sequel
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sequel_pg
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
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: rest-client
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sinatra
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: bundler
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.7'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.7'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '10.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '10.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: awesome_print
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: dotenv
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description:
182
+ email:
183
+ - pro@rchampourlier.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".codeclimate.yml"
189
+ - ".env.example"
190
+ - ".env.test"
191
+ - ".gitignore"
192
+ - ".rspec"
193
+ - ".rubocop.yml"
194
+ - ".ruby-gemset"
195
+ - ".ruby-version"
196
+ - ".travis.yml"
197
+ - CODE_OF_CONDUCT.md
198
+ - Gemfile
199
+ - Guardfile
200
+ - HISTORY.md
201
+ - LICENSE.txt
202
+ - README.md
203
+ - Rakefile
204
+ - VERSION
205
+ - bin/console
206
+ - bin/db/migrate
207
+ - bin/db/psql
208
+ - bin/db/reset
209
+ - bin/setup
210
+ - bin/sync
211
+ - config.ru
212
+ - config/Guardfile
213
+ - config/boot.rb
214
+ - config/db_migrations/001_create_issues.rb
215
+ - docker-compose.yml
216
+ - jira_cache.gemspec
217
+ - lib/jira_cache.rb
218
+ - lib/jira_cache/client.rb
219
+ - lib/jira_cache/data.rb
220
+ - lib/jira_cache/data/issue_repository.rb
221
+ - lib/jira_cache/notifier.rb
222
+ - lib/jira_cache/sync.rb
223
+ - lib/jira_cache/version.rb
224
+ - lib/jira_cache/webhook_app.rb
225
+ - spec/fixtures/responses/get_issue_keys_jql_query_project="multiple_requests"_start_at_0.json
226
+ - spec/fixtures/responses/get_issue_keys_jql_query_project="multiple_requests"_start_at_10.json
227
+ - spec/fixtures/responses/get_issue_keys_jql_query_project="multiple_requests"_start_at_5.json
228
+ - spec/fixtures/responses/get_issue_keys_jql_query_project="single_request"_start_at_0.json
229
+ - spec/fixtures/responses/get_issue_many_worklogs.json
230
+ - spec/fixtures/responses/get_issue_not_found.json
231
+ - spec/fixtures/responses/get_issue_simple.json
232
+ - spec/fixtures/responses/get_issue_worklog_many_worklogs.json
233
+ - spec/spec_helper.rb
234
+ - spec/support/response_fixture.rb
235
+ - spec/unit/client_spec.rb
236
+ - spec/unit/data/issue_repository_spec.rb
237
+ - spec/unit/notifier_spec.rb
238
+ - spec/unit/sync_spec.rb
239
+ - spec/unit/webhook_app_spec.rb
240
+ homepage: https://github.com/rchampourlier/jira_cache
241
+ licenses:
242
+ - MIT
243
+ metadata:
244
+ allowed_push_host: https://rubygems.org
245
+ post_install_message:
246
+ rdoc_options: []
247
+ require_paths:
248
+ - lib
249
+ required_ruby_version: !ruby/object:Gem::Requirement
250
+ requirements:
251
+ - - ">="
252
+ - !ruby/object:Gem::Version
253
+ version: '0'
254
+ required_rubygems_version: !ruby/object:Gem::Requirement
255
+ requirements:
256
+ - - ">="
257
+ - !ruby/object:Gem::Version
258
+ version: '0'
259
+ requirements: []
260
+ rubyforge_project:
261
+ rubygems_version: 2.5.1
262
+ signing_key:
263
+ specification_version: 4
264
+ summary: Fetches data from JIRA and caches it in a local database.
265
+ test_files:
266
+ - spec/fixtures/responses/get_issue_keys_jql_query_project="multiple_requests"_start_at_0.json
267
+ - spec/fixtures/responses/get_issue_keys_jql_query_project="multiple_requests"_start_at_10.json
268
+ - spec/fixtures/responses/get_issue_keys_jql_query_project="multiple_requests"_start_at_5.json
269
+ - spec/fixtures/responses/get_issue_keys_jql_query_project="single_request"_start_at_0.json
270
+ - spec/fixtures/responses/get_issue_many_worklogs.json
271
+ - spec/fixtures/responses/get_issue_not_found.json
272
+ - spec/fixtures/responses/get_issue_simple.json
273
+ - spec/fixtures/responses/get_issue_worklog_many_worklogs.json
274
+ - spec/spec_helper.rb
275
+ - spec/support/response_fixture.rb
276
+ - spec/unit/client_spec.rb
277
+ - spec/unit/data/issue_repository_spec.rb
278
+ - spec/unit/notifier_spec.rb
279
+ - spec/unit/sync_spec.rb
280
+ - spec/unit/webhook_app_spec.rb