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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 150824534aedbe261c0c3b126f7055e1f2072065
4
+ data.tar.gz: e96cbfcf5b638b4666b6a5e12524324f3dc9891e
5
+ SHA512:
6
+ metadata.gz: e13ead3a828a3353abad58a2253494e61235ab5a8a98d1b5ae5aa131236079f6054902ecd62b68e3705eca4e62b7d70f5f80a62153926ca6a45cca43e8777af4
7
+ data.tar.gz: 97da7cfc2f762fc650e51662b9391619cdfdbb5138c6f9e1173e1072de20c4ec969e025ffaf88ac03cfddbac4a4eaa3a6764ce71552be55a8d0be08f18dc30e8
data/.codeclimate.yml ADDED
@@ -0,0 +1,10 @@
1
+ engines:
2
+ rubocop:
3
+ enabled: true
4
+ ratings:
5
+ paths:
6
+ - config/**
7
+ - lib/**
8
+ - "**.rb"
9
+ exclude_paths:
10
+ - spec/**/*
data/.env.example ADDED
@@ -0,0 +1,10 @@
1
+ APP_ENV=development
2
+ DATABASE_URL=postgres://jira_cache_user:password@localhost:5432/jira_cache_development
3
+ POSTGRES_USER=jira_cache_user
4
+ POSTGRES_PASSWORD=password
5
+ POSTGRES_DB=jira_cache_development
6
+ JIRA_DOMAIN=project.atlassian.net
7
+ JIRA_USERNAME=user.name
8
+ JIRA_PASSWORD=PASSW0RD
9
+ JIRA_PROJECT_KEY=PJ
10
+ JIRA_LOG_LEVEL=INFO
data/.env.test ADDED
@@ -0,0 +1,10 @@
1
+ APP_ENV=test
2
+ DATABASE_URL=postgres://jira_cache_user:password@localhost:5433/jira_cache_test
3
+ POSTGRES_USER=jira_cache_user
4
+ POSTGRES_PASSWORD=password
5
+ POSTGRES_DB=jira_cache_test
6
+ JIRA_DOMAIN=test.atlassian.net
7
+ JIRA_USERNAME=username
8
+ JIRA_PASSWORD=password
9
+ JIRA_PROJECT_KEY=PJ
10
+ JIRA_LOG_LEVEL=DEBUG
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.env.development
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,12 @@
1
+ Style/LineLength:
2
+ Max: 120
3
+ Style/StringLiterals:
4
+ EnforcedStyle: double_quotes
5
+ Style/EmptyLinesAroundBody:
6
+ Enabled: false
7
+ Style/EmptyLinesAroundModuleBody:
8
+ Enabled: false
9
+ Style/EmptyLinesAroundClassBody:
10
+ Enabled: false
11
+ Style/AlignParameters:
12
+ EnforcedStyle: with_fixed_indentation
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ jira_cache
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ before_install: gem install bundler
5
+ before_script:
6
+ - psql -c 'create database travis_ci_test;' -U postgres
7
+ after_success: bundle exec codeclimate-test-reporter
8
+ services:
9
+ - postgresql
10
+ addons:
11
+ postgresql: "9.4"
12
+ env:
13
+ global:
14
+ - APP_ENV=test
15
+ - DATABASE_URL=postgres://localhost:5432/travis_ci_test
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ source "https://rubygems.org"
2
+ #
3
+ # Specify your gem"s dependencies in jira_cache.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem "guard", require: false
8
+ gem "guard-rspec", require: false
9
+ gem "guard-shotgun", require: false
10
+ gem "terminal-notifier-guard"
11
+ end
12
+
13
+ group :test do
14
+ gem "rspec"
15
+ gem "rack-test"
16
+ gem "webmock"
17
+ gem "coveralls", require: false
18
+ gem "simplecov", require: false
19
+ gem "simplecov-json", require: false
20
+ gem "timecop"
21
+ end
data/Guardfile ADDED
@@ -0,0 +1 @@
1
+ config/Guardfile
data/HISTORY.md ADDED
@@ -0,0 +1,22 @@
1
+ # History
2
+
3
+ ## 2017-02-19 - 0.2.0
4
+
5
+ - Supporting fetching of all issues without filtering on a specific project key.
6
+ - Simplified interface by relying to default values for notifier, client...
7
+ using environment variables to configure them.
8
+
9
+ Interface changes:
10
+
11
+ - `JiraCache.sync_project_issues(client, project_key)` becomes
12
+ `JiraCache.sync_issues(client: client, project_key: project_key)`.
13
+ - `JiraCache.sync_issue(client, issue_key)` becomes
14
+ `JiraCache.sync_issue(issue_key, client: client)`.
15
+ - `JiraCache::Sync.sync_project_issues(project_key)` becomes
16
+ `JiraCache::Sync.sync_issues(project_key: project_key)`.
17
+ - `JiraCache.sync_issue(client, 'issue_key')` becomes
18
+ `JiraCache.sync_issue('issue_key', client: client)`.
19
+ - The webhook app may now be run using `run JiraCache.webhook_app`
20
+ instead of `...webhook_app(client)` if the default client may be
21
+ used (configured using environment variables).
22
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Romain Champourlier
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # JiraCache
2
+
3
+ JiraCache enables storing JIRA issues fetched from the API in a local storage for easier and faster processing. This allows you to build applications performing complex operations on a large number of JIRA content without the JIRA's API latency.
4
+
5
+ [![Build Status](https://travis-ci.org/rchampourlier/jira_cache.svg?branch=master)](https://travis-ci.org/rchampourlier/jira_cache)
6
+ [![Code Climate](https://codeclimate.com/github/rchampourlier/jira_cache/badges/gpa.svg)](https://codeclimate.com/github/rchampourlier/jira_cache)
7
+ [![Coverage Status](https://coveralls.io/repos/github/rchampourlier/jira_cache/badge.svg?branch=master)](https://coveralls.io/github/rchampourlier/jira_cache?branch=master)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'jira_cache'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install jira_cache
24
+
25
+ ## Usage
26
+
27
+ Inside of `bin/console`:
28
+
29
+ ```ruby
30
+ # Basic usage (relies on environment variables to configure the client,
31
+ # see .env.example for details)
32
+ JiraCache.sync_issue('ISSUE_KEY')
33
+
34
+ # Using customized client and logger
35
+ logger = Logger.new(STDOUT)
36
+ logger.level = Logger::DEBUG
37
+ client = JiraCache::Client.new(
38
+ domain: 'example.atlassian.net',
39
+ username: 'username',
40
+ password: 'password',
41
+ logger: logger
42
+ )
43
+ JiraCache.sync_issue('ISSUE_KEY', client: client)
44
+ ```
45
+
46
+ ## Advanced use
47
+
48
+ ### Getting notified on sync events
49
+
50
+ When you trigger a project sync with `JiraCache.sync_project_issues(<project_key>)`,
51
+ you can get notifications on every issue fetched by providing a notifier
52
+ instance to `JiraCache::Client`:
53
+
54
+ ```
55
+ JiraCache::Client.set_notifier(MyNotifier.new)
56
+ ```
57
+
58
+ Your notifier class must implement the `#publish(event_name, data)` method. See `JiraCache::Notifier` class for more details.
59
+
60
+ Your notifier's `#publish` method will get called synchronously on every issue fetch. Your responsible of making it being processed in the background if you don't want to slow down the fetching process. Also, beware that fetchs can be performed in multiple threads concurrently (by default 5, you can override it by setting `JiraCache::THREAD_POOL_SIZE`).
61
+
62
+ Currently notified events are:
63
+ - `fetched_issue`
64
+
65
+ ## Contributing
66
+
67
+ 1. Fork it ( https://github.com/rchampourlier/jira_cache/fork )
68
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
69
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
70
+ 4. Push to the branch (`git push origin my-new-feature`)
71
+ 5. Create a new Pull Request
72
+
73
+ Check the [code of conduct](CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+ task :test => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.1
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Load dependencies
4
+ require 'rubygems'
5
+ require 'bundler/setup'
6
+
7
+ $LOAD_PATH.unshift File.expand_path('../..', __FILE__)
8
+ require 'config/boot'
9
+
10
+ require 'pry'
11
+ Pry.start
data/bin/db/migrate ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+ if [ "$RACK_ENV" == "production" ]
3
+ then
4
+ sequel -m config/db_migrations $DATABASE_URL
5
+ else
6
+ export $(cat .env.development | xargs) && sequel -m config/db_migrations $DATABASE_URL
7
+ fi
data/bin/db/psql ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+ if [ "$RACK_ENV" == "production" ]
3
+ then
4
+ psql $DATABASE_URL
5
+ else
6
+ export $(cat .env.development | xargs) && psql $DATABASE_URL
7
+ fi
data/bin/db/reset ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+ if [ "$RACK_ENV" == "production" ]
3
+ then
4
+ sequel -m config/db_migrations -M 0 $DATABASE_URL
5
+ else
6
+ export $(cat .env.development | xargs) && sequel -m config/db_migrations -M 0 $DATABASE_URL
7
+ fi
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/bin/sync ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Load dependencies
4
+ require "rubygems"
5
+ require "bundler/setup"
6
+ require "logger"
7
+
8
+ $LOAD_PATH.unshift File.expand_path("../..", __FILE__)
9
+ require "config/boot"
10
+
11
+ require "jira_cache/client"
12
+ require "jira_cache/notifier"
13
+
14
+ JiraCache.sync_issues(project_key: ENV["JIRA_PROJECT_KEY"])
data/config.ru ADDED
@@ -0,0 +1,7 @@
1
+ ENV["RACK_ENV"] ||= ENV["APP_ENV"] ||= "development"
2
+
3
+ root_dir = File.dirname(__FILE__)
4
+ require File.join(root_dir, "config", "boot")
5
+ require File.join(root_dir, "lib", "jira_cache", "webhook_app")
6
+
7
+ run JiraCache.webhook_app
data/config/Guardfile ADDED
@@ -0,0 +1,35 @@
1
+ # More info at https://github.com/guard/guard#readme
2
+
3
+ directories %w(lib config spec)
4
+
5
+ # Note: The cmd option is now required due to the increasing number of ways
6
+ # rspec may be run, below are examples of the most common uses.
7
+ # * bundler: 'bundle exec rspec'
8
+ # * bundler binstubs: 'bin/rspec'
9
+ # * spring: 'bin/rspec' (This will use spring if running and you have
10
+ # installed the spring binstubs per the docs)
11
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
12
+ # * 'just' rspec: 'rspec'
13
+
14
+ group :test do
15
+ guard :rspec, cmd: 'bundle exec rspec' do
16
+ require 'guard/rspec/dsl'
17
+ dsl = Guard::RSpec::Dsl.new(self)
18
+
19
+ # RSpec files
20
+ rspec = dsl.rspec
21
+ watch(rspec.spec_helper) { rspec.spec_dir }
22
+ watch(rspec.spec_support) { rspec.spec_dir }
23
+ watch(rspec.spec_files)
24
+
25
+ # Ruby files
26
+ ruby = dsl.ruby
27
+ dsl.watch_spec_files_for(ruby.lib_files)
28
+ end
29
+ end
30
+
31
+ group :server do
32
+ guard :shotgun do
33
+ watch(/.+/) # watch *every* file in the directory
34
+ end
35
+ end
data/config/boot.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ env = ENV["APP_ENV"] || "development"
3
+ if env == "development" || env == "test"
4
+ require "dotenv"
5
+ Dotenv.load(".env.#{env}")
6
+ end
7
+
8
+ root_dir = File.expand_path("../..", __FILE__)
9
+ $LOAD_PATH.unshift root_dir
10
+ $LOAD_PATH.unshift File.join(root_dir, "lib")
11
+ require "jira_cache"
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ Sequel.migration do
5
+ up do
6
+ create_table :jira_cache_issues do
7
+ String :key
8
+ column :data, "json"
9
+ DateTime :synced_at
10
+ DateTime :deleted_from_jira_at
11
+
12
+ # Timestamps
13
+ DateTime :created_at
14
+ DateTime :updated_at
15
+ end
16
+ end
17
+
18
+ down do
19
+ drop_table(:jira_cache_issues)
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ version: '2'
2
+
3
+ services:
4
+ pg-dev:
5
+ env_file:
6
+ - .env.development
7
+ image: postgres:9.4
8
+ ports:
9
+ - "5432:5432"
10
+ volumes:
11
+ - pg-dev-data:/var/lib/postgresql/data
12
+ pg-test:
13
+ env_file:
14
+ - .env.test
15
+ image: postgres:9.4
16
+ ports:
17
+ - "5433:5432"
18
+ volumes:
19
+ - pg-test-data:/var/lib/postgresql/data
20
+
21
+ volumes:
22
+ pg-dev-data:
23
+ driver: local
24
+ pg-test-data:
25
+ driver: local