brpm_module_jira 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDEzNmE1YTg4MDMxOTU1MDc3MjQyNmZiYjYzN2IwNjI0Mzc4ODM3Zg==
4
+ Y2RiN2RmODVlZmY1MDEwYjM1MGE5YmMzZjU3YzY3Y2U2ZjQ5MDZhNw==
5
5
  data.tar.gz: !binary |-
6
- MTY5ZjljNTdjMGE1MTMwMDRiODVmODdhMTM4MjkzYzc1NDUwZGI2ZA==
6
+ YjUzNjA0NzhlMzMxMjVkZWE5ZDZkY2YwNGMwYzM2OTJjMmE1NTcyZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- N2U4MDM0NTA3NmYyNzEzNTM2MWIwYmEyYzI1OGRlNWQxMDVjZjQyM2VkYTgy
10
- YzlhNGQ3M2UzM2E2MmZiYjc1YzRkOTVjMzE5NGM1ZWU3YjdjNzEzN2MyYjA3
11
- MWEzYzM3ZWMxMDY3MjYyMTBhZTRhYWI5MjcwYmMxMjNlZWMxNjQ=
9
+ ZGNhMGU3Y2NjMjliMTQ1NjdjM2RhNzM4NDY3ZjY3NTgyZWVhYTllYjYzMjJj
10
+ ZTE4ZjMzY2MyNGM2MTViNDc4NmZlNDdjN2JhMDNhODY2Yzg4Y2QwMDRjY2Q4
11
+ Zjc1YjgzZDBhYmY4ZGQ5NzI0OTc4ODljMjBmMzYwMDcxZjAwNDY=
12
12
  data.tar.gz: !binary |-
13
- ZDU0MmZmN2E3Y2I4MDAzYzcwNTU1YzExYzc5OGY5M2IxYTU3MjkxZDU3N2Vl
14
- NTUxMzc2MTMzNTM1ODBjY2MyMGFhMDM2MTUyMjZhM2MxZjNmN2UzMzgzOGJi
15
- ZjM3YWMyZjZkNzYwZmYyNTkyYzk5NjkxZWI2NWY2ZDdhMWExN2I=
13
+ ODZjZDdlYzJjYWUxODFhMTZhNDIxZjU5MTIxYzMzNTU1YTZmYjQ2OTVjY2Q3
14
+ ZmEzODE1YTIwODJkMTRmMTI1NWU4NjU5NDJkMzU1ZDU2OTNlM2E3NTM5OGIx
15
+ NDVlMDllMmFjMjIwYTM0NWZlNzgyZDViYmQ3YjQxYjlmYTcwMGM=
@@ -1,4 +1,12 @@
1
1
  params = BrpmAuto.params
2
+ jira_rest_client = JiraRestClient.new
2
3
 
3
- BrpmAuto.log "Setting the status of issue #{params["issue_id"]} to #{params["target_issue_status"]}"
4
- JiraRestClient.new.set_issue_to_status(params["issue_id"], params["target_issue_status"])
4
+ BrpmAuto.log "Getting issue #{params["issue_id"]}..."
5
+ issue = jira_rest_client.get_issue(params["issue_id"])
6
+
7
+ raise "This issue doesn't exist" unless issue
8
+
9
+ BrpmAuto.log "Setting the status of issue #{params["issue_id"]} to #{params["target_issue_status"]}..."
10
+ transition = jira_rest_client.set_issue_to_status(params["issue_id"], params["target_issue_status"])
11
+
12
+ raise "This status is not allowed" unless transition
@@ -24,6 +24,6 @@ if params["target_issue_status"].nil? or params["target_issue_status"].empty?
24
24
  end
25
25
 
26
26
  tickets.each do |ticket|
27
- BrpmAuto.log "Setting the status of issue #{ticket["foreign_id"]} to #{params["target_issue_status"]}"
27
+ BrpmAuto.log "Setting the status of issue #{ticket["foreign_id"]} to #{params["target_issue_status"]}... (non-existing issues or invalid target statuses will be ignored)"
28
28
  JiraRestClient.new.set_issue_to_status(ticket["foreign_id"], params["target_issue_status"])
29
29
  end
@@ -21,6 +21,6 @@ unless params["target_issue_status"]
21
21
  end
22
22
 
23
23
  tickets.each do |ticket|
24
- BrpmAuto.log "Setting the status of issue #{ticket["foreign_id"]} to #{params["target_issue_status"]}"
24
+ BrpmAuto.log "Setting the status of issue #{ticket["foreign_id"]} to #{params["target_issue_status"]}... (non-existing issues or invalid target statuses will be ignored)"
25
25
  JiraRestClient.new.set_issue_to_status(ticket["foreign_id"], params["target_issue_status"])
26
26
  end
data/config.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  dependencies:
2
2
  - brpm_module_brpm
3
3
 
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
 
6
6
  author: Niek Bartholomeus
7
7
  email: niek.bartholomeus@gmail.com
@@ -20,7 +20,13 @@ class JiraRestClient
20
20
  # POST /rest/api/2/issue/{issueIdOrKey}/comment
21
21
  def add_comment(issue_id, comment_body = 'Dummy Comment')
22
22
  cmmnt = {:body => comment_body}
23
- Rest.post("#{@api_url}/issue/#{issue_id}/comment", cmmnt, { :username => @username, :password => @password })["response"]
23
+ result = Rest.post("#{@api_url}/issue/#{issue_id}/comment", cmmnt, { :username => @username, :password => @password })
24
+
25
+ unless result["status"] == "success"
26
+ raise "Could not add the comment: #{result["error_message"]}"
27
+ end
28
+
29
+ result["response"]
24
30
  end
25
31
 
26
32
  # GET /rest/api/2/issue/{issueIdOrKey}/transitions[?expand=transitions.fields]
@@ -29,7 +35,17 @@ class JiraRestClient
29
35
  if expand_transition
30
36
  url = "#{url}?expand=transitions.fields"
31
37
  end
32
- Rest.get(url, { :username => @username, :password => @password })["response"]
38
+ result = Rest.get(url, { :username => @username, :password => @password })
39
+
40
+ if result["status"] == "success"
41
+ result["response"]["transitions"]
42
+ else
43
+ if result["code"] == 404
44
+ {}
45
+ else
46
+ raise "Error getting the issue transitions: #{result["error_message"]}"
47
+ end
48
+ end
33
49
  end
34
50
 
35
51
  # GET /rest/api/2/issue/{issueIdOrKey}/transitions?transitionId={transistion_id}[&expand=transitions.fields]
@@ -38,7 +54,13 @@ class JiraRestClient
38
54
  if expand_transition
39
55
  url = "#{url}&expand=transitions.fields"
40
56
  end
41
- Rest.get(url, { :username => @username, :password => @password })["response"]
57
+ result = Rest.get(url, { :username => @username, :password => @password })
58
+
59
+ if result["status"] == "success"
60
+ result["response"]
61
+ else
62
+ raise "Error getting the issue transition: #{result["error_message"]}"
63
+ end
42
64
  end
43
65
 
44
66
  # POST /rest/api/2/issue/{issueIdOrKey}/transitions[?expand=transitions.fields]
@@ -49,26 +71,42 @@ class JiraRestClient
49
71
  end
50
72
  transition = {:update=>{:comment =>[{:add => {:body => "#{comment}"}}]}, :transition => {:id => "#{transition_id}"}}
51
73
  #Simple post as only return code is returned
52
- Rest.post(url, transition, { :username => @username, :password => @password })["response"]
74
+ result = Rest.post(url, transition, { :username => @username, :password => @password })
75
+
76
+ unless result["status"] == "success"
77
+ raise "Could not add the comment: #{result["error_message"]}"
78
+ end
79
+
80
+ result["response"]
53
81
  end
54
82
 
55
83
  # GET /rest/api/2/project
56
84
  def get_projects()
57
- Rest.get("#{@api_url}/project", { :username => @username, :password => @password })["response"]
85
+ result = Rest.get("#{@api_url}/project", { :username => @username, :password => @password })
86
+
87
+ if result["status"] == "success"
88
+ result["response"]
89
+ else
90
+ if result["code"] == 404
91
+ {}
92
+ else
93
+ raise "Error getting the projects: #{result["error_message"]}"
94
+ end
95
+ end
58
96
  end
59
97
 
60
98
  def set_issue_to_status(issue_id, status)
61
99
  BrpmAuto.log "Getting the possible transitions for issue #{issue_id}..."
62
- result = get_issue_transitions(issue_id)
63
- transitions = result["transitions"]
100
+ transitions = get_issue_transitions(issue_id)
64
101
 
65
102
  transition = transitions.find { |transition| transition["to"]["name"] == status }
66
103
 
67
104
  if transition
68
105
  BrpmAuto.log "Issuing transition #{transition["name"]} to update the status of the issue to #{status}..."
69
- issues = post_issue_transition(issue_id, transition["id"])
106
+ post_issue_transition(issue_id, transition["id"])
70
107
  else
71
- BrpmAuto.log "This ticket does not have a transition to status #{status} currently. Leaving it in its current state."
108
+ BrpmAuto.log "This issue does not have a transition to status #{status} currently. Leaving it in its current state."
109
+ nil
72
110
  end
73
111
  end
74
112
 
@@ -80,7 +118,17 @@ class JiraRestClient
80
118
  url = "#{url}&fields=#{fields}" unless fields == ''
81
119
  url = "#{url}&expand=#{expand}" unless expand == ''
82
120
 
83
- Rest.get(url, { :username => @username, :password => @password })["response"]
121
+ Rest.get(url, { :username => @username, :password => @password })
122
+
123
+ if result["status"] == "success"
124
+ result["response"]
125
+ else
126
+ if result["code"] == 404
127
+ {}
128
+ else
129
+ raise "Error doing the search: #{result["error_message"]}"
130
+ end
131
+ end
84
132
  end
85
133
 
86
134
  # GET /rest/api/2/issue/{issueIdOrKey}[?fields=<field,field,...>&expand=<param,param,...>]
@@ -98,7 +146,13 @@ class JiraRestClient
98
146
  url = "#{url}?expand=#{expand}"
99
147
  end
100
148
  end
101
- Rest.get(url, { :username => @username, :password => @password })["response"]
149
+ result = Rest.get(url, { :username => @username, :password => @password })
150
+
151
+ if result["status"] == "success"
152
+ result["response"]
153
+ else
154
+ raise "Error getting the issue: #{result["error_message"]}"
155
+ end
102
156
  end
103
157
 
104
158
  def get_option_for_dropdown_custom_field(custom_field_id, option_value)
@@ -109,7 +163,7 @@ class JiraRestClient
109
163
 
110
164
  if result["status"] == "success"
111
165
  custom_field_options = result["response"]
112
- return custom_field_options.find { |custom_field_option| custom_field_option["optionvalue"] == option_value }
166
+ custom_field_options.find { |custom_field_option| custom_field_option["optionvalue"] == option_value }
113
167
  else
114
168
  if result["code"] == 404
115
169
  return nil
@@ -135,7 +189,7 @@ class JiraRestClient
135
189
  result = Rest.post(url, data, { :username => @username, :password => @password })
136
190
 
137
191
  if result["status"] == "success"
138
- return result["response"]
192
+ result["response"]
139
193
  else
140
194
  raise "Could not create option: #{result["error_message"]}"
141
195
  end
@@ -9,7 +9,7 @@ describe 'transition issue' do
9
9
  end
10
10
 
11
11
  describe '' do
12
- it 'transition an issue in JIRA' do
12
+ it 'should transition an issue in JIRA' do
13
13
  params = get_default_params
14
14
  params = params.merge(get_integration_params_for_jira)
15
15
 
@@ -24,9 +24,19 @@ describe 'transition issue' do
24
24
  params["target_issue_status"] = "In development"
25
25
  BrpmScriptExecutor.execute_automation_script("brpm_module_jira", "transition_issue", params)
26
26
 
27
- params["target_issue_status"] = "Deployed to development"
27
+ params["target_issue_status"] = "Deployed to Development"
28
28
  BrpmScriptExecutor.execute_automation_script("brpm_module_jira", "transition_issue", params)
29
29
  end
30
+
31
+ it 'should raise an error when transitioning an unknown issue in JIRA' do
32
+ params = get_default_params
33
+ params = params.merge(get_integration_params_for_jira)
34
+
35
+ params["issue_id"] = "XXX-999"
36
+
37
+ params["target_issue_status"] = "Done"
38
+ expect { BrpmScriptExecutor.execute_automation_script("brpm_module_jira", "transition_issue", params) }.to raise_exception
39
+ end
30
40
  end
31
41
  end
32
42
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brpm_module_jira
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Niek Bartholomeus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-09 00:00:00.000000000 Z
11
+ date: 2015-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: brpm_content_framework