brpm_module_jira 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NTc1ZTkyMDJmODAzMjQ3MjQxMzg5MmM0OTRkYjUzNzE1Y2I4OTBkZQ==
5
+ data.tar.gz: !binary |-
6
+ YTdjYzQyM2VmMTQ1ZTMwMGViMmViMDM3ZjlmMjQ1ZTVmZjY0NjIzOA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZWM1MDY4YmM0MmRlYzY3MjM0YzhjY2MzOTRkYWFmMmVkMDM3NDcyOGQzNDkz
10
+ N2MzYmNmMWIzMWIzMDRhNDIyMjJjYTNlNWNkZmY2MzY1N2U3Mjc3OTY4ZDVk
11
+ ZDA0MTg1ZTM4Mjg3MTkyMzRlM2VlNDUwMjVkYTg0MmEzMDBlNmU=
12
+ data.tar.gz: !binary |-
13
+ NzQxY2Y4M2FkYWMwYTQ5YzhjMjUyNTIzOGQ5ZTE2YmRlM2YzYzY0Mzk1ZDY3
14
+ NDA3Njc1MzJkMzQ2Y2ZhYjYyOTdjMjMzMzQ2NzM2NTUxNzEzZWIyZTk1NzU1
15
+ ZWUwYzMzZTEzOTk3N2Q0MmFmNjE4YjYwYmU4YWEwN2I0M2UwNmM=
data/.gitignore ADDED
@@ -0,0 +1,37 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ Gemfile.lock
30
+ .ruby-gemset
31
+
32
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
33
+ .rvmrc
34
+
35
+ .DS_Store
36
+
37
+ .idea
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3-p392
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+
3
+ before_install:
4
+ - gem update --system 2.1.9
5
+
6
+ bundler_args: '' #remove the --deployment flag that causes the gems to be installed in .../1.9.1/...
7
+
8
+ script:
9
+ - rspec tests --format documentation --color
10
+
11
+ notifications:
12
+ email:
13
+ - niek.bartholomeus@gmail.com
14
+
15
+ branches:
16
+ except:
17
+ - /^v[0-9.]*/
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ # gem "brpm_content", path: "#{ENV["BRPM_CONTENT_PATH"]}/gems/brpm_content-latest" #TODO: doesn't work: "Could not find gem 'brpm_content (>= 0) ruby'..."
6
+ # gem "brpm_content", path: "/Users/niek/src/bmc/brpm_content" # works fine but is specific to my local configuration
7
+
8
+ # TODO: not sure how the framework can get hold of this configuration to find out where this modules is located (for now we're using a symlink from the gem path to the source path)
9
+ # gem "brpm_module_selenium", path: "."
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 BMC
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.
data/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # JIRA module for BRPM
2
+
3
+ [![Build Status](https://travis-ci.org/BMC-RLM/brpm_module_jira.svg?branch=master)](https://travis-ci.org/BMC-RLM/brpm_module_jira)
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/brpm_module_jira.png)](http://badge.fury.io/rb/brpm_module_jira)
6
+
7
+ This repository represents an external module for JIRA, to be used on top of the [BRPM content repository](https://github.com/BMC-RLM/brpm_content)
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ # Copied from https://github.com/mitchellh/vagrant-aws/blob/master/Rakefile
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ require 'rspec/core/rake_task'
5
+
6
+ # Immediately sync all stdout so that tools like buildbot can
7
+ # immediately load in the output.
8
+ $stdout.sync = true
9
+ $stderr.sync = true
10
+
11
+ # Change to the directory of this file.
12
+ Dir.chdir(File.expand_path("../", __FILE__))
13
+
14
+ # This installs the tasks that help with gem creation and
15
+ # publishing.
16
+ Bundler::GemHelper.install_tasks
17
+
18
+ # Install the `spec` task so that we can run tests.
19
+ RSpec::Core::RakeTask.new do |task|
20
+ task.pattern = "tests/**/*_spec.rb"
21
+ end
22
+
23
+ # Default task is to run the unit tests
24
+ task :default => "spec"
@@ -0,0 +1,4 @@
1
+ params = BrpmAuto.params
2
+
3
+ BrpmAuto.log "Adding a comment for issue '#{params["issue_id"]}'..."
4
+ JiraRestClient.new.add_comment(params["issue_id"], params["comment"])
@@ -0,0 +1,23 @@
1
+ ###
2
+ # issue_id:
3
+ # name: Issue Id
4
+ # required: yes
5
+ # comment:
6
+ # name: Comment
7
+ # required: yes
8
+ ###
9
+
10
+ #=== BMC Application Automation Integration Server: JIRA ===#
11
+ # [integration_id=4]
12
+ #=== End ===#
13
+
14
+ require "#{ENV["BRPM_CONTENT_HOME"] || "#{ENV["BRPM_HOME"]}/modules"}/gems/brpm_content-#{ENV["BRPM_CONTENT_VERSION"] || "latest"}/modules/framework/brpm_script_executor.rb"
15
+
16
+ params["direct_execute"] = "true"
17
+
18
+ params["SS_integration_dns"] = SS_integration_dns
19
+ params["SS_integration_username"] = SS_integration_username
20
+ params["SS_integration_password_enc"] = SS_integration_password_enc
21
+ params["SS_integration_details"] = YAML.load(SS_integration_details)
22
+
23
+ BrpmScriptExecutor.execute_automation_script_from_gem("brpm_module_jira", "add_comment", params)
@@ -0,0 +1,4 @@
1
+ params = BrpmAuto.params
2
+
3
+ BrpmAuto.log "Creating a new option for plan '#{params["release_name"]}' in the JIRA dropdown custom field with id #{params["jira_release_field_id"]}..."
4
+ JiraRestClient.new.create_option_for_dropdown_custom_field(params["jira_release_field_id"], params["release_name"])
@@ -0,0 +1,23 @@
1
+ ###
2
+ # jira_release_field_id:
3
+ # name: JIRA release field id
4
+ # required: yes
5
+ # release_name:
6
+ # name: Release name
7
+ # required: yes
8
+ ###
9
+
10
+ #=== BMC Application Automation Integration Server: JIRA ===#
11
+ # [integration_id=4]
12
+ #=== End ===#
13
+
14
+ require "#{ENV["BRPM_CONTENT_HOME"] || "#{ENV["BRPM_HOME"]}/modules"}/gems/brpm_content-#{ENV["BRPM_CONTENT_VERSION"] || "latest"}/modules/framework/brpm_script_executor.rb"
15
+
16
+ params["direct_execute"] = "true"
17
+
18
+ params["SS_integration_dns"] = SS_integration_dns
19
+ params["SS_integration_username"] = SS_integration_username
20
+ params["SS_integration_password_enc"] = SS_integration_password_enc
21
+ params["SS_integration_details"] = YAML.load(SS_integration_details)
22
+
23
+ BrpmScriptExecutor.execute_automation_script_from_gem("brpm_module_jira", "create_release", params)
@@ -0,0 +1,4 @@
1
+ params = BrpmAuto.params
2
+
3
+ BrpmAuto.log "Deleting option for plan '#{params["release_name"]}' in the JIRA dropdown custom field with id #{params["jira_release_field_id"]}..."
4
+ JiraRestClient.new.delete_option_for_dropdown_custom_field(params["jira_release_field_id"], params["release_name"])
@@ -0,0 +1,23 @@
1
+ ###
2
+ # jira_release_field_id:
3
+ # name: JIRA release field id
4
+ # required: yes
5
+ # release_name:
6
+ # name: Release name
7
+ # required: yes
8
+ ###
9
+
10
+ #=== BMC Application Automation Integration Server: JIRA ===#
11
+ # [integration_id=4]
12
+ #=== End ===#
13
+
14
+ require "#{ENV["BRPM_CONTENT_HOME"] || "#{ENV["BRPM_HOME"]}/modules"}/gems/brpm_content-#{ENV["BRPM_CONTENT_VERSION"] || "latest"}/modules/framework/brpm_script_executor.rb"
15
+
16
+ params["direct_execute"] = "true"
17
+
18
+ params["SS_integration_dns"] = SS_integration_dns
19
+ params["SS_integration_username"] = SS_integration_username
20
+ params["SS_integration_password_enc"] = SS_integration_password_enc
21
+ params["SS_integration_details"] = YAML.load(SS_integration_details)
22
+
23
+ BrpmScriptExecutor.execute_automation_script_from_gem("brpm_module_jira", "delete_release", params)
@@ -0,0 +1,4 @@
1
+ params = BrpmAuto.params
2
+
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"])
@@ -0,0 +1,23 @@
1
+ ###
2
+ # issue_id:
3
+ # name: Issue Id
4
+ # required: yes
5
+ # target_issue_status:
6
+ # name: Target issue status
7
+ # required: yes
8
+ ###
9
+
10
+ #=== BMC Application Automation Integration Server: JIRA ===#
11
+ # [integration_id=4]
12
+ #=== End ===#
13
+
14
+ require "#{ENV["BRPM_CONTENT_HOME"] || "#{ENV["BRPM_HOME"]}/modules"}/gems/brpm_content-#{ENV["BRPM_CONTENT_VERSION"] || "latest"}/modules/framework/brpm_script_executor.rb"
15
+
16
+ params["direct_execute"] = "true"
17
+
18
+ params["SS_integration_dns"] = SS_integration_dns
19
+ params["SS_integration_username"] = SS_integration_username
20
+ params["SS_integration_password_enc"] = SS_integration_password_enc
21
+ params["SS_integration_details"] = YAML.load(SS_integration_details)
22
+
23
+ BrpmScriptExecutor.execute_automation_script_from_gem("brpm_module_jira", "transition_issues_for_request", params)
@@ -0,0 +1,29 @@
1
+ brpm_rest_client = BrpmRestClient.new
2
+ params = BrpmAuto.params
3
+
4
+ BrpmAuto.log "Getting the tickets that are linked to the request..."
5
+ tickets = brpm_rest_client.get_tickets_by_request_id(params.rest_request_id)
6
+
7
+ if tickets.count == 0
8
+ BrpmAuto.log "This request has no tickets, nothing further to do."
9
+ return
10
+ end
11
+
12
+ unless params["target_issue_status"]
13
+ BrpmAuto.log "Getting the stage of this request..."
14
+ request_with_details = brpm_rest_client.get_request_by_id(params.rest_request_id)
15
+
16
+ if request_with_details.has_key?("plan_member")
17
+ stage_name = request_with_details["plan_member"]["stage"]["name"]
18
+
19
+ params["target_issue_status"] = "Deployed to #{stage_name}"
20
+ else
21
+ BrpmAuto.log "The request is not part of a plan so not processing the tickets."
22
+ return
23
+ end
24
+ end
25
+
26
+ tickets.each do |ticket|
27
+ BrpmAuto.log "Setting the status of issue #{ticket["foreign_id"]} to #{params["target_issue_status"]}"
28
+ JiraRestClient.new.set_issue_to_status(ticket["foreign_id"], params["target_issue_status"])
29
+ end
@@ -0,0 +1,20 @@
1
+ ###
2
+ # target_issue_status:
3
+ # name: Target issue status
4
+ # required: no
5
+ ###
6
+
7
+ #=== BMC Application Automation Integration Server: JIRA ===#
8
+ # [integration_id=4]
9
+ #=== End ===#
10
+
11
+ require "#{ENV["BRPM_CONTENT_HOME"] || "#{ENV["BRPM_HOME"]}/modules"}/gems/brpm_content-#{ENV["BRPM_CONTENT_VERSION"] || "latest"}/modules/framework/brpm_script_executor.rb"
12
+
13
+ params["direct_execute"] = "true"
14
+
15
+ params["SS_integration_dns"] = SS_integration_dns
16
+ params["SS_integration_username"] = SS_integration_username
17
+ params["SS_integration_password_enc"] = SS_integration_password_enc
18
+ params["SS_integration_details"] = YAML.load(SS_integration_details)
19
+
20
+ BrpmScriptExecutor.execute_automation_script_from_gem("brpm_module_jira", "transition_issues_for_request", params)
@@ -0,0 +1,26 @@
1
+ brpm_rest_client = BrpmRestClient.new
2
+ params = BrpmAuto.params
3
+
4
+ run_id = params["request_run_id"] || params["run_id"]
5
+
6
+ BrpmAuto.log "Getting the tickets that are linked to the requests of this run..."
7
+ tickets = brpm_rest_client.get_tickets_by_run_id_and_request_state(run_id, "completed")
8
+
9
+ if tickets.count == 0
10
+ BrpmAuto.log "This run has no tickets, nothing further to do."
11
+ return
12
+ end
13
+
14
+ unless params["target_issue_status"]
15
+ if params["request_plan_stage"]
16
+ params["target_issue_status"] = "Deployed to #{params["request_plan_stage"]}"
17
+ else
18
+ BrpmAuto.log "The request is not part of a plan so not processing the tickets."
19
+ return
20
+ end
21
+ end
22
+
23
+ tickets.each do |ticket|
24
+ BrpmAuto.log "Setting the status of issue #{ticket["foreign_id"]} to #{params["target_issue_status"]}"
25
+ JiraRestClient.new.set_issue_to_status(ticket["foreign_id"], params["target_issue_status"])
26
+ end
@@ -0,0 +1,20 @@
1
+ ###
2
+ # target_issue_status:
3
+ # name: Target issue status
4
+ # required: no
5
+ ###
6
+
7
+ #=== BMC Application Automation Integration Server: JIRA ===#
8
+ # [integration_id=4]
9
+ #=== End ===#
10
+
11
+ require "#{ENV["BRPM_CONTENT_HOME"] || "#{ENV["BRPM_HOME"]}/modules"}/gems/brpm_content-#{ENV["BRPM_CONTENT_VERSION"] || "latest"}/modules/framework/brpm_script_executor.rb"
12
+
13
+ params["direct_execute"] = "true"
14
+
15
+ params["SS_integration_dns"] = SS_integration_dns
16
+ params["SS_integration_username"] = SS_integration_username
17
+ params["SS_integration_password_enc"] = SS_integration_password_enc
18
+ params["SS_integration_details"] = YAML.load(SS_integration_details)
19
+
20
+ BrpmScriptExecutor.execute_automation_script_from_gem("brpm_module_jira", "transition_issues_for_run", params)
@@ -0,0 +1,4 @@
1
+ params = BrpmAuto.params
2
+
3
+ BrpmAuto.log "Updating option for plan from '#{params["old_release_name"]}' to '#{params["new_release_name"]}' in the JIRA dropdown custom field with id #{params["jira_release_field_id"]}..."
4
+ JiraRestClient.new.update_option_for_dropdown_custom_field(params["jira_release_field_id"], params["old_release_name"], params["new_release_name"])
@@ -0,0 +1,26 @@
1
+ ###
2
+ # jira_release_field_id:
3
+ # name: JIRA release field id
4
+ # required: yes
5
+ # old_release_name:
6
+ # name: Old release name
7
+ # required: yes
8
+ # new_release_name:
9
+ # name: New release name
10
+ # required: yes
11
+ ###
12
+
13
+ #=== BMC Application Automation Integration Server: JIRA ===#
14
+ # [integration_id=4]
15
+ #=== End ===#
16
+
17
+ params["direct_execute"] = "true"
18
+
19
+ require "#{ENV["BRPM_CONTENT_HOME"] || "#{ENV["BRPM_HOME"]}/modules"}/gems/brpm_content-#{ENV["BRPM_CONTENT_VERSION"] || "latest"}/modules/framework/brpm_script_executor.rb"
20
+
21
+ params["SS_integration_dns"] = SS_integration_dns
22
+ params["SS_integration_username"] = SS_integration_username
23
+ params["SS_integration_password_enc"] = SS_integration_password_enc
24
+ params["SS_integration_details"] = YAML.load(SS_integration_details)
25
+
26
+ BrpmScriptExecutor.execute_automation_script_from_gem("brpm_module_jira", "update_release", params)
@@ -0,0 +1,39 @@
1
+ require "yaml"
2
+
3
+ config = YAML.load_file(File.join(File.dirname(__FILE__), "config.yml"))
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = File.basename(File.expand_path(File.dirname(__FILE__)))
7
+ spec.version = config["version"]
8
+ spec.platform = Gem::Platform::RUBY
9
+ spec.license = "GNU General Public License v2.0"
10
+ spec.authors = [config["author"]]
11
+ spec.email = config["email"]
12
+ spec.homepage = config["homepage"]
13
+ spec.summary = config["summary"]
14
+ spec.description = config["description"]
15
+
16
+ spec.add_runtime_dependency "brpm_content", ">=0.1.10"
17
+
18
+ if config["dependencies"]
19
+ config["dependencies"].each do |dependency|
20
+ if dependency.is_a?(Hash)
21
+ modul = dependency.keys[0]
22
+ options = dependency.values[0]
23
+ else
24
+ modul = dependency
25
+ options = {}
26
+ end
27
+ spec.add_runtime_dependency modul, options["version"] unless ["brpm", "bladelogic", "jira"].include?(modul)
28
+ end
29
+ end
30
+
31
+ spec.add_development_dependency "rake"
32
+ spec.add_development_dependency "rspec"
33
+
34
+ spec.files = `git ls-files`.split("\n")
35
+ spec.require_path = 'lib'
36
+
37
+ spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
38
+ spec.bindir = "bin"
39
+ end
data/config.yml ADDED
@@ -0,0 +1,13 @@
1
+ dependencies:
2
+ - brpm_module_brpm
3
+
4
+ integration_servers:
5
+ - JIRA
6
+
7
+ version: 0.1.3
8
+
9
+ author: Niek Bartholomeus
10
+ email: niek.bartholomeus@gmail.com
11
+ homepage: https://github.com/BMC-RLM/brpm_module_jira
12
+ summary: JIRA automation scripts and libraries to run on top of the BRPM Content framework
13
+ description: JIRA automation scripts and libraries to run on top of the BRPM Content framework. See https://github.com/BMC-RLM/brpm_content for more information about the BRPM Content framework
@@ -0,0 +1,185 @@
1
+ require 'json'
2
+ require 'uri'
3
+
4
+ #=============================================================================#
5
+ # Jira Rest Module #
6
+ #-----------------------------------------------------------------------------#
7
+ # The REST module currently supports the 6.0.8 version of the Jira API as #
8
+ # well as a rest client which supports both HTTP and HTTPS #
9
+ #=============================================================================#
10
+
11
+ class JiraRestClient
12
+ def initialize(integration_settings = BrpmAuto.integration_settings)
13
+ @url = integration_settings.dns
14
+ @username = integration_settings.username
15
+ @password = integration_settings.password
16
+
17
+ @api_url = "#{@url}/rest/api/2"
18
+ end
19
+
20
+ # POST /rest/api/2/issue/{issueIdOrKey}/comment
21
+ def add_comment(issue_id, comment_body = 'Dummy Comment')
22
+ cmmnt = {:body => comment_body}
23
+ Rest.post("#{@api_url}/issue/#{issue_id}/comment", cmmnt, { :username => @username, :password => @password })["response"]
24
+ end
25
+
26
+ # GET /rest/api/2/issue/{issueIdOrKey}/transitions[?expand=transitions.fields]
27
+ def get_issue_transitions(issue_id, expand_transition = false)
28
+ url = "#{@api_url}/issue/#{issue_id}/transitions"
29
+ if expand_transition
30
+ url = "#{url}?expand=transitions.fields"
31
+ end
32
+ Rest.get(url, { :username => @username, :password => @password })["response"]
33
+ end
34
+
35
+ # GET /rest/api/2/issue/{issueIdOrKey}/transitions?transitionId={transistion_id}[&expand=transitions.fields]
36
+ def get_issue_transition(issue_id, transition_id, expand_transition = false)
37
+ url = "#{@api_url}/issue/#{issue_id}/transitions?transitionId=#{transition_id}"
38
+ if expand_transition
39
+ url = "#{url}&expand=transitions.fields"
40
+ end
41
+ Rest.get(url, { :username => @username, :password => @password })["response"]
42
+ end
43
+
44
+ # POST /rest/api/2/issue/{issueIdOrKey}/transitions[?expand=transitions.fields]
45
+ def post_issue_transition(issue_id, transition_id, comment = 'simple comment', expand_transition = false)
46
+ url = "#{@api_url}/issue/#{issue_id}/transitions"
47
+ if expand_transition
48
+ url = "#{url}?expand=transitions.fields"
49
+ end
50
+ transition = {:update=>{:comment =>[{:add => {:body => "#{comment}"}}]}, :transition => {:id => "#{transition_id}"}}
51
+ #Simple post as only return code is returned
52
+ Rest.post(url, transition, { :username => @username, :password => @password })["response"]
53
+ end
54
+
55
+ # GET /rest/api/2/project
56
+ def get_projects()
57
+ Rest.get("#{@api_url}/project", { :username => @username, :password => @password })["response"]
58
+ end
59
+
60
+ def set_issue_to_status(issue_id, status)
61
+ BrpmAuto.log "Getting the possible transitions for issue #{issue_id}..."
62
+ result = get_issue_transitions(issue_id)
63
+ transitions = result["transitions"]
64
+
65
+ transition = transitions.find { |transition| transition["to"]["name"] == status }
66
+
67
+ if transition
68
+ BrpmAuto.log "Issuing transition #{transition["name"]} to update the status of the issue to #{status}..."
69
+ issues = post_issue_transition(issue_id, transition["id"])
70
+ else
71
+ BrpmAuto.log "This ticket does not have a transition to status #{status} currently. Leaving it in its current state."
72
+ end
73
+ end
74
+
75
+ # GET /rest/api/2/search?jql=[Some Jira Query Language Search][&startAt=<num>&maxResults=<num>&fields=<field,field,...>&expand=<param,param,...>]
76
+ def search(jql, start_at = 0, max_results = 50, fields = '', expand = '')
77
+ url = "#{@api_url}/search?jql=#{jql}"
78
+ url = "#{url}&startAt=#{start_at}" unless start_at == 0
79
+ url = "#{url}&maxResults=#{max_results}" unless max_results == 50
80
+ url = "#{url}&fields=#{fields}" unless fields == ''
81
+ url = "#{url}&expand=#{expand}" unless expand == ''
82
+
83
+ Rest.get(url, { :username => @username, :password => @password })["response"]
84
+ end
85
+
86
+ # GET /rest/api/2/issue/{issueIdOrKey}[?fields=<field,field,...>&expand=<param,param,...>]
87
+ def get_issue(issue_id, fields = '', expand = '')
88
+ added = false
89
+ url = "#{@api_url}/issue/#{issue_id}"
90
+ if not fields.eql? ''
91
+ url = "#{url}?fields=#{fields}"
92
+ added = true
93
+ end
94
+ if not expand.eql? ''
95
+ if added
96
+ url = "#{url}&expand=#{expand}"
97
+ else
98
+ url = "#{url}?expand=#{expand}"
99
+ end
100
+ end
101
+ Rest.get(url, { :username => @username, :password => @password })["response"]
102
+ end
103
+
104
+ def get_option_for_dropdown_custom_field(custom_field_id, option_value)
105
+ # NOTE: this method assumes that the "Customfield Editor Plugin" is installed on the JIRA instance and that permission was granted for the custom field
106
+
107
+ url = "#{@url}/rest/jiracustomfieldeditorplugin/1.1/user/customfieldoptions/customfield_#{custom_field_id}"
108
+ result = Rest.get(url, { :username => @username, :password => @password })
109
+
110
+ if result["status"] == "success"
111
+ custom_field_options = result["response"]
112
+ return custom_field_options.find { |custom_field_option| custom_field_option["optionvalue"] == option_value }
113
+ else
114
+ if result["code"] == 404
115
+ return nil
116
+ else
117
+ raise "Error getting option: #{result["error_message"]}"
118
+ end
119
+ end
120
+ end
121
+
122
+ def create_option_for_dropdown_custom_field(custom_field_id, option_value)
123
+ # NOTE: this method assumes that the "Customfield Editor Plugin" is installed on the JIRA instance and that permission was granted for the custom field
124
+
125
+ custom_field_option = get_option_for_dropdown_custom_field(custom_field_id, option_value)
126
+
127
+ if custom_field_option
128
+ BrpmAuto.log "The option already exists, nothing to do."
129
+ return custom_field_option
130
+ end
131
+
132
+ url = "#{@url}/rest/jiracustomfieldeditorplugin/1.1/user/customfieldoption/customfield_#{custom_field_id}"
133
+ data = {:optionvalue => option_value }
134
+
135
+ result = Rest.post(url, data, { :username => @username, :password => @password })
136
+
137
+ if result["status"] == "success"
138
+ return result["response"]
139
+ else
140
+ raise "Could not create option: #{result["error_message"]}"
141
+ end
142
+ end
143
+
144
+ def update_option_for_dropdown_custom_field(custom_field_id, old_option_value, new_option_value)
145
+ # NOTE: this method assumes that the "Customfield Editor Plugin" is installed on the JIRA instance and that permission was granted for the custom field
146
+
147
+ custom_field_option_to_update = get_option_for_dropdown_custom_field(custom_field_id, old_option_value)
148
+
149
+ if custom_field_option_to_update
150
+ url = "#{@url}/rest/jiracustomfieldeditorplugin/1.1/user/customfieldoption/customfield_#{custom_field_id}/#{custom_field_option_to_update["id"]}"
151
+ data = {:optionvalue => new_option_value }
152
+
153
+ result = Rest.put(url, data, { :username => @username, :password => @password })
154
+
155
+ if result["status"] == "success"
156
+ return result["response"]
157
+ else
158
+ raise "Could not update option: #{result["error_message"]}"
159
+ end
160
+ else
161
+ BrpmAuto.log "The option doesn't exist yet, creating it instead of updating..."
162
+ create_option_for_dropdown_custom_field(custom_field_id, new_option_value)
163
+ end
164
+ end
165
+
166
+ def delete_option_for_dropdown_custom_field(custom_field_id, option_value)
167
+ # NOTE: this method assumes that the "Customfield Editor Plugin" is installed on the JIRA instance and that permission was granted for the custom field
168
+
169
+ custom_field_option_to_delete = get_option_for_dropdown_custom_field(custom_field_id, option_value)
170
+
171
+ if custom_field_option_to_delete
172
+ url = "#{@url}/rest/jiracustomfieldeditorplugin/1.1/user/customfieldoption/customfield_#{custom_field_id}/#{custom_field_option_to_delete["id"]}"
173
+
174
+ result = Rest.delete(url, { :username => @username, :password => @password })
175
+
176
+ if result["status"] == "success"
177
+ return result["response"]
178
+ else
179
+ raise "Could not delete option: #{result["error_message"]}"
180
+ end
181
+ else
182
+ BrpmAuto.log "The option doesn't exist, nothing to do."
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,39 @@
1
+ require_relative "spec_helper"
2
+
3
+ describe 'create/update/delete release' do
4
+ before(:all) do
5
+ setup_brpm_auto
6
+ end
7
+
8
+ before(:each) do
9
+ cleanup_release('JIRA tests - release 1')
10
+ cleanup_release('JIRA tests - release 1 - updated')
11
+ end
12
+
13
+ describe '' do
14
+ it 'should create/update/delete release in jira' do
15
+ params = get_default_params
16
+ params = params.merge(get_integration_params_for_jira)
17
+
18
+ params["release_name"] = 'JIRA tests - release 1'
19
+ BrpmScriptExecutor.execute_automation_script_from_gem("brpm_module_jira", "create_release", params)
20
+
21
+ option = @jira_rest_client.get_option_for_dropdown_custom_field(params["jira_release_field_id"], 'JIRA tests - release 1')
22
+ expect(option).not_to be_nil
23
+
24
+ params["old_release_name"] = 'JIRA tests - release 1'
25
+ params["new_release_name"] = 'JIRA tests - release 1 - updated'
26
+ BrpmScriptExecutor.execute_automation_script_from_gem("brpm_module_jira", "update_release", params)
27
+
28
+ option = @jira_rest_client.get_option_for_dropdown_custom_field(params["jira_release_field_id"], 'JIRA tests - release 1 - updated')
29
+ expect(option).not_to be_nil
30
+
31
+ params["release_name"] = 'JIRA tests - release 1 - updated'
32
+ BrpmScriptExecutor.execute_automation_script_from_gem("brpm_module_jira", "delete_release", params)
33
+
34
+ option = @jira_rest_client.get_option_for_dropdown_custom_field(params["jira_release_field_id"], 'JIRA tests - release 1 - updated')
35
+ expect(option).to be_nil
36
+ end
37
+ end
38
+ end
39
+
@@ -0,0 +1,47 @@
1
+ require 'fileutils'
2
+ require "brpm_script_executor"
3
+
4
+ def setup_brpm_auto
5
+ FileUtils.mkdir_p "/tmp/brpm_content"
6
+ create_symlink_to_gemset
7
+
8
+ BrpmAuto.setup( get_default_params.merge!(get_integration_params_for_jira) )
9
+
10
+ BrpmAuto.require_module_from_gem "brpm_module_jira"
11
+
12
+ @jira_rest_client = JiraRestClient.new
13
+ end
14
+
15
+ def get_default_params
16
+ params = {}
17
+ params['also_log_to_console'] = 'true'
18
+
19
+ params['brpm_url'] = 'http://brpm-content.pulsar-it.be:8088/brpm'
20
+ params['brpm_api_token'] = ENV["BRPM_API_TOKEN"]
21
+
22
+ params['output_dir'] = "/tmp/brpm_content"
23
+
24
+ params
25
+ end
26
+
27
+ def get_integration_params_for_jira
28
+ params = {}
29
+ params["SS_integration_dns"] = 'http://brpm.pulsar-it.be:9090'
30
+ params["SS_integration_username"] = 'brpm'
31
+ params["SS_integration_password"] = ENV["JIRA_PASSWORD"]
32
+
33
+ params["jira_release_field_id"] = '10000'
34
+
35
+ params
36
+ end
37
+
38
+ def cleanup_release(release_name)
39
+ @jira_rest_client.delete_option_for_dropdown_custom_field('10000', release_name)
40
+ end
41
+
42
+ def create_symlink_to_gemset
43
+ module_name = File.basename(File.expand_path("#{File.dirname(__FILE__)}/.."))
44
+ symlink = "#{ENV["GEM_HOME"]}/gems/#{module_name}-999.0.0"
45
+ FileUtils.rm(symlink) if File.exists?(symlink)
46
+ FileUtils.ln_s(File.expand_path("#{File.dirname(__FILE__)}/.."), symlink)
47
+ end
@@ -0,0 +1,32 @@
1
+ require_relative "spec_helper"
2
+
3
+ describe 'transition issue' do
4
+ before(:all) do
5
+ setup_brpm_auto
6
+ end
7
+
8
+ before(:each) do
9
+ end
10
+
11
+ describe '' do
12
+ it 'transition an issue in JIRA' do
13
+ params = get_default_params
14
+ params = params.merge(get_integration_params_for_jira)
15
+
16
+ params["issue_id"] = "EF-25"
17
+
18
+ params["target_issue_status"] = "Done"
19
+ BrpmScriptExecutor.execute_automation_script_from_gem("brpm_module_jira", "transition_issue", params)
20
+
21
+ params["target_issue_status"] = "To Do"
22
+ BrpmScriptExecutor.execute_automation_script_from_gem("brpm_module_jira", "transition_issue", params)
23
+
24
+ params["target_issue_status"] = "In development"
25
+ BrpmScriptExecutor.execute_automation_script_from_gem("brpm_module_jira", "transition_issue", params)
26
+
27
+ params["target_issue_status"] = "Deployed to development"
28
+ BrpmScriptExecutor.execute_automation_script_from_gem("brpm_module_jira", "transition_issue", params)
29
+ end
30
+ end
31
+ end
32
+
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brpm_module_jira
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Niek Bartholomeus
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: brpm_content
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.10
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.10
27
+ - !ruby/object:Gem::Dependency
28
+ name: brpm_module_brpm
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: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: JIRA automation scripts and libraries to run on top of the BRPM Content
70
+ framework. See https://github.com/BMC-RLM/brpm_content for more information about
71
+ the BRPM Content framework
72
+ email: niek.bartholomeus@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .ruby-version
79
+ - .travis.yml
80
+ - Gemfile
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - automations/add_comment.rb
85
+ - automations/add_comment.txt
86
+ - automations/create_release.rb
87
+ - automations/create_release.txt
88
+ - automations/delete_release.rb
89
+ - automations/delete_release.txt
90
+ - automations/transition_issue.rb
91
+ - automations/transition_issue.txt
92
+ - automations/transition_issues_for_request.rb
93
+ - automations/transition_issues_for_request.txt
94
+ - automations/transition_issues_for_run.rb
95
+ - automations/transition_issues_for_run.txt
96
+ - automations/update_release.rb
97
+ - automations/update_release.txt
98
+ - brpm_module_jira.gemspec
99
+ - config.yml
100
+ - lib/jira_rest_client.rb
101
+ - tests/create_read_update_delete_release_spec.rb
102
+ - tests/spec_helper.rb
103
+ - tests/transition_issue_spec.rb
104
+ homepage: https://github.com/BMC-RLM/brpm_module_jira
105
+ licenses:
106
+ - GNU General Public License v2.0
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.1.9
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: JIRA automation scripts and libraries to run on top of the BRPM Content framework
128
+ test_files: []