jirarest2 0.0.3
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.
- data.tar.gz.sig +1 -0
- data/.autotest +23 -0
- data/.gemtest +0 -0
- data/GPLv3 +674 -0
- data/History.txt +37 -0
- data/Manifest.txt +28 -0
- data/README.md +8 -0
- data/README.txt +53 -0
- data/Rakefile +30 -0
- data/bin/create_issue.rb +270 -0
- data/header.copyright +16 -0
- data/lib/config.rb +55 -0
- data/lib/connect.rb +99 -0
- data/lib/credentials.rb +62 -0
- data/lib/exceptions.rb +47 -0
- data/lib/issue.rb +266 -0
- data/lib/issuelink.rb +74 -0
- data/lib/jirarest2.rb +28 -0
- data/lib/jirarest2/result.rb +55 -0
- data/lib/services.rb +55 -0
- data/lib/services/issuelink.rb +94 -0
- data/lib/services/issuelinktype.rb +91 -0
- data/lib/services/watcher.rb +73 -0
- data/test/test_connect.rb +21 -0
- data/test/test_credentials.rb +38 -0
- data/test/test_issue.rb +51 -0
- data/test/test_issuelink.rb +31 -0
- data/test/test_issuelinktype.rb +35 -0
- data/test/test_result.rb +29 -0
- data/test/test_watcher.rb +35 -0
- metadata +182 -0
- metadata.gz.sig +0 -0
data/lib/issuelink.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Watcher class
|
2
|
+
# Copyright (C) 2012 Cyril Bitterich
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "connect"
|
19
|
+
=begin
|
20
|
+
Watchers do have their own calling
|
21
|
+
=end
|
22
|
+
class Watcher
|
23
|
+
|
24
|
+
=begin
|
25
|
+
We expect to receive an existing
|
26
|
+
:connection
|
27
|
+
:issueid
|
28
|
+
=end
|
29
|
+
def initialize(connection,issueid)
|
30
|
+
@connection = connection
|
31
|
+
@uritail = "issue/#{issueid}/watchers"
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
=begin
|
36
|
+
Return all the watchers of the issue
|
37
|
+
=end
|
38
|
+
def get_watchers
|
39
|
+
ret = @connection.execute("Get",@uritail,"").result
|
40
|
+
watchers = Array.new
|
41
|
+
ret["watchers"].each { |entry|
|
42
|
+
watchers << entry["name"]
|
43
|
+
}
|
44
|
+
return watchers
|
45
|
+
end
|
46
|
+
|
47
|
+
=begin
|
48
|
+
Adds a new watcher for the issue
|
49
|
+
=end
|
50
|
+
def add_watcher(username)
|
51
|
+
ret = @connection.execute("Post",@uritail,username)
|
52
|
+
case ret.code
|
53
|
+
when "204"
|
54
|
+
return true
|
55
|
+
else
|
56
|
+
return false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
=begin
|
61
|
+
removes one watcher from the issue
|
62
|
+
=end
|
63
|
+
def remove_watcher(username)
|
64
|
+
query = {"username" => username}
|
65
|
+
ret = @connection.execute("Delete",@uritail,query)
|
66
|
+
case ret.code # Have to decide what to do here (Work with exceptions or with the case block)
|
67
|
+
when "204"
|
68
|
+
return true
|
69
|
+
else
|
70
|
+
false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
data/lib/jirarest2.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Jirarest2 is a gem to connect to the REST interface of JIRA(tm) . It uses Basic authentification and not oauth
|
2
|
+
|
3
|
+
|
4
|
+
# Copyright (C) 2012 Cyril Bitterich
|
5
|
+
#
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
|
20
|
+
VERSION = "0.0.3"
|
21
|
+
|
22
|
+
require_relative "connect"
|
23
|
+
require_relative "issue"
|
24
|
+
require_relative "credentials"
|
25
|
+
require_relative "exceptions"
|
26
|
+
require_relative "services/watcher"
|
27
|
+
require_relative "services"
|
28
|
+
require_relative "services/issuelink"
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# Our own class to hide the use of Net::HTTP and uri in the results we get
|
2
|
+
|
3
|
+
|
4
|
+
# Copyright (C) 2012 Cyril Bitterich
|
5
|
+
#
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'json'
|
21
|
+
|
22
|
+
module Jirarest2
|
23
|
+
=begin
|
24
|
+
An object of Result contians the result of a Net::HTTP REST request that has a JSON-Body with easily accessable parameters.
|
25
|
+
=end
|
26
|
+
class Result
|
27
|
+
|
28
|
+
# The statuscode of the result
|
29
|
+
attr_reader :code
|
30
|
+
# header lines
|
31
|
+
attr_reader :header
|
32
|
+
# The original body of the result
|
33
|
+
attr_reader :body
|
34
|
+
# The JSON part of the body
|
35
|
+
attr_reader :result
|
36
|
+
|
37
|
+
=begin
|
38
|
+
Takes an Net::HTTPResponse object and builds itself from there
|
39
|
+
=end
|
40
|
+
def initialize(httpResponse)
|
41
|
+
# pp httpResponse
|
42
|
+
# pp httpResponse.body
|
43
|
+
@code = httpResponse.code
|
44
|
+
@header = httpResponse.to_hash
|
45
|
+
@body = httpResponse.body
|
46
|
+
if httpResponse.instance_of?(Net::HTTPNoContent) or httpResponse.body == "" then # If there is nothing in the body it would be hard to parse it.
|
47
|
+
@result = @body
|
48
|
+
else
|
49
|
+
@result = JSON.parse(@body)
|
50
|
+
end
|
51
|
+
end # initialize
|
52
|
+
|
53
|
+
end # class
|
54
|
+
|
55
|
+
end # module
|
data/lib/services.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Services super class (what the services themselves can do is mostly the same)
|
2
|
+
# Copyright (C) 2012 Cyril Bitterich
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "connect"
|
19
|
+
=begin
|
20
|
+
Trying to keep the services together in one class so I don't have to write so much
|
21
|
+
=end
|
22
|
+
class Services
|
23
|
+
|
24
|
+
=begin
|
25
|
+
We expect to receive an existing
|
26
|
+
:connection
|
27
|
+
=end
|
28
|
+
def initialize(connection)
|
29
|
+
@connection = connection
|
30
|
+
# to be set in each subclass;
|
31
|
+
# @uritail = ""
|
32
|
+
end
|
33
|
+
|
34
|
+
=begin
|
35
|
+
Send the GET request
|
36
|
+
=end
|
37
|
+
def get(data = "")
|
38
|
+
return @connection.execute("Get",@uritail,data).result
|
39
|
+
end
|
40
|
+
|
41
|
+
=begin
|
42
|
+
Send the POST request
|
43
|
+
=end
|
44
|
+
def post(data = "")
|
45
|
+
return @connection.execute("Post",@uritail,data)
|
46
|
+
end
|
47
|
+
|
48
|
+
=begin
|
49
|
+
Send the DELETE request
|
50
|
+
=end
|
51
|
+
def delete(data = "")
|
52
|
+
return @connection.execute("Delete",@uritail,data)
|
53
|
+
end
|
54
|
+
|
55
|
+
end #class
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# IssueLink class
|
2
|
+
# Copyright (C) 2012 Cyril Bitterich
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "connect"
|
19
|
+
require "services"
|
20
|
+
require "issue"
|
21
|
+
require "services/issuelinktype"
|
22
|
+
require "exceptions"
|
23
|
+
|
24
|
+
=begin
|
25
|
+
This class is responsible for the Linking of Issues
|
26
|
+
No real getter as of yet (I just didn't need it)
|
27
|
+
=end
|
28
|
+
class IssueLink < Services
|
29
|
+
|
30
|
+
def initialize(connection)
|
31
|
+
@uritail = "issueLink"
|
32
|
+
super(connection)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
=begin
|
37
|
+
return the issuekey
|
38
|
+
=end
|
39
|
+
def key(issue)
|
40
|
+
if issue.instance_of?(Issue) then
|
41
|
+
return issue.issuekey
|
42
|
+
else
|
43
|
+
return issue
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
public
|
48
|
+
=begin
|
49
|
+
Links two issues
|
50
|
+
Right now the visibility feature for comments is not supported
|
51
|
+
=end
|
52
|
+
def link_issue(thisIssue,remoteIssue,type,comment = nil)
|
53
|
+
inwardIssue = key(thisIssue)
|
54
|
+
outwardIssue = key(remoteIssue)
|
55
|
+
|
56
|
+
# lets see if we have the right name
|
57
|
+
linktype = IssueLinkType.new(@connection)
|
58
|
+
if ! linktype.internal_name?(type) then # time to find the correct name and see if we have to exchange tickets
|
59
|
+
realname = linktype.name(type)
|
60
|
+
if realname.nil? then
|
61
|
+
raise Jirarest2::ValueNotAllowedException, type
|
62
|
+
else
|
63
|
+
type = realname[0]
|
64
|
+
if realname[1] == "inward" then # we have to change the issues as jira only knows one direction.
|
65
|
+
temp = inwardIssue
|
66
|
+
inwardIssue = outwardIssue
|
67
|
+
outwardIssue = temp
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end # if ! linktype.internal_name?
|
71
|
+
|
72
|
+
|
73
|
+
#create the hashes for JSON
|
74
|
+
json = Hash.new
|
75
|
+
json["type"] = { "name" => type }
|
76
|
+
json["inwardIssue"] = { "key" => inwardIssue }
|
77
|
+
json["outwardIssue"] = { "key" => outwardIssue }
|
78
|
+
json["comment"] = { "body" => comment} if comment
|
79
|
+
|
80
|
+
return post(json)
|
81
|
+
end
|
82
|
+
|
83
|
+
=begin
|
84
|
+
Only true if successfully linked false if something happened. Elseway exactly as link_issue.
|
85
|
+
=end
|
86
|
+
def link(thisIssue,remoteIssue,type,comment = nil)
|
87
|
+
if link_issue(thisIssue,remoteIssue,type,comment).code == "201" then
|
88
|
+
return true
|
89
|
+
else
|
90
|
+
return false
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end # class
|
@@ -0,0 +1,91 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2012 Cyril Bitterich
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "services"
|
19
|
+
|
20
|
+
=begin
|
21
|
+
An IssueLinkType Object represents one or all IssueLinkTypes
|
22
|
+
=end
|
23
|
+
class IssueLinkType < Services
|
24
|
+
|
25
|
+
=begin
|
26
|
+
We expect to receive an existing
|
27
|
+
:connection
|
28
|
+
=end
|
29
|
+
def initialize(connection,data = "")
|
30
|
+
if data == "" then
|
31
|
+
@uritail = "issueLinkType"
|
32
|
+
else
|
33
|
+
@uritail = "issueLinkType/#{data}"
|
34
|
+
end
|
35
|
+
super(connection)
|
36
|
+
@all = get
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
=begin
|
41
|
+
do the search for each block
|
42
|
+
=end
|
43
|
+
def name_block_search(hash,uiname)
|
44
|
+
name = nil
|
45
|
+
direction = nil
|
46
|
+
if ( hash["inward"] == uiname) then
|
47
|
+
direction = "inward"
|
48
|
+
name = hash["name"]
|
49
|
+
return name, direction
|
50
|
+
elsif (hash["outward"] == uiname) then
|
51
|
+
direction = "outward"
|
52
|
+
name = hash["name"]
|
53
|
+
return name, direction
|
54
|
+
else
|
55
|
+
return nil # Save my butt
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
public
|
61
|
+
=begin
|
62
|
+
Get the internal name and direction instead of the one in the UI.
|
63
|
+
Returns an Array with the name and the direction ("inward" or "outward") if successfull , nil if not
|
64
|
+
=end
|
65
|
+
def name(uiname)
|
66
|
+
if @all["issueLinkTypes"].instance_of?(Array) then
|
67
|
+
@all["issueLinkTypes"].each{ |hash|
|
68
|
+
result = name_block_search(hash,uiname)
|
69
|
+
return result if result # Return if we got an actual result
|
70
|
+
}
|
71
|
+
else
|
72
|
+
return name_block_search(@all,uiname)
|
73
|
+
end
|
74
|
+
return nil # Nothing found don't want to return @all
|
75
|
+
end # name
|
76
|
+
|
77
|
+
=begin
|
78
|
+
Is the name realy the internal name we need to use?
|
79
|
+
=end
|
80
|
+
def internal_name?(test)
|
81
|
+
if @all["issueLinkTypes"].instance_of?(Array) then
|
82
|
+
@all["issueLinkTypes"].each{ |hash|
|
83
|
+
return true if ( hash["name"] == test)
|
84
|
+
}
|
85
|
+
else
|
86
|
+
return ( @all["name"] == test )
|
87
|
+
end
|
88
|
+
return false # Nothing found don't want to return @all
|
89
|
+
end
|
90
|
+
|
91
|
+
end #class
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Watcher class
|
2
|
+
# Copyright (C) 2012 Cyril Bitterich
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "connect"
|
19
|
+
require "services"
|
20
|
+
|
21
|
+
=begin
|
22
|
+
Watchers do have their own calling
|
23
|
+
=end
|
24
|
+
class Watcher < Services
|
25
|
+
|
26
|
+
=begin
|
27
|
+
Set our uritail
|
28
|
+
=end
|
29
|
+
def initialize(connection, issueid)
|
30
|
+
@uritail = "issue/#{issueid}/watchers"
|
31
|
+
super(connection)
|
32
|
+
end
|
33
|
+
|
34
|
+
=begin
|
35
|
+
Return all the watchers of the issue
|
36
|
+
=end
|
37
|
+
def get_watchers
|
38
|
+
ret = get
|
39
|
+
watchers = Array.new
|
40
|
+
ret["watchers"].each { |entry|
|
41
|
+
watchers << entry["name"]
|
42
|
+
}
|
43
|
+
return watchers
|
44
|
+
end
|
45
|
+
|
46
|
+
=begin
|
47
|
+
Adds a new watcher for the issue
|
48
|
+
=end
|
49
|
+
def add_watcher(username)
|
50
|
+
ret = post(username)
|
51
|
+
case ret.code
|
52
|
+
when "204"
|
53
|
+
return true
|
54
|
+
else
|
55
|
+
return false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
=begin
|
60
|
+
removes one watcher from the issue
|
61
|
+
=end
|
62
|
+
def remove_watcher(username)
|
63
|
+
query = {"username" => username}
|
64
|
+
ret = delete(query)
|
65
|
+
case ret.code # Have to decide what to do here (Work with exceptions or with the case block)
|
66
|
+
when "204"
|
67
|
+
return true
|
68
|
+
else
|
69
|
+
false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|