capistrano-redmine 0.0.4 → 1.0.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.
@@ -7,9 +7,8 @@ module Capistrano
|
|
7
7
|
def Redmine.configure(site, token, options = {})
|
8
8
|
RedmineClient::Base.configure do
|
9
9
|
self.site = site
|
10
|
-
self.format =
|
11
|
-
self.
|
12
|
-
self.password = ""
|
10
|
+
self.format = 'json'
|
11
|
+
self.token = token
|
13
12
|
self.ssl_options = options[:ssl] if options[:ssl]
|
14
13
|
self.proxy = options[:proxy] if options[:proxy]
|
15
14
|
end
|
@@ -31,20 +30,21 @@ module Capistrano
|
|
31
30
|
rescue Errno::ECONNREFUSED
|
32
31
|
logger.important "Redmine error: Server unavailable."
|
33
32
|
return
|
34
|
-
rescue
|
35
|
-
logger.important "Redmine error:
|
33
|
+
rescue SocketError
|
34
|
+
logger.important "Redmine error: Check hostname, port, protocol."
|
36
35
|
return
|
37
|
-
rescue
|
38
|
-
logger.important "Redmine error: Project not found."
|
36
|
+
rescue JSON::ParserError
|
37
|
+
logger.important "Redmine error: HTTP error. Unauthorized Access. Check token. Project not found."
|
39
38
|
return
|
40
39
|
end
|
41
40
|
|
41
|
+
# This code get error if you use ChiliProject instead Redmine
|
42
42
|
if issue_statuses = RedmineClient::IssueStatus.all
|
43
43
|
statuses = issue_statuses.inject({}) do |memo, s|
|
44
|
-
memo.merge s
|
44
|
+
memo.merge s['id'] => s['name']
|
45
45
|
end
|
46
46
|
|
47
|
-
if statuses[from_status
|
47
|
+
if statuses[from_status].nil? || statuses[to_status].nil?
|
48
48
|
logger.important "Redmine error: Invalid issue status (or statuses)."
|
49
49
|
return
|
50
50
|
end
|
@@ -53,19 +53,13 @@ module Capistrano
|
|
53
53
|
end
|
54
54
|
|
55
55
|
begin
|
56
|
-
issues = RedmineClient::Issue.
|
57
|
-
:project_id => p,
|
58
|
-
:status_id => from_status,
|
59
|
-
:limit => 100
|
60
|
-
}
|
61
|
-
)
|
56
|
+
issues = RedmineClient::Issue.all ({ project_id: p, status_id: from_status, limit: 100 })
|
62
57
|
|
63
58
|
issues.each do |i|
|
64
|
-
i
|
65
|
-
i
|
66
|
-
logger.debug "Update ##{i.id} #{i.subject}"
|
59
|
+
RedmineClient::Issue.update(i['id'], { "issue[status_id]" => to_status })
|
60
|
+
logger.debug "Update ##{i['id']} #{i['subject']}"
|
67
61
|
end
|
68
|
-
rescue
|
62
|
+
rescue
|
69
63
|
logger.important "Redmine error: Update issue error."
|
70
64
|
end
|
71
65
|
end
|
@@ -1,20 +1,111 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
|
2
5
|
module RedmineClient
|
3
|
-
class Base < ActiveResource::Base
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
+
class Base
|
8
|
+
HTTP_GET = 'GET'
|
9
|
+
HTTP_PUT = 'PUT'
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
attr_accessor :site, :format, :token, :ssl_options, :proxy
|
13
|
+
|
14
|
+
def configure(&block)
|
15
|
+
instance_eval &block
|
16
|
+
end
|
17
|
+
|
18
|
+
def http(resource, params = {}, method = HTTP_GET)
|
19
|
+
uri = URI("#{site}/#{resource}.#{format}")
|
20
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
21
|
+
|
22
|
+
case method
|
23
|
+
when HTTP_GET
|
24
|
+
params[:key] = token # add key to GET-params
|
25
|
+
uri.query = URI.encode_www_form(params) # GET-params including key
|
26
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
27
|
+
when HTTP_PUT
|
28
|
+
uri.query = URI.encode_www_form({key: token }) # GET-params is only key
|
29
|
+
request = Net::HTTP::Put.new(uri.request_uri)
|
30
|
+
request.set_form_data(params) # PUT-params without key
|
31
|
+
end
|
32
|
+
|
33
|
+
if http.use_ssl = ssl_options ? true : false
|
34
|
+
http.cert = ssl_options[:cert]
|
35
|
+
http.key = ssl_options[:key]
|
36
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
37
|
+
end
|
38
|
+
|
39
|
+
http.request(request)
|
40
|
+
end
|
41
|
+
|
7
42
|
end
|
8
43
|
|
44
|
+
extend ClassMethods
|
9
45
|
end
|
10
46
|
|
11
47
|
class Project < RedmineClient::Base
|
48
|
+
|
49
|
+
module ClassMethods
|
50
|
+
def all
|
51
|
+
resource = 'projects'
|
52
|
+
http = Base.http(resource)
|
53
|
+
|
54
|
+
begin
|
55
|
+
JSON.parse(http.body)[resource]
|
56
|
+
rescue JSON::ParserError
|
57
|
+
false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def find(project_id)
|
62
|
+
http = Base.http("projects/#{project_id}")
|
63
|
+
|
64
|
+
begin
|
65
|
+
JSON.parse(http.body)['project']
|
66
|
+
rescue JSON::ParserError
|
67
|
+
false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
extend ClassMethods
|
12
73
|
end
|
13
74
|
|
14
75
|
class Issue < RedmineClient::Base
|
76
|
+
module ClassMethods
|
77
|
+
def all(params = {})
|
78
|
+
resource = 'issues'
|
79
|
+
http = Base.http(resource, params)
|
80
|
+
|
81
|
+
begin
|
82
|
+
JSON.parse(http.body)[resource]
|
83
|
+
rescue JSON::ParserError
|
84
|
+
false
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def update(issue_id, params = {})
|
89
|
+
http = Base.http("issues/#{issue_id}", params, Base::HTTP_PUT)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
extend ClassMethods
|
15
93
|
end
|
16
94
|
|
17
95
|
class IssueStatus < RedmineClient::Base
|
96
|
+
module ClassMethods
|
97
|
+
def all
|
98
|
+
resource = 'issue_statuses'
|
99
|
+
http = Base.http(resource)
|
100
|
+
|
101
|
+
begin
|
102
|
+
JSON.parse(http.body)[resource]
|
103
|
+
rescue JSON::ParserError
|
104
|
+
false
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
extend ClassMethods
|
18
109
|
end
|
19
110
|
|
20
111
|
end
|
data/lib/capistrano-redmine.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-redmine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-27 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! "This gem contains a Capistrano :task, which allows to\n update
|
15
15
|
the Redmine issues statuses when you do deploy with Capistrano."
|
@@ -54,4 +54,3 @@ signing_key:
|
|
54
54
|
specification_version: 3
|
55
55
|
summary: Update Redmine issues statuses on Capistrano deploy.
|
56
56
|
test_files: []
|
57
|
-
has_rdoc:
|