brpm_module_demo 0.1.13

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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MDk5OTU0ZTAyOTdiMzk2YWQ4YjQ0ZDBhM2EyMjNiMWRlNzE5NWIwZA==
5
+ data.tar.gz: !binary |-
6
+ ZWM2MzdkNDg2ODY4OGVlZDA2NDFlY2U5ODIxNjQ5NzhmNDdkNjNhOA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YTJlZDZkNmRiMWM3YmQwOWZiOWQ5M2M2NTBlYzVkMGE5MjM1MjRiODVkY2Rm
10
+ ZDBlY2Q0MTA4OWY4N2M4ZTRkODA3ODI4Y2UxNWMyNDJmMTQ3ODg4NWExOTZj
11
+ ZDdiZmRlODQ2MmJlNzBkYWU3YmRkMTA1OWFlMWY4OWJiMzc0MzQ=
12
+ data.tar.gz: !binary |-
13
+ MGEzMDUxNGI2NWI4NDBkMGQ4YmVmOWM5ODYyMTQ0OTAxZGFlZmFkYjM2Mjlm
14
+ M2EyYmQzZGQwNDAzMDIyM2E4MGU4OTBhNTk3YWQzYmM0ZjZkZjcyYjNkOGJi
15
+ Y2UwYTI2NGUwNDc3Y2YwZjE0MzIxMmExODU4NjlmMTY3MmU1YjE=
data/.gitignore ADDED
@@ -0,0 +1,38 @@
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
38
+
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
+ - bundle exec 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,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
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
+ # BRPM module for a customer "Demo"
2
+
3
+ [![Build Status](https://travis-ci.org/BMC-RLM/brpm_module_demo.svg?branch=master)](https://travis-ci.org/BMC-RLM/brpm_module_demo)
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/brpm_module_demo.png)](http://badge.fury.io/rb/brpm_module_demo)
6
+
7
+ This repository represents an module for a fictive customer "Demo", to be used on top of the [BRPM content framework](https://github.com/BMC-RLM/brpm_content_framework). It contains customer-specific logic to integrate BRPM and JIRA in both directions: creating BRPM tickets from created or updated JIRA issues and udating the state of JIRA issues after a request was deployed into an environment.
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"
data/config.yml ADDED
@@ -0,0 +1,12 @@
1
+ dependencies:
2
+ - brpm_module_brpm
3
+ - brpm_module_jira
4
+
5
+ version: 0.1.13
6
+
7
+ author: Niek Bartholomeus
8
+ email: niek.bartholomeus@gmail.com
9
+ homepage: https://github.com/BMC-RLM/brpm_module_demo
10
+ license: MIT
11
+ summary: Demo customer's automation scripts and libraries to run on top of the BRPM Content framework
12
+ description: Demo customer's automation scripts and libraries to run on top of the BRPM Content framework. See https://github.com/BMC-RLM/brpm_content_framework for more information about the BRPM Content framework
@@ -0,0 +1,184 @@
1
+ BrpmAuto.require_module "brpm_module_brpm"
2
+ require_relative "../../jira_mappings"
3
+
4
+ def process_event(event)
5
+ @brpm_rest_client = BrpmRestClient.new("http://#{ENV["EVENT_HANDLER_BRPM_HOST"]}:#{ENV["EVENT_HANDLER_BRPM_PORT"]}/brpm", ENV["EVENT_HANDLER_BRPM_TOKEN"])
6
+
7
+ if event.has_key?("request")
8
+ BrpmAuto.log "The event is for a request #{event["event"][0]}..."
9
+ process_request_event(event)
10
+ elsif event.has_key?("run")
11
+ BrpmAuto.log "The event is for a run #{event["event"][0]}..."
12
+ process_run_event(event)
13
+ elsif event.has_key?("plan")
14
+ BrpmAuto.log "The event is for a plan #{event["event"][0]}..."
15
+ process_plan_event(event)
16
+ end
17
+ end
18
+
19
+ def process_request_event(event)
20
+ if event["event"][0] == "create"
21
+ request = event["request"].find { |item| item["type"] == "new" }
22
+
23
+ BrpmAuto.log "Request '#{request["name"][0]}' created"
24
+ elsif event["event"][0] == "update"
25
+ request_old_state = event["request"].find { |item| item["type"] == "old" }
26
+ request_new_state = event["request"].find { |item| item["type"] == "new" }
27
+
28
+ if request_old_state["aasm-state"][0] != request_new_state["aasm-state"][0] or request_new_state["aasm-state"][0] == "complete" #TODO bug when a request is moved to complete the old state is also reported as complete
29
+ BrpmAuto.log "Request '#{request_new_state["name"][0]}' moved from state '#{request_old_state["aasm-state"][0]}' to state '#{request_new_state["aasm-state"][0]}'"
30
+
31
+ if request_new_state["aasm-state"][0] == "planned"
32
+ process_app_release_event(request_new_state)
33
+ elsif request_new_state["aasm-state"][0] == "complete"
34
+ update_tickets_in_jira_by_request(request_new_state)
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ def process_run_event(event)
41
+ if event["event"][0] == "create"
42
+ run = event["run"].find { |item| item["type"] == "new" }
43
+
44
+ BrpmAuto.log "Run '#{run["name"][0]}' created"
45
+ elsif event["event"][0] == "update"
46
+ run_old_state = event["run"].find { |item| item["type"] == "old" }
47
+ run_new_state = event["run"].find { |item| item["type"] == "new" }
48
+
49
+ if run_old_state["aasm-state"][0] != run_new_state["aasm-state"][0]
50
+ BrpmAuto.log "Run '#{run_new_state["name"][0]}' moved from state '#{run_old_state["aasm-state"][0]}' to state '#{run_new_state["aasm-state"][0]}'"
51
+
52
+ if run_new_state["aasm-state"][0] == "complete"
53
+ update_tickets_in_jira_by_run(run_new_state)
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ def process_plan_event(event)
60
+ if event["event"][0] == "create"
61
+ plan = event["plan"].find { |item| item["type"] == "new" }
62
+
63
+ BrpmAuto.log "Plan '#{plan["name"][0]}' created"
64
+
65
+ create_release_in_jira(plan)
66
+
67
+ elsif event["event"][0] == "update"
68
+ plan_old_state = event["plan"].find { |item| item["type"] == "old" }
69
+ plan_new_state = event["plan"].find { |item| item["type"] == "new" }
70
+
71
+ if plan_old_state["aasm-state"][0] != plan_new_state["aasm-state"][0]
72
+ BrpmAuto.log "Plan '#{plan_new_state["name"][0]}' moved from state '#{plan_old_state["aasm-state"][0]}' to state '#{plan_new_state["aasm-state"][0]}'"
73
+ end
74
+
75
+ if plan_new_state["name"][0].start_with?(plan_old_state["name"][0] + " [deleted ")
76
+ BrpmAuto.log "Plan '#{plan_old_state["name"][0]}' deleted"
77
+
78
+ delete_release_in_jira(plan_old_state)
79
+
80
+ elsif plan_old_state["name"][0] != plan_new_state["name"][0]
81
+ BrpmAuto.log "Plan '#{plan_new_state["name"][0]}' moved from state '#{plan_old_state["aasm-state"][0]}' to state '#{plan_new_state["aasm-state"][0]}'"
82
+
83
+ update_release_in_jira(plan_old_state, plan_new_state)
84
+
85
+ end
86
+ end
87
+ end
88
+
89
+ #################################
90
+ # BRPM
91
+
92
+ def process_app_release_event(request)
93
+ release_request_stage_name = "Release"
94
+ release_request_environment_name = "development"
95
+ release_request_template_prefix = "Release"
96
+ deployment_request_stage_name = "Entrance"
97
+
98
+ request_with_details = @brpm_rest_client.get_request_by_id(request["id"][0]["content"])
99
+ if request_with_details.has_key?("plan_member")
100
+ plan_id = request_with_details["plan_member"]["plan"]["id"]
101
+ plan_name = request_with_details["plan_member"]["plan"]["name"]
102
+ stage_name = request_with_details["plan_member"]["stage"]["name"]
103
+ app_name = request_with_details["apps"][0]["name"]
104
+ release_request_template_name = "#{release_request_template_prefix} #{app_name} - with promotion"
105
+ request_name = request_with_details["name"] || ""
106
+ release_request_name = request_name.sub("Deploy", "Release")
107
+
108
+ if stage_name == deployment_request_stage_name
109
+ BrpmAuto.log "Creating an app release request for plan '#{plan_name}' and app '#{app_name}' ..."
110
+ @brpm_rest_client.create_request_for_plan_from_template(plan_id, release_request_stage_name, release_request_template_name, release_request_name, release_request_environment_name, true)
111
+ end
112
+ end
113
+ end
114
+ #################################
115
+
116
+ #################################
117
+ # JIRA
118
+
119
+ def get_default_params
120
+ params = {}
121
+ params["SS_integration_dns"] = ENV["EVENT_HANDLER_JIRA_URL"]
122
+ params["SS_integration_username"] = ENV["EVENT_HANDLER_JIRA_USERNAME"]
123
+ params["SS_integration_password"] = ENV["EVENT_HANDLER_JIRA_PASSWORD"]
124
+
125
+ params["brpm_url"] = "http://#{ENV["EVENT_HANDLER_BRPM_HOST"]}:#{ENV["EVENT_HANDLER_BRPM_PORT"]}/brpm"
126
+ params["brpm_api_token"] = ENV["EVENT_HANDLER_BRPM_TOKEN"]
127
+
128
+ params["log_file"] = ENV["EVENT_HANDLER_LOG_FILE"]
129
+ params
130
+ end
131
+
132
+ def update_tickets_in_jira_by_request(request)
133
+ params = get_default_params
134
+ params["request_id"] = (request["id"][0]["content"].to_i + 1000).to_s
135
+
136
+ request_with_details = @brpm_rest_client.get_request_by_id(request["id"][0]["content"])
137
+ if request_with_details.has_key?("plan_member")
138
+ stage_name = request_with_details["plan_member"]["stage"]["name"]
139
+
140
+ BrpmAuto.log "Getting the target JIRA issue status for stage #{stage_name}..."
141
+ params["target_issue_status"] = map_stage_to_issue_status(stage_name)
142
+
143
+ BrpmScriptExecutor.execute_automation_script("brpm_module_jira", "transition_issues_for_request", params)
144
+ end
145
+ end
146
+
147
+ def update_tickets_in_jira_by_run(run)
148
+ params = get_default_params
149
+ params["run_id"] = run["id"][0]["content"]
150
+
151
+ BrpmAuto.log "Getting the stage of this run..."
152
+ stage = @brpm_rest_client.get_plan_stage_by_id(run["plan_stage_id"][0]["content"])
153
+
154
+ BrpmAuto.log "Getting the target JIRA issue status for stage #{stage["name"]}..."
155
+ params["target_issue_status"] = map_stage_to_issue_status(stage["name"])
156
+
157
+ BrpmScriptExecutor.execute_automation_script("brpm_module_jira", "transition_issues_for_run", params)
158
+ end
159
+
160
+ def create_release_in_jira(plan)
161
+ params = get_default_params
162
+ params["jira_release_field_id"] = ENV["EVENT_HANDLER_JIRA_RELEASE_FIELD_ID"]
163
+ params["release_name"] = plan["name"][0]
164
+
165
+ BrpmScriptExecutor.execute_automation_script("brpm_module_jira", "create_release", params)
166
+ end
167
+
168
+ def update_release_in_jira(old_plan, new_plan)
169
+ params = get_default_params
170
+ params["jira_release_field_id"] = ENV["EVENT_HANDLER_JIRA_RELEASE_FIELD_ID"]
171
+ params["old_release_name"] = old_plan["name"][0]
172
+ params["new_release_name"] = new_plan["name"][0]
173
+
174
+ BrpmScriptExecutor.execute_automation_script("brpm_module_jira", "update_release", params)
175
+ end
176
+
177
+ def delete_release_in_jira(plan)
178
+ params = get_default_params
179
+ params["jira_release_field_id"] = ENV["EVENT_HANDLER_JIRA_RELEASE_FIELD_ID"]
180
+ params["release_name"] = plan["name"][0]
181
+
182
+ BrpmScriptExecutor.execute_automation_script("brpm_module_jira", "delete_release", params)
183
+ end
184
+ #################################
@@ -0,0 +1,89 @@
1
+ require_relative "../spec_helper"
2
+
3
+ describe '/api/applications' do
4
+ before(:all) do
5
+ setup
6
+ end
7
+
8
+ it 'should create an application' do
9
+ app = {}
10
+ app["name"] = "rest_api_test_app1"
11
+
12
+ result = brpm_post "v1/apps", { :app => app}
13
+
14
+ result["code"].should eq(201)
15
+ end
16
+
17
+ it 'should create another application' do
18
+ app = {}
19
+ app["name"] = "rest_api_test_app2"
20
+
21
+ result = brpm_post "v1/apps", { :app => app}
22
+
23
+ result["code"].should eq(201)
24
+ end
25
+
26
+ it 'should get all the applications' do
27
+ result = brpm_get "v1/apps"
28
+
29
+ result["code"].should eq(200)
30
+ result["response"].length.should be >= 6
31
+ end
32
+
33
+ it 'should get an application by name' do
34
+ result = brpm_get "v1/apps?filters[name]=rest_api_test_app1"
35
+
36
+ result["code"].should eq(200)
37
+ result["response"].length.should eq(1)
38
+ result["response"][0]["name"].should eq("rest_api_test_app1")
39
+ end
40
+
41
+ it 'should update an application' do
42
+ result = brpm_get "v1/apps?filters[name]=rest_api_test_app1"
43
+
44
+ result["code"].should eq(200)
45
+
46
+ app_id = result["response"][0]["id"]
47
+
48
+ newname = "#{Time.now.strftime("%Y%m%d%H%M%S")} - rest_api_test_app1"
49
+ app = {}
50
+ app["name"] = newname
51
+
52
+ result = brpm_put "v1/apps/#{app_id}", { :app => app}
53
+
54
+ result["code"].should eq(202)
55
+ result["response"]["name"].should eq(newname)
56
+ end
57
+
58
+ it 'should update another application' do
59
+ result = brpm_get "v1/apps?filters[name]=rest_api_test_app2"
60
+
61
+ result["code"].should eq(200)
62
+
63
+ app_id = result["response"][0]["id"]
64
+
65
+ newname = "#{Time.now.strftime("%Y%m%d%H%M%S")} - rest_api_test_app2"
66
+ app = {}
67
+ app["name"] = newname
68
+
69
+ result = brpm_put "v1/apps/#{app_id}", { :app => app}
70
+
71
+ result["code"].should eq(202)
72
+ result["response"]["name"].should eq(newname)
73
+ end
74
+
75
+ it 'should delete all applications' do
76
+ result = brpm_get "v1/apps"
77
+
78
+ result["code"].should eq(200)
79
+
80
+ result["response"].each do |app|
81
+ if app["name"] =~ /rest_api_test_app/
82
+ result = brpm_delete "v1/apps/#{app["id"]}"
83
+
84
+ result["code"].should eq(202)
85
+ end
86
+ end
87
+
88
+ end
89
+ end
@@ -0,0 +1,69 @@
1
+ require_relative "../spec_helper"
2
+
3
+ plan_id = nil
4
+
5
+ describe '/api/plans' do
6
+ before(:all) do
7
+ setup
8
+ end
9
+
10
+ it 'should _create_ a plan from a plan template with associated stages and request templates' do
11
+ plan = {}
12
+ plan["name"] = "#{Time.now.strftime("%Y%m%d%H%M%S")} - rest_api_test_plan_from_template"
13
+ plan["plan_template_name"] = "rest_api_test_plan_template"
14
+ plan["deployment_coordinator_id"] = ADMIN_USER_ID
15
+ plan["environment"] = "aws_cloud"
16
+ plan["app_ids"] = [SMARTRELEASE_APP_ID]
17
+
18
+ result = brpm_post "v1/plans", { :plan => plan}
19
+
20
+ result["code"].should eq(201)
21
+
22
+ plan_id = result["response"]["id"]
23
+ end
24
+
25
+ it 'should _plan_ a plan from a plan template with associated stages and request templates' do
26
+ plan = {}
27
+ plan["aasm_event"] = "plan_it"
28
+
29
+ result = brpm_put "v1/plans/#{plan_id}", { :plan => plan}
30
+
31
+ result["code"].should eq(202)
32
+ end
33
+
34
+ it 'should _start_ a plan from a plan template with associated stages and request templates' do
35
+ plan = {}
36
+ plan["aasm_event"] = "start"
37
+
38
+ result = brpm_put "v1/plans/#{plan_id}", { :plan => plan}
39
+
40
+ result["code"].should eq(202)
41
+ end
42
+
43
+ it 'should start all requests from the plan' do
44
+ result = brpm_get "v1/plans/#{plan_id}"
45
+
46
+ result["code"].should eq(200)
47
+
48
+ plan = result["response"]
49
+ plan["members"].each do |member|
50
+ if member.has_key?("request")
51
+ request_id = member["request"]["number"].to_i - 1000
52
+
53
+ request_data = {}
54
+ request_data["aasm_event"] = "plan_it"
55
+
56
+ result = brpm_put "v1/requests/#{request_id}", { :request => request_data}
57
+
58
+ result["code"].should eq(202)
59
+
60
+ request_data = {}
61
+ request_data["aasm_event"] = "start"
62
+
63
+ result = brpm_put "v1/requests/#{request_id}", { :request => request_data}
64
+
65
+ result["code"].should eq(202)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,57 @@
1
+ require_relative "../spec_helper"
2
+
3
+ request_id = nil
4
+
5
+ describe '/api/requests' do
6
+ before(:all) do
7
+ setup
8
+ end
9
+
10
+ it 'should create a request' do
11
+ request = {}
12
+ request["name"] = "rest_api_test_request"
13
+ request["requestor_id"] = ADMIN_USER_ID
14
+ request["deployment_coordinator_id"] = ADMIN_USER_ID
15
+ request["environment"] = "aws_cloud"
16
+ request["app_ids"] = [SMARTRELEASE_APP_ID]
17
+
18
+ result = brpm_post "v1/requests", { :request => request}
19
+
20
+ result["code"].should eq(201)
21
+
22
+ request_id = result["response"]["id"]
23
+ end
24
+
25
+ it 'should plan a request' do
26
+ request = {}
27
+ request["aasm_event"] = "plan_it"
28
+
29
+ result = brpm_put "v1/requests/#{request_id}", { :request => request}
30
+
31
+ result["code"].should eq(202)
32
+ end
33
+
34
+ it 'should start a request' do
35
+ request = {}
36
+ request["aasm_event"] = "start"
37
+
38
+ result = brpm_put "v1/requests/#{request_id}", { :request => request}
39
+
40
+ result["code"].should eq(202)
41
+ end
42
+
43
+ # it 'should get all the requests' do
44
+ # result = brpm_get "v1/requests"
45
+ #
46
+ # result["code"].should eq(200)
47
+ # result["response"].length.should be >= 1
48
+ # end
49
+
50
+ it 'should get a request by name' do
51
+ result = brpm_get "v1/requests?filters[name]=rest_api_test_request"
52
+
53
+ result["code"].should eq(200)
54
+ result["response"].length.should be >= 1
55
+ result["response"][0]["name"].should eq("rest_api_test_request")
56
+ end
57
+ end
@@ -0,0 +1,33 @@
1
+ require_relative "../../../../../modules/framework/brpm_auto"
2
+
3
+ ADMIN_USER_ID = 1
4
+ SMARTRELEASE_APP_ID = 1
5
+
6
+ def setup
7
+ @brpm_url = "http://#{ENV["BRPM_HOST"]}:#{ENV["BRPM_PORT"]}/brpm"
8
+ @brpm_api_token = ENV["BRPM_API_TOKEN"]
9
+
10
+ BrpmAuto.setup( { "output_dir" => "/home/jenkins" } )
11
+ end
12
+
13
+ def add_token(path)
14
+ path + (path.include?("?") ? "&" : "?") + "token=#{@brpm_api_token}"
15
+ end
16
+
17
+ def brpm_get(path, options = {})
18
+ Rest.get("#{@brpm_url}/#{add_token(path)}", options)
19
+ end
20
+
21
+ def brpm_post(path, data, options = {})
22
+ Rest.post("#{@brpm_url}/#{add_token(path)}", data, options)
23
+ end
24
+
25
+ def brpm_put(path, data, options = {})
26
+ Rest.put("#{@brpm_url}/#{add_token(path)}", data, options)
27
+ end
28
+
29
+ def brpm_delete(path, options = {})
30
+ Rest.delete("#{@brpm_url}/#{add_token(path)}", options)
31
+ end
32
+
33
+ setup
@@ -0,0 +1,33 @@
1
+ BrpmAuto.require_module "brpm_module_brpm"
2
+ require_relative "../../jira_mappings"
3
+
4
+ def process_event(event)
5
+ BrpmAuto.log "Processing event #{event["id"]} ..."
6
+
7
+ @brpm_rest_client = BrpmRestClient.new("http://#{ENV["WEBHOOK_RECEIVER_BRPM_HOST"]}:#{ENV["WEBHOOK_RECEIVER_BRPM_PORT"]}/brpm", ENV["WEBHOOK_RECEIVER_BRPM_TOKEN"])
8
+
9
+ issue = event["issue"]
10
+
11
+ BrpmAuto.log "Validating the issue..."
12
+ unless is_issue_valid(issue)
13
+ raise "Validation error, see the log file for more information."
14
+ end
15
+
16
+ # Prepare the ticket placeholder we will use to create or update the ticket
17
+ ticket = {}
18
+ ticket["project_server_id"] = ENV["WEBHOOK_RECEIVER_INTEGRATION_ID"]
19
+
20
+ BrpmAuto.log "Associating the ticket with a plan..."
21
+ if issue["fields"]["customfield_#{ENV["WEBHOOK_RECEIVER_JIRA_RELEASE_FIELD_ID"]}"]
22
+ plan = @brpm_rest_client.get_plan_by_name(issue["fields"]["customfield_#{ENV["WEBHOOK_RECEIVER_JIRA_RELEASE_FIELD_ID"]}"]["value"])
23
+ ticket["plan_ids"] = [ plan["id"] ] unless plan.nil?
24
+ end
25
+
26
+ BrpmAuto.log "Mapping the issue to the ticket..."
27
+ map_issue_to_ticket(issue, ticket)
28
+
29
+ BrpmAuto.log "Creating or updating the ticket..."
30
+ @brpm_rest_client.create_or_update_ticket(ticket)
31
+
32
+ BrpmAuto.log "Finished processing the event."
33
+ end
@@ -0,0 +1,19 @@
1
+ BrpmAuto.require_module "brpm_module_brpm"
2
+
3
+ def process_event(event)
4
+ BrpmAuto.log "Processing event #{event["id"]} ..."
5
+
6
+ @brpm_rest_client = BrpmRestClient.new("http://#{ENV["WEBHOOK_RECEIVER_BRPM_HOST"]}:#{ENV["WEBHOOK_RECEIVER_BRPM_PORT"]}/brpm", ENV["WEBHOOK_RECEIVER_BRPM_TOKEN"])
7
+
8
+ change_request = event["change_request"]
9
+
10
+ request = @brpm_rest_client.create_request(change_request["automation_type"], "#{change_request["automation_type"]} #{change_request["number"]}","Production",false)
11
+
12
+ request_to_update = {}
13
+ request_to_update["id"] = request["id"]
14
+ request_to_update["servers"] = [ change_request["configuration_item"] ]
15
+
16
+ @brpm_rest_client.update_request_from_hash(request)
17
+
18
+ BrpmAuto.log "Finished processing the event."
19
+ end
@@ -0,0 +1,27 @@
1
+ def is_issue_valid(issue)
2
+ return true
3
+ end
4
+
5
+ def map_issue_to_ticket(issue, ticket)
6
+ ticket["foreign_id"] = issue["key"]
7
+ ticket["ticket_type"] = issue["fields"]["issuetype"]["name"]
8
+ ticket["name"] = issue["fields"]["summary"]
9
+ ticket["status"] = issue["fields"]["status"]["name"]
10
+ ticket["app_name"] = issue["fields"]["project"]["name"]
11
+
12
+ ticket["extended_attributes_attributes"] = Array.new
13
+ # ticket["extended_attributes_attributes"].push( { "name" => "blabla", "value_text" => "bloblo" } )
14
+ end
15
+
16
+ def map_stage_to_issue_status(stage)
17
+ case stage
18
+ when "Development"
19
+ return "Deployed to Development"
20
+ when "Test"
21
+ return "Deployed to Test"
22
+ else
23
+ return nil
24
+ end
25
+ end
26
+
27
+
data/module.gemspec ADDED
@@ -0,0 +1,38 @@
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__))).sub("-#{config["version"]}", "")
7
+ spec.version = config["version"]
8
+ spec.platform = Gem::Platform::RUBY
9
+ spec.license = config["license"]
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_framework", ">=0.2.38"
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"]
28
+ end
29
+ end
30
+
31
+ unless ENV["BRPM_CONTENT_FRAMEWORK_DEPLOYMENT"]
32
+ spec.add_development_dependency "rake"
33
+ spec.add_development_dependency "rspec"
34
+ end
35
+
36
+ spec.files = `git ls-files`.split("\n")
37
+ spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
38
+ end
@@ -0,0 +1,10 @@
1
+
2
+ describe 'Gemspec' do
3
+ it 'should have the right license' do
4
+ config = YAML.load_file(File.expand_path("#{File.dirname(__FILE__)}/../config.yml"))
5
+
6
+ expect(config).to have_key("license")
7
+ expect(config["license"].downcase).not_to include("gpl")
8
+ expect(config["license"].downcase).not_to include("gnu")
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brpm_module_demo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.13
5
+ platform: ruby
6
+ authors:
7
+ - Niek Bartholomeus
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: brpm_content_framework
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.38
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.38
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: brpm_module_jira
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: rake
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
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Demo customer's automation scripts and libraries to run on top of the
84
+ BRPM Content framework. See https://github.com/BMC-RLM/brpm_content_framework for
85
+ more information about the BRPM Content framework
86
+ email: niek.bartholomeus@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .ruby-version
93
+ - .travis.yml
94
+ - Gemfile
95
+ - LICENSE
96
+ - README.md
97
+ - Rakefile
98
+ - config.yml
99
+ - lib/integrations/brpm/process_event_handler_event.rb
100
+ - lib/integrations/jenkins/spec/api/applications_spec.rb
101
+ - lib/integrations/jenkins/spec/api/plans_spec.rb
102
+ - lib/integrations/jenkins/spec/api/requests_spec.rb
103
+ - lib/integrations/jenkins/spec/spec_helper.rb
104
+ - lib/integrations/jira/process_webhook_event.rb
105
+ - lib/integrations/servicenow/process_webhook_event.rb
106
+ - lib/jira_mappings.rb
107
+ - module.gemspec
108
+ - tests/gemspec_spec.rb
109
+ homepage: https://github.com/BMC-RLM/brpm_module_demo
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.1.9
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Demo customer's automation scripts and libraries to run on top of the BRPM
133
+ Content framework
134
+ test_files: []