ruboty-redmine 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +2 -0
- data/lib/ruboty/handlers/redmine.rb +74 -0
- data/lib/ruboty/redmine.rb +9 -0
- data/lib/ruboty/redmine/client.rb +73 -0
- data/lib/ruboty/redmine/version.rb +5 -0
- data/ruboty-redmine.gemspec +25 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2e90a7c8715980e024dcf49c34fbec39fc8ae48e
|
4
|
+
data.tar.gz: 482337e7a40e9e8477dab1e7ad435d96be101a0e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 25cb89b79d296d0efdbccea99fe1bc46862d3910f9ad833e77fbad432439d6ad238a692411db2b89624706daacc8d515dc52938a5f1db7f6f190c489225f86bd
|
7
|
+
data.tar.gz: a8fa00ca1c418536b9ed64da242605abaa45e70816a7db9f17b0d2ddcbe277327a5ba5dbdc515a727bc3159218e2439b6b89a62444e0edf9bdba27ab8062263d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Ryota Arai
|
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,33 @@
|
|
1
|
+
# Ruboty::Redmine
|
2
|
+
|
3
|
+
Redmine plugin for Ruboty
|
4
|
+
|
5
|
+
## Available commands
|
6
|
+
|
7
|
+
```
|
8
|
+
ruboty create issue "subject" "project name" project "tracker name" tracker
|
9
|
+
```
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'ruboty-redmine'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install ruboty-redmine
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it ( https://github.com/[my-github-username]/ruboty-redmine/fork )
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Handlers
|
3
|
+
class Redmine < Base
|
4
|
+
env :REDMINE_URL, 'Redmine url (e.g. http://your-redmine)', optional: false
|
5
|
+
env :REDMINE_API_KEY, 'Redmine REST API key', optional: false
|
6
|
+
|
7
|
+
on(
|
8
|
+
/create issue (?<rest>.+)/,
|
9
|
+
name: 'create_issue',
|
10
|
+
description: 'Create a new issue'
|
11
|
+
)
|
12
|
+
|
13
|
+
def create_issue(message)
|
14
|
+
words = message[:rest].scan(/("([^"]+)"|([^ ]+))/).map {|v| v[1] || v[2] }
|
15
|
+
req = {}
|
16
|
+
req[:subject] = words.shift
|
17
|
+
words.each_with_index do |word, i|
|
18
|
+
next if i == 0
|
19
|
+
|
20
|
+
arg = words[i - 1]
|
21
|
+
|
22
|
+
case word
|
23
|
+
when 'project'
|
24
|
+
project = redmine.projects.find do |project|
|
25
|
+
[
|
26
|
+
project.id.to_s,
|
27
|
+
project.name.downcase,
|
28
|
+
project.identifier.downcase,
|
29
|
+
].include?(arg.downcase)
|
30
|
+
end
|
31
|
+
|
32
|
+
unless project
|
33
|
+
message.reply("Project '#{arg}' is not found.")
|
34
|
+
return
|
35
|
+
end
|
36
|
+
|
37
|
+
req[:project] = project
|
38
|
+
when 'tracker'
|
39
|
+
tracker = redmine.trackers.find do |tracker|
|
40
|
+
[
|
41
|
+
tracker.id.to_s,
|
42
|
+
tracker.name.downcase,
|
43
|
+
].include?(arg.downcase)
|
44
|
+
end
|
45
|
+
|
46
|
+
unless tracker
|
47
|
+
message.reply("Tracker '#{arg}' is not found.")
|
48
|
+
return
|
49
|
+
end
|
50
|
+
|
51
|
+
req[:tracker] = tracker
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
unless req.has_key?(:project)
|
56
|
+
message.reply("Project must be specified.")
|
57
|
+
return
|
58
|
+
end
|
59
|
+
|
60
|
+
issue = redmine.create_issue(req)
|
61
|
+
message.reply("Issue created: #{redmine.url_for_issue(issue)}")
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def redmine
|
67
|
+
Ruboty::Redmine::Client.new(
|
68
|
+
ENV['REDMINE_URL'],
|
69
|
+
ENV['REDMINE_API_KEY'],
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'faraday'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Ruboty
|
6
|
+
module Redmine
|
7
|
+
class Client
|
8
|
+
def initialize(url, api_key)
|
9
|
+
@url = url
|
10
|
+
@api_key = api_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def projects
|
14
|
+
res = JSON.parse(get('/projects.json').body)
|
15
|
+
res['projects'].map do |project|
|
16
|
+
OpenStruct.new(project)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def trackers
|
21
|
+
res = JSON.parse(get('/trackers.json').body)
|
22
|
+
res['trackers'].map do |tracker|
|
23
|
+
OpenStruct.new(tracker)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_issue(opts)
|
28
|
+
req = {
|
29
|
+
issue: {
|
30
|
+
subject: opts[:subject],
|
31
|
+
project_id: opts[:project].id,
|
32
|
+
},
|
33
|
+
}
|
34
|
+
req[:issue][:tracker_id] = opts[:tracker].id if opts[:tracker]
|
35
|
+
|
36
|
+
OpenStruct.new(
|
37
|
+
JSON.parse(post('/issues.json', req).body)['issue']
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def url_for_issue(issue)
|
42
|
+
URI.join(@url, "/issues/#{issue.id}")
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def conn
|
48
|
+
conn = Faraday.new(url: @url) do |faraday|
|
49
|
+
faraday.request :url_encoded
|
50
|
+
faraday.response :logger if ENV['DEBUG']
|
51
|
+
faraday.adapter Faraday.default_adapter
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def get(path, params = {})
|
56
|
+
conn.get do |req|
|
57
|
+
req.url path
|
58
|
+
req.params = params
|
59
|
+
req.headers['X-Redmine-API-Key'] = @api_key
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def post(path, params = {})
|
64
|
+
conn.post do |req|
|
65
|
+
req.url path
|
66
|
+
req.body = params.to_json
|
67
|
+
req.headers['X-Redmine-API-Key'] = @api_key
|
68
|
+
req.headers['Content-Type'] = 'application/json'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruboty/redmine/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruboty-redmine"
|
8
|
+
spec.version = Ruboty::Redmine::VERSION
|
9
|
+
spec.authors = ["Ryota Arai"]
|
10
|
+
spec.email = ["ryota.arai@gmail.com"]
|
11
|
+
spec.summary = %q{Redmine plugin for Ruboty}
|
12
|
+
spec.homepage = "https://github.com/ryotarai/ruboty-redmine"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "ruboty"
|
21
|
+
spec.add_dependency "faraday"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-redmine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryota Arai
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruboty
|
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: faraday
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- ryota.arai@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/ruboty/handlers/redmine.rb
|
82
|
+
- lib/ruboty/redmine.rb
|
83
|
+
- lib/ruboty/redmine/client.rb
|
84
|
+
- lib/ruboty/redmine/version.rb
|
85
|
+
- ruboty-redmine.gemspec
|
86
|
+
homepage: https://github.com/ryotarai/ruboty-redmine
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.2.2
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Redmine plugin for Ruboty
|
110
|
+
test_files: []
|