lita-jira-issues 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6a8031619193c513be736c5ab30c7a042f8e7904
4
+ data.tar.gz: f5cafa72ed70367ffe54ff72bb4aecc1f194e8e3
5
+ SHA512:
6
+ metadata.gz: af14129f93d13f70895fb58193572b748e068db7c18d4330819442f80867be97705234510b1d0e4fb19158a621ae86aabf0e91b29f2fd02c2d56a0a895be9f83
7
+ data.tar.gz: e886bd47ca666e7c2024f231eccbe1b1e0396a246b19143f0500571d4427c4848e74d46b7235c8ad12a763d33fd2b8226c36617c3c74b9f8d880a4133c127a5e
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.swp
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script: bundle exec rake
5
+ before_install:
6
+ - gem update --system
7
+ services:
8
+ - redis-server
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2014 Arthur Maltson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # lita-jira-issues
2
+
3
+ [![Build Status](http://img.shields.io/travis/amaltson/lita-jira-issues.svg)](https://travis-ci.org/amaltson/lita-jira-issues)
4
+ [![Code Climate](http://img.shields.io/codeclimate/github/amaltson/lita-jira-issues.svg)](https://codeclimate.com/github/amaltson/lita-jira-issues)
5
+ [![Coverage Status](http://img.shields.io/coveralls/amaltson/lita-jira-issues.svg)](https://coveralls.io/r/amaltson/lita-jira-issues)
6
+
7
+ Lita handler for showing JIRA issue details when a JIRA issue key is mentioned in
8
+ chat. Inspired by the [Hubot jira-issue
9
+ plugin](https://github.com/github/hubot-scripts/blob/master/src/scripts/jira-issues.coffee)
10
+
11
+ ## Installation
12
+
13
+ Add lita-jira-issues to your Lita instance's Gemfile:
14
+
15
+ ``` ruby
16
+ gem "lita-jira-issues"
17
+ ```
18
+
19
+
20
+ ## Configuration
21
+
22
+ The `jira_issues` handler needs to be configured with your JIRA instance. Add
23
+ the following configurations to your `lita_config.rb`.
24
+
25
+ ```ruby
26
+ config.handlers.jira_issues.url = 'http://jira.local'
27
+ config.handlers.jira_issues.username = ENV['JIRA_USER'] || 'user'
28
+ config.handlers.jira_issues.password = ENV['JIRA_PASSWORD'] || 'password'
29
+ ```
30
+
31
+ As in the example above, you can always use environment variables for sensitive
32
+ information like the JIRA user's password.
33
+
34
+ ## Usage
35
+
36
+ Simply mention any JIRA valid key in upper or lower case, eg. JIRA-123, proj-8,
37
+ and Lita will respond with the issue details.
38
+
39
+ ## License
40
+
41
+ [MIT](http://opensource.org/licenses/MIT)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ require "lita"
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join("..", "..", "locales", "*.yml"), __FILE__
5
+ )]
6
+
7
+ require "lita/handlers/jira_issues"
@@ -0,0 +1,17 @@
1
+ class JiraGateway
2
+
3
+ attr_reader :http, :config
4
+
5
+ def initialize(http, config)
6
+ @http = http
7
+ @config = config
8
+ end
9
+
10
+ def data_for_issue(key)
11
+ http.basic_auth(config.username, config.password)
12
+ response = http.get(config.url + '/rest/api/2/issue/' + key)
13
+ return MultiJson.load(response.body, symbolize_keys: true) if response.success?
14
+ {}
15
+ end
16
+
17
+ end
@@ -0,0 +1,96 @@
1
+ require_relative 'jira_gateway'
2
+
3
+ module Lita
4
+ module Handlers
5
+ class JiraIssues < Handler
6
+
7
+ def initialize(*args)
8
+ super(args)
9
+ @jira = JiraGateway.new(http, config)
10
+ end
11
+
12
+ def self.default_config(config)
13
+ config.enabled = true
14
+ end
15
+
16
+ route /[a-zA-Z]+-\d+/, :jira_message, help: {
17
+ "KEY-123" => "Replies with information about the given JIRA key"
18
+ }
19
+
20
+ def jira_message(response)
21
+ unless configured?
22
+ raise 'Need to configure url, username, password for jira_issues ' \
23
+ 'to work'
24
+ end
25
+ response.matches.each do | key |
26
+ handle_key(response, key)
27
+ end
28
+ end
29
+
30
+ def configured?
31
+ config.url && config.username && config.password
32
+ end
33
+
34
+ def handle_key(response, key)
35
+ data = @jira.data_for_issue(key)
36
+ return if data.empty?
37
+ issue = issue_details(data)
38
+ response.reply issue
39
+ end
40
+
41
+ def issue_details(data)
42
+ key = data[:key]
43
+ data = data[:fields]
44
+ issue = summary(key, data)
45
+ issue << status(data)
46
+ issue << assignee(data)
47
+ issue << reporter(data)
48
+ issue << fix_version(data)
49
+ issue << priority(data)
50
+ issue << issue_link(key)
51
+ end
52
+
53
+ def summary(key, data)
54
+ "[#{key}] #{data[:summary]}"
55
+ end
56
+
57
+ def status(data)
58
+ "\nStatus: #{data[:status][:name]}"
59
+ end
60
+
61
+ def assignee(data)
62
+ if assigned_to = data[:assignee]
63
+ return ", assigned to #{assigned_to[:displayName]}"
64
+ end
65
+ ', unassigned'
66
+ end
67
+
68
+ def reporter(data)
69
+ ", rep. by #{data[:reporter][:displayName]}"
70
+ end
71
+
72
+ def fix_version(data)
73
+ fix_versions = data[:fixVersions]
74
+ if fix_versions and fix_versions.first
75
+ ", fixVersion: #{fix_versions.first[:name]}"
76
+ else
77
+ ', fixVersion: NONE'
78
+ end
79
+ end
80
+
81
+ def priority(data)
82
+ if data[:priority]
83
+ ", priority: #{data[:priority][:name]}"
84
+ else
85
+ ""
86
+ end
87
+ end
88
+
89
+ def issue_link(key)
90
+ "\n#{config.url}/browse/#{key}"
91
+ end
92
+ end
93
+
94
+ Lita.register_handler(JiraIssues)
95
+ end
96
+ end
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-jira-issues"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["Arthur Maltson"]
5
+ spec.email = ["arthur@maltson.com"]
6
+ spec.description = "Lita handler to show JIRA issue details"
7
+ spec.summary = %q{Lita handler that looks for JIRA issue keys and
8
+ helpfully inserts details into the chat conversation.}
9
+ spec.homepage = "https://github.com/amaltson/lita-jira-issues"
10
+ spec.license = "MIT"
11
+ spec.metadata = { "lita_plugin_type" => "handler" }
12
+
13
+ spec.files = `git ls-files`.split($/)
14
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_runtime_dependency "lita", "~> 3.3"
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake", "~> 10.3"
22
+ spec.add_development_dependency "rspec", ">= 3.0.0"
23
+ spec.add_development_dependency "simplecov"
24
+ spec.add_development_dependency "coveralls"
25
+ end
data/lita_config.rb ADDED
@@ -0,0 +1,6 @@
1
+ Lita.configure do |config|
2
+ config.robot.name = 'Jira Lita'
3
+ config.handlers.jira_issues.url = 'http://jira.local'
4
+ config.handlers.jira_issues.username = ENV['JIRA_USER'] || 'user'
5
+ config.handlers.jira_issues.password = ENV['JIRA_PASSWORD'] || 'password'
6
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,4 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ jira_issues:
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+
3
+ describe JiraGateway do
4
+
5
+ User = Struct.new(:url, :username, :password)
6
+ Response = Struct.new(:body, :success?)
7
+
8
+ let(:http_mock) { spy('http') }
9
+ subject do
10
+ JiraGateway.new(http_mock,
11
+ User.new('http://jira.local', 'user', 'password'))
12
+ end
13
+
14
+ it 'should return symbolized hash for JSON result' do
15
+ expect(http_mock).to receive(:basic_auth).with('user', 'password')
16
+ expect(http_mock).to receive(:get)
17
+ .with('http://jira.local/rest/api/2/issue/PRO-98')
18
+ .and_return(Response.new('{"key":"PRO-98"}', true))
19
+ expect(subject.data_for_issue('PRO-98')).to eq({key: 'PRO-98'})
20
+ end
21
+
22
+ it 'should return empty hash when response fails' do
23
+ expect(http_mock).to receive(:get)
24
+ .and_return(Response.new('{"key":"NOT_USED"}', false))
25
+ expect(subject.data_for_issue('some key')).to eq({})
26
+ end
27
+ end
@@ -0,0 +1,97 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::JiraIssues, lita_handler: true do
4
+
5
+ it 'should fail to start without configuration' do
6
+ send_message('Trying to use JIRA_123 not configured')
7
+ end
8
+
9
+ it { routes('JIRA-123').to(:jira_message) }
10
+ it { routes('user talking about something JIRA-123 had key').to(:jira_message) }
11
+
12
+ describe 'Looking up keys' do
13
+
14
+ before(:each) do
15
+ Lita.config.handlers.jira_issues.url = 'http://jira.local'
16
+ Lita.config.handlers.jira_issues.username = 'user'
17
+ Lita.config.handlers.jira_issues.password = 'pass'
18
+ end
19
+
20
+ it 'should reply with JIRA description if one seen' do
21
+ mock_jira('KEY-424', {
22
+ key:'KEY-424',
23
+ fields: {
24
+ summary: 'Another issue',
25
+ status: {
26
+ name: 'Fixed'
27
+ },
28
+ assignee: {
29
+ displayName: 'User'
30
+ },
31
+ reporter: {
32
+ displayName: 'Reporter'
33
+ },
34
+ fixVersions: [ { name: 'Sprint 2' } ],
35
+ priority: { name: 'Undecided' }
36
+ }
37
+ })
38
+ send_message('Some message KEY-424 more text')
39
+ expect(replies.last).to eq(<<-EOS.chomp
40
+ [KEY-424] Another issue
41
+ Status: Fixed, assigned to User, rep. by Reporter, fixVersion: Sprint 2, priority: Undecided
42
+ http://jira.local/browse/KEY-424
43
+ EOS
44
+ )
45
+ end
46
+
47
+ it 'it should reply with multiple JIRA descriptions if many seen' do
48
+ mock_jira('PROJ-9872',
49
+ {key:'PROJ-9872',
50
+ fields: {
51
+ summary: 'Too many bugs',
52
+ status: {
53
+ name: 'Resolved'
54
+ },
55
+ assignee: nil,
56
+ reporter: {
57
+ displayName: 'User'
58
+ }
59
+ }})
60
+ mock_jira('nEw-1',
61
+ {key:'NEW-1',
62
+ fields: {
63
+ summary: 'New 1',
64
+ status: {
65
+ name: 'Open'
66
+ },
67
+ reporter: {
68
+ displayName: 'User2'
69
+ },
70
+ fixVersions: [],
71
+ priority: { name: 'High' }
72
+ }})
73
+
74
+ send_message('Some PROJ-9872 message nEw-1 more text')
75
+ expect(replies.pop).to eq(<<-EOS.chomp
76
+ [NEW-1] New 1
77
+ Status: Open, unassigned, rep. by User2, fixVersion: NONE, priority: High
78
+ http://jira.local/browse/NEW-1
79
+ EOS
80
+ )
81
+ expect(replies.pop).to eq(<<-EOS.chomp
82
+ [PROJ-9872] Too many bugs
83
+ Status: Resolved, unassigned, rep. by User, fixVersion: NONE
84
+ http://jira.local/browse/PROJ-9872
85
+ EOS
86
+ )
87
+ end
88
+
89
+ def mock_jira(key, result)
90
+ allow_any_instance_of(JiraGateway).to receive(:data_for_issue)
91
+ .with(key)
92
+ .and_return(result)
93
+ end
94
+
95
+ end
96
+
97
+ end
@@ -0,0 +1,10 @@
1
+ require "simplecov"
2
+ require "coveralls"
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter
6
+ ]
7
+ SimpleCov.start { add_filter "/spec/" }
8
+
9
+ require "lita-jira-issues"
10
+ require "lita/rspec"
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-jira-issues
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Arthur Maltson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 3.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
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: coveralls
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: Lita handler to show JIRA issue details
98
+ email:
99
+ - arthur@maltson.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
+ - Gemfile
107
+ - LICENSE
108
+ - README.md
109
+ - Rakefile
110
+ - lib/lita-jira-issues.rb
111
+ - lib/lita/handlers/jira_gateway.rb
112
+ - lib/lita/handlers/jira_issues.rb
113
+ - lita-jira-issues.gemspec
114
+ - lita_config.rb
115
+ - locales/en.yml
116
+ - spec/lita/handlers/jira_gateway_spec.rb
117
+ - spec/lita/handlers/jira_issues_spec.rb
118
+ - spec/spec_helper.rb
119
+ homepage: https://github.com/amaltson/lita-jira-issues
120
+ licenses:
121
+ - MIT
122
+ metadata:
123
+ lita_plugin_type: handler
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.2.2
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Lita handler that looks for JIRA issue keys and helpfully inserts details
144
+ into the chat conversation.
145
+ test_files:
146
+ - spec/lita/handlers/jira_gateway_spec.rb
147
+ - spec/lita/handlers/jira_issues_spec.rb
148
+ - spec/spec_helper.rb