exception_notification-redmine 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a4f3e09e0c4a178a42ea58d78ca5c39744463531
4
+ data.tar.gz: f671f36eb35d3f4d158453e41ff417d289e2baa0
5
+ SHA512:
6
+ metadata.gz: 6c43bfbfef407ea3cdd04fee98175149dd282980c2c76f77348b1811f743435ee99dd47de39894d7d14636c1b96568efcfe8d43287a4779e1c695946f17a4a4b
7
+ data.tar.gz: a42974a96adac7a09128174eb1c83047b121a4a722e22e22598f3ddb169f0cef74d66d9d7b86f02698deff8b1debb9e3aaefcb41005d54ccc0b43c0bf86656aa
data/.gitignore ADDED
@@ -0,0 +1,73 @@
1
+ # Compiled source #
2
+ ###################
3
+ *.com
4
+ *.class
5
+ *.dll
6
+ *.exe
7
+ *.o
8
+ *.so
9
+
10
+ # Packages #
11
+ ############
12
+ # it's better to unpack these files and commit the raw source
13
+ # git has its own built in compression methods
14
+ *.7z
15
+ *.dmg
16
+ *.gz
17
+ *.iso
18
+ *.jar
19
+ *.rar
20
+ *.tar
21
+ *.zip
22
+
23
+ # Logs and databases #
24
+ ######################
25
+ *.log
26
+ *.sql
27
+ *sqlite*
28
+
29
+ # Rubymine config dir #
30
+ #######################
31
+ .idea
32
+
33
+ # Rails database config #
34
+ ########################
35
+ config/database.yml
36
+
37
+ # Rails 3.1 #
38
+ #############
39
+ .sass-cache/
40
+
41
+ # Misc #
42
+ ########
43
+ *~
44
+ *.cache
45
+ *.pid
46
+ tmp/*
47
+ tmp/**/*
48
+ db/cstore/**
49
+ doc/api
50
+ doc/app
51
+ doc/plugins
52
+ coverage/*
53
+ *.tmproj
54
+ Capfile
55
+ doc/*.dot
56
+ *.sw?
57
+ .svn
58
+ .rake_tasks
59
+ .bundle
60
+
61
+
62
+ # xcode noise #
63
+ ###############
64
+ build/*
65
+ *.pbxuser
66
+ *.mode1v3
67
+
68
+ # OS generated files #
69
+ ######################
70
+ .DS_Store*
71
+ ehthumbs.db
72
+ Icon?
73
+ Thumbs.db
data/CHANGELOG ADDED
@@ -0,0 +1,4 @@
1
+ Version 0.0.1: Initial release
2
+ Version 0.0.2: Use a custom field to avoid creation of same issue multiple times
3
+ Version 0.1.0: Version bump, add README.md, TODO.md and LICENCE
4
+ Version 0.1.1: Update README.md
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in exception_notification-redmine.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Nuxos Asia - richard.piacentini@nuxos.asia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # ExceptionNotification::Redmine
2
+
3
+ This gem add a Redmine notifier to Exception Notification.
4
+
5
+ This Ruby gem is an extension of the [exception_notification gem](http://rubygems.org/gems/exception_notification) to support creating issues in Redmine.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'exception_notification-redmine'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install exception_notification-redmine
22
+
23
+ ## Usage
24
+
25
+ **IMPORTANT:** You must create a custom field named `x_checksum` in your Redmine project for the Redmine notifier to work properly
26
+
27
+ As of Rails 3 ExceptionNotification-Redmine is used as a rack middleware, or in the environment you want it to run. In most cases you would want ExceptionNotification-Redmine to run on production. Thus, you can make it work by putting the following lines in your `config/environments/production.rb`:
28
+
29
+ ```ruby
30
+ Whatever::Application.config.middleware.use ExceptionNotification::Rack,
31
+ # host_url: url of your Redmine host
32
+ # issues_url: issues.json (Redmine REST API)
33
+ # api_key: the api key of the user that will be used to create the Redmine issue
34
+ # project_id: create issues in the project with the given id, where id is either project_id or project identifier
35
+ # tracker_id: create issues with the given tracker_id
36
+ # assigned_to_id: create issues which are assigned to the given user_id
37
+ # priority_id: create issues with the given priority_id
38
+ # status_id: create issues with the given status_id
39
+ # x_checksum_cf_id: custom field used to avoid creation of the same issue multiple times. You must use the DOM id assigned by Redmine to this field in the issue form. You can find it by creating an issue manually in your project and inspecting the HTML form, you should see something like name="issue[custom_field_values][19]", in this case the id would be 19.
40
+
41
+ :redmine => {
42
+ :host_url => "http://redmine.example.com",
43
+ :issues_url => "issues.json",
44
+ :api_key => "123456",
45
+ :project_id => "test-project",
46
+ :tracker_id => "1", # Bug
47
+ :assigned_to_id => "123",
48
+ :priority_id => "6", # Urgent
49
+ :status_id => "1", # New
50
+ :x_checksum_cf_id => "19" # DOM id in Redmine issue form
51
+ }
52
+ ```
53
+ ## Contributing
54
+
55
+ 1. Fork it ( https://github.com/Nuxos-Asia/exception_notification-redmine/fork )
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/TODO.md ADDED
@@ -0,0 +1 @@
1
+ - improve formatting of issue description
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'exception_notification/redmine/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'exception_notification-redmine'
8
+ s.version = ExceptionNotification::Redmine::VERSION
9
+ s.authors = ["Richard Piacentini", "Suttipong Wisittanakorn"]
10
+ s.date = "2014-10-28"
11
+ s.summary = "This gem add a Redmine notifier to Exception Notification"
12
+ s.description = "This Ruby gem is an extension of the exception_notification gem to support creating issues in Redmine"
13
+ s.homepage = "https://github.com/Nuxos-Asia/exception_notification-redmine"
14
+ s.email = ["richard.piacentini@nuxos.asia", "safe@nuxos.asia"]
15
+ s.license = "MIT"
16
+
17
+ s.post_install_message = "*** Please read the README.MD file to setup the Redmine Notifier."
18
+
19
+ s.files = `git ls-files -z`.split("\x0")
20
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
22
+ s.require_paths = ["lib"]
23
+
24
+ s.add_dependency("exception_notification", "~> 4.0.1")
25
+ s.add_dependency("httparty", "~> 0.10.2")
26
+ s.add_dependency("json", "~> 1.8.1")
27
+
28
+ s.add_development_dependency "bundler", "~> 1.7"
29
+ s.add_development_dependency "rake", "~> 10.0"
30
+
31
+ end
@@ -0,0 +1,2 @@
1
+ # This file exists to support gem autoloading by bundler.
2
+ require 'exception_notifier/redmine'
@@ -0,0 +1,5 @@
1
+ module ExceptionNotification
2
+ module Redmine
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require 'exception_notifier/redmine/redmine'
@@ -0,0 +1,81 @@
1
+ require 'action_dispatch'
2
+ require 'httparty'
3
+ require 'json'
4
+
5
+ module ExceptionNotifier
6
+
7
+ class RedmineNotifier
8
+
9
+ def initialize(config)
10
+ @config = config
11
+ end
12
+
13
+ def call(exception, options={})
14
+ env = options[:env]
15
+ issue = compose_issue(options, exception)
16
+ create_issue(issue) unless issue_exist?(issue)
17
+ end
18
+
19
+ private
20
+
21
+ def compose_issue(options, exception)
22
+ env = options[:env]
23
+
24
+ unless env.nil?
25
+ options[:body] ||= {}
26
+ options[:body][:server] = Socket.gethostname
27
+ options[:body][:process] = $$
28
+ options[:body][:rails_root] = Rails.root if defined?(Rails)
29
+ options[:body][:exception] = { :error_class => exception.class.to_s,
30
+ :message => exception.message.inspect,
31
+ :backtrace => exception.backtrace }
32
+ options[:body][:data] = (env['exception_notifier.exception_data'] || {}).merge(options[:data] || {})
33
+
34
+ issue = {}
35
+ issue[:project_id] = @config[:project_id]
36
+ issue[:tracker_id] = @config[:tracker_id]
37
+ issue[:status_id] = @config[:status_id]
38
+ issue[:priority_id] = @config[:priority_id]
39
+ issue[:assigned_to_id] = @config[:assigned_to_id]
40
+ issue[:subject] = compose_subject(options, exception)
41
+ issue[:custom_fields] = [{ :id => @config[:x_checksum_cf_id],
42
+ :value => encode_subject(issue[:subject])}]
43
+ issue[:description] = options[:body][:exception].inspect
44
+ issue
45
+ end
46
+ end
47
+
48
+ def compose_subject(options, exception)
49
+ env = options[:env]
50
+ kontroller = env['action_controller.instance'] || MissingController.new
51
+ subject = "#{kontroller.controller_name}##{kontroller.action_name}" if kontroller
52
+ subject << " (#{exception.class})"
53
+ subject << " #{exception.message.inspect}" if options[:verbose_subject]
54
+ subject.length > 120 ? subject[0...120] + "..." : subject
55
+ end
56
+
57
+ def issues_url(params = {})
58
+ default_params = { :key => @config[:api_key] }
59
+ encoded_params = URI.encode_www_form(default_params.merge(params))
60
+ "#{@config[:host_url]}/#{@config[:issues_url]}?#{encoded_params}"
61
+ end
62
+
63
+ def create_issue(issue)
64
+ options = { :body => { :issue => issue }.to_json,
65
+ :headers => { "Content-Type" => "application/json" } }
66
+ response = ::HTTParty.send(:post, issues_url, options)
67
+ end
68
+
69
+ def issue_exist?(issue)
70
+ x_checksum = issue[:custom_fields][0][:value]
71
+ response = ::HTTParty.send(:get, issues_url("project_id" => @config[:project_id],
72
+ "cf_#{@config[:x_checksum_cf_id]}" => x_checksum))
73
+ raise "Unexpected Response" if response.nil? || response["total_count"].nil?
74
+ response["total_count"] > 0
75
+ end
76
+
77
+ def encode_subject(subject)
78
+ Digest::SHA2.hexdigest(subject)
79
+ end
80
+ end
81
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exception_notification-redmine
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Richard Piacentini
8
+ - Suttipong Wisittanakorn
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-10-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: exception_notification
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 4.0.1
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 4.0.1
28
+ - !ruby/object:Gem::Dependency
29
+ name: httparty
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 0.10.2
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 0.10.2
42
+ - !ruby/object:Gem::Dependency
43
+ name: json
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 1.8.1
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 1.8.1
56
+ - !ruby/object:Gem::Dependency
57
+ name: bundler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.7'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.7'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '10.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '10.0'
84
+ description: This Ruby gem is an extension of the exception_notification gem to support
85
+ creating issues in Redmine
86
+ email:
87
+ - richard.piacentini@nuxos.asia
88
+ - safe@nuxos.asia
89
+ executables: []
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - ".gitignore"
94
+ - CHANGELOG
95
+ - Gemfile
96
+ - LICENSE
97
+ - README.md
98
+ - Rakefile
99
+ - TODO.md
100
+ - exception_notification-redmine.gemspec
101
+ - lib/exception_notification/redmine.rb
102
+ - lib/exception_notification/redmine/version.rb
103
+ - lib/exception_notifier/redmine.rb
104
+ - lib/exception_notifier/redmine/redmine.rb
105
+ homepage: https://github.com/Nuxos-Asia/exception_notification-redmine
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message: "*** Please read the README.MD file to setup the Redmine Notifier."
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.2.2
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: This gem add a Redmine notifier to Exception Notification
129
+ test_files: []