jenkins_pipeline_builder 0.10.5 → 0.10.6

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
- YWU1ZGI4Y2VjNTc5MmEyMGMyYTA2YjViMDAzNjJlYWNkYWI1M2RkZA==
4
+ OGVhNGM1N2I0MzllNGY3NWQwZTE4ODUyYTBlNjg3M2UyZjQyYmMzOQ==
5
5
  data.tar.gz: !binary |-
6
- MzA4OGQ1MTYwODVlNGQzNzY4N2Q4NjNmMDkxYjY2OWNjMzczMmNjOA==
6
+ YjJlYTdjNTFhYTdlODVkMWEwNjI3MWE3YmE1MzA4ZjhlM2Y1MTY3Mw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjUyYzE2YjRmNGQxNzUzOWI3ZmJmN2NlYjVhZjU3Y2JhYjcxNGNmZGFmNDc2
10
- NWE2MmJiYzNkNTVhMzI2NzcxZDExNWRjYTdiZTc4M2M1NDI1MmE3ZmJiNmFm
11
- MjM3M2I5Y2U0NWJiNjc2OTllNDZkMmMwNDQzMmJiMDgzN2UwNmI=
9
+ NjU5YzFhZTQ0MmYyZjlmOTBiZGM2OTQ5YmNiZDM1YWUyZWZhNTRjNTZhOWY3
10
+ NzIzZGI4MTMwZDJhZmE1YjJjNDNmOTY1NmU5OTEzNjE1YmZlMjBiNzNhMjU2
11
+ YTlkNDU3MjliODdlYzUzODg3OGIwNjQ0NzA2ZGI2NjQyZTdhZmM=
12
12
  data.tar.gz: !binary |-
13
- MjJlMWRiN2ZjMGRhNDZiODdlYjJiODgzNTY5Zjk2MjEyZjUxZWFjODZkNWEw
14
- ZjQ5YjU2NTQwMzJlNzNkY2M0N2E0NDRjMmIwYjUwNjZlMDM5NDQyZDdmMzQw
15
- MmQyZDJmMmIyMDVjYTZjYWJhMjVjODMyZjk5MDc1Y2RiMGU1NDg=
13
+ ZWRmODUwZmFkZDQ1N2ZmZGJkNDU3ZDc1OGM1MTU5OGVlMWNiMGJmNTc3ODg2
14
+ N2FjNTJlYjllOWZmMjEzM2U5MmEzNzdkMTExYmRhZjI0MGI4NDE5ZmZmM2U5
15
+ ODU4Y2JlZjI5MWI3YWZlMDdlYTViMWI3ZGJmNThlZWM2NjkzNjA=
@@ -29,6 +29,7 @@ Metrics/LineLength:
29
29
  - 'spec/lib/jenkins_pipeline_builder/compiler_spec.rb'
30
30
  - 'spec/lib/jenkins_pipeline_builder/view_spec.rb'
31
31
  - 'spec/lib/jenkins_pipeline_builder/pull_request_spec.rb'
32
+ - 'spec/lib/jenkins_pipeline_builder/pull_request_generator_spec.rb'
32
33
  - 'lib/jenkins_pipeline_builder/extensions/*'
33
34
 
34
35
  # Configuration parameters: CountComments.
@@ -27,6 +27,7 @@ require 'jenkins_pipeline_builder/version'
27
27
  require 'jenkins_pipeline_builder/utils'
28
28
  require 'jenkins_pipeline_builder/compiler'
29
29
  require 'jenkins_pipeline_builder/module_registry'
30
+ require 'jenkins_pipeline_builder/pull_request_generator'
30
31
  require 'jenkins_pipeline_builder/pull_request'
31
32
  require 'jenkins_pipeline_builder/view'
32
33
  require 'jenkins_pipeline_builder/generator'
@@ -28,7 +28,7 @@ module JenkinsPipelineBuilder
28
28
  class_option :username, aliases: '-u', desc: 'Name of Jenkins user'
29
29
  class_option :password, aliases: '-p', desc: 'Password of Jenkins user'
30
30
  class_option :password_base64, aliases: '-b', desc: 'Base 64 encoded password of Jenkins user'
31
- class_option :server_ip, aliases: '-s', desc: 'Jenkins server IP address'
31
+ class_option :server, aliases: '-s', desc: 'Jenkins server IP address or URL'
32
32
  class_option :server_port, aliases: '-o', desc: 'Jenkins port'
33
33
  class_option :creds_file, aliases: '-c', desc: 'Credentials file for communicating with Jenkins server'
34
34
  class_option :debug, type: :boolean, aliases: '-d', desc: 'Run in debug mode (no Jenkins changes)', default: false
@@ -40,9 +40,8 @@ module JenkinsPipelineBuilder
40
40
  # @return [JenkinsPipelineBuilder::Generator] A new Client object
41
41
  #
42
42
  def self.setup(options)
43
- if options[:username] && options[:server_ip] && \
44
- (options[:password] || options[:password_base64])
45
- creds = options
43
+ if options[:username] && options[:server] && (options[:password] || options[:password_base64])
44
+ creds = process_cli_creds(options)
46
45
  elsif options[:creds_file]
47
46
  if options[:creds_file].end_with? 'json'
48
47
  creds = JSON.parse(IO.read(File.expand_path(options[:creds_file])))
@@ -58,7 +57,7 @@ module JenkinsPipelineBuilder
58
57
  else
59
58
  msg = 'Credentials are not set. Please pass them as parameters or'
60
59
  msg << ' set them in the default credentials file'
61
- puts msg
60
+ $stderr.puts msg
62
61
  exit 1
63
62
  end
64
63
 
@@ -67,6 +66,21 @@ module JenkinsPipelineBuilder
67
66
  generator.debug = options[:debug]
68
67
  generator
69
68
  end
69
+
70
+ def self.process_cli_creds(options)
71
+ creds = {}.with_indifferent_access.merge options
72
+ if creds[:server] =~ Resolv::AddressRegex
73
+ creds[:server_ip] = creds.delete :server
74
+ elsif creds[:server] =~ URI.regexp
75
+ creds[:server_url] = creds.delete :server
76
+ else
77
+ msg = "server given (#{creds[:server]}) is neither a URL nor an IP."
78
+ msg << ' Please pass either a valid IP address or valid URI'
79
+ $stderr.puts msg
80
+ exit 1
81
+ end
82
+ creds
83
+ end
70
84
  end
71
85
  end
72
86
  end
@@ -119,6 +119,10 @@ module JenkinsPipelineBuilder
119
119
  File.open(job_name + '.xml', 'w') { |f| f.write xml }
120
120
  end
121
121
 
122
+ def out_dir
123
+ 'out/xml'
124
+ end
125
+
122
126
  #
123
127
  # BEGIN PRIVATE METHODS
124
128
  #
@@ -618,9 +622,5 @@ module JenkinsPipelineBuilder
618
622
  xml.removedJobAction 'IGNORE'
619
623
  end
620
624
  end
621
-
622
- def out_dir
623
- 'out/xml'
624
- end
625
625
  end
626
626
  end
@@ -19,66 +19,7 @@
19
19
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
20
  # THE SOFTWARE.
21
21
  #
22
-
23
22
  module JenkinsPipelineBuilder
24
- class PullRequestGenerator
25
- attr_reader :purge
26
- attr_reader :create
27
- attr_reader :jobs
28
-
29
- def initialize(project, jobs, pull_job)
30
- @purge = []
31
- @create = []
32
- @jobs = {}
33
-
34
- pull_requests = check_for_pull pull_job
35
- purge_old(pull_requests, project)
36
- pull_requests.each do |number|
37
- # Manipulate the YAML
38
- req = JenkinsPipelineBuilder::PullRequest.new(project, number, jobs, pull_job)
39
- @jobs.merge! req.jobs
40
- project_new = req.project
41
-
42
- # Overwrite the jobs from the generator to the project
43
- project_new[:value][:jobs] = req.jobs.keys
44
- @create << project_new
45
- end
46
- end
47
-
48
- private
49
-
50
- # Check for Github Pull Requests
51
- #
52
- # args[:git_url] URL to the github main page ex. https://www.github.com/
53
- # args[:git_repo] Name of repo only, not url ex. jenkins_pipeline_builder
54
- # args[:git_org] The Orig user ex. constantcontact
55
- # @return = array of pull request numbers
56
- def check_for_pull(args)
57
- fail 'Please specify all arguments' unless args[:git_url] && args[:git_org] && args[:git_repo]
58
- # Build the Git URL
59
- git_url = "#{args[:git_url]}api/v3/repos/#{args[:git_org]}/#{args[:git_repo]}/pulls"
60
-
61
- # Download the JSON Data from the API
62
- resp = Net::HTTP.get_response(URI.parse(git_url))
63
- pulls = JSON.parse(resp.body)
64
- pulls.map { |p| p['number'] }
65
- end
66
-
67
- # Purge old builds
68
- def purge_old(pull_requests, project)
69
- reqs = pull_requests.clone.map { |req| "#{project[:name]}-PR#{req}" }
70
- # Read File
71
- old_requests = File.new('pull_requests.csv', 'a+').read.split(',')
72
-
73
- # Pop off current pull requests
74
- old_requests.delete_if { |req| reqs.include?("#{req}") }
75
- @purge = old_requests
76
-
77
- # Write File
78
- File.open('pull_requests.csv', 'w+') { |file| file.write reqs.join(',') }
79
- end
80
- end
81
-
82
23
  class PullRequest
83
24
  attr_reader :project # The root project YAML as a hash
84
25
  attr_reader :number # The pull request number
@@ -117,7 +58,7 @@ module JenkinsPipelineBuilder
117
58
  # Change the git branch for each job
118
59
  def change_git!
119
60
  @jobs.each_value do |job|
120
- job[:value][:scm_branch] = "origin/pr/#{@number}/head"
61
+ job[:value][:scm_branch] = 'origin/pr/{{pull_request_number}}/head'
121
62
  job[:value][:scm_params] = {} unless job[:value][:scm_params]
122
63
  job[:value][:scm_params][:refspec] = 'refs/pull/*:refs/remotes/origin/pr/*'
123
64
  end
@@ -0,0 +1,81 @@
1
+ #
2
+ # Copyright (c) 2014 Constant Contact
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #
22
+
23
+ module JenkinsPipelineBuilder
24
+ class PullRequestGenerator
25
+ attr_reader :purge
26
+ attr_reader :create
27
+ attr_reader :jobs
28
+
29
+ def initialize(project, jobs, pull_job)
30
+ @purge = []
31
+ @create = []
32
+ @jobs = {}
33
+
34
+ pull_requests = check_for_pull pull_job
35
+ purge_old(pull_requests, project)
36
+ pull_requests.each do |number|
37
+ # Manipulate the YAML
38
+ req = JenkinsPipelineBuilder::PullRequest.new(project, number, jobs, pull_job)
39
+ @jobs.merge! req.jobs
40
+ project_new = req.project
41
+
42
+ # Overwrite the jobs from the generator to the project
43
+ project_new[:value][:jobs] = req.jobs.keys
44
+ @create << project_new
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ # Check for Github Pull Requests
51
+ #
52
+ # args[:git_url] URL to the github main page ex. https://www.github.com/
53
+ # args[:git_repo] Name of repo only, not url ex. jenkins_pipeline_builder
54
+ # args[:git_org] The Orig user ex. constantcontact
55
+ # @return = array of pull request numbers
56
+ def check_for_pull(args)
57
+ fail 'Please specify all arguments' unless args[:git_url] && args[:git_org] && args[:git_repo]
58
+ # Build the Git URL
59
+ git_url = "#{args[:git_url]}api/v3/repos/#{args[:git_org]}/#{args[:git_repo]}/pulls"
60
+
61
+ # Download the JSON Data from the API
62
+ resp = Net::HTTP.get_response(URI.parse(git_url))
63
+ pulls = JSON.parse(resp.body)
64
+ pulls.map { |p| p['number'] }
65
+ end
66
+
67
+ # Purge old builds
68
+ def purge_old(pull_requests, project)
69
+ reqs = pull_requests.clone.map { |req| "#{project[:name]}-PR#{req}" }
70
+ # Read File
71
+ old_requests = File.new('pull_requests.csv', 'a+').read.split(',')
72
+
73
+ # Pop off current pull requests
74
+ old_requests.delete_if { |req| reqs.include?("#{req}") }
75
+ @purge = old_requests
76
+
77
+ # Write File
78
+ File.open('pull_requests.csv', 'w+') { |file| file.write reqs.join(',') }
79
+ end
80
+ end
81
+ end
@@ -21,5 +21,5 @@
21
21
  #
22
22
 
23
23
  module JenkinsPipelineBuilder
24
- VERSION = '0.10.5'
24
+ VERSION = '0.10.6'
25
25
  end
@@ -0,0 +1,105 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe JenkinsPipelineBuilder::CLI::Helper do
4
+ context '#setup' do
5
+ let(:generator) do
6
+ instance_double(
7
+ JenkinsPipelineBuilder::Generator,
8
+ :debug= => true
9
+ )
10
+ end
11
+
12
+ before(:each) do
13
+ allow(JenkinsPipelineBuilder).to receive(:generator).and_return(generator)
14
+ end
15
+
16
+ context 'username and password given' do
17
+ let(:options) do
18
+ {
19
+ username: 'username',
20
+ password: 'password'
21
+ }
22
+ end
23
+
24
+ let(:expected_options) do
25
+ {
26
+ username: 'username',
27
+ password: 'password'
28
+ }
29
+ end
30
+
31
+ it 'should handle server arg being an ipv4 address' do
32
+ expect(JenkinsPipelineBuilder).to receive(:credentials=).with(expected_options)
33
+ options[:server] = '127.0.0.1'
34
+ expected_options[:server_ip] = '127.0.0.1'
35
+ described_class.setup(options)
36
+ end
37
+
38
+ it 'should handle server arg being an ipv6 address' do
39
+ expect(JenkinsPipelineBuilder).to receive(:credentials=).with(expected_options)
40
+ options[:server] = '::1'
41
+ expected_options[:server_ip] = '::1'
42
+ described_class.setup(options)
43
+ end
44
+
45
+ it 'should handle server arg being a url' do
46
+ expect(JenkinsPipelineBuilder).to receive(:credentials=).with(expected_options)
47
+ options[:server] = 'https://localhost.localdomain'
48
+ expected_options[:server_url] = 'https://localhost.localdomain'
49
+ described_class.setup(options)
50
+ end
51
+
52
+ it 'should puts an error to stdout and exit if server is invalid' do
53
+ options[:server] = 'not_valid_at_all'
54
+ expect($stderr).to receive(:puts).with(/server given \(not_valid_at_all\)/)
55
+ expect { described_class.setup(options) }.to raise_error(SystemExit, 'exit')
56
+ end
57
+ end
58
+
59
+ context 'credential file given' do
60
+ let(:creds_file_base) { 'spec/lib/jenkins_pipeline_builder/fixtures/sample_creds' }
61
+
62
+ let(:expected_options) do
63
+ {
64
+ 'username' => 'username',
65
+ 'password' => 'password',
66
+ 'server_url' => 'https://localhost.localdomain',
67
+ 'server_port' => 8080
68
+ }
69
+ end
70
+
71
+ it 'should handle credentials passed as a yaml file' do
72
+ options = {
73
+ creds_file: "#{creds_file_base}.yaml"
74
+ }
75
+ expect(JenkinsPipelineBuilder).to receive(:credentials=).with(expected_options)
76
+ described_class.setup(options)
77
+ end
78
+
79
+ it 'should handle credentials passed as a json file' do
80
+ options = {
81
+ creds_file: "#{creds_file_base}.json"
82
+ }
83
+ expect(JenkinsPipelineBuilder).to receive(:credentials=).with(expected_options)
84
+ described_class.setup(options)
85
+ end
86
+
87
+ it 'should handle the debug flag' do
88
+ options = { debug: true }
89
+ expected_options = {
90
+ username: :foo,
91
+ password: :bar,
92
+ server_ip: :baz
93
+ }
94
+ expect(JenkinsPipelineBuilder).to receive(:credentials=).with(expected_options)
95
+ described_class.setup(options)
96
+ end
97
+
98
+ it 'should puts and error to stdout and exit if no credentials are passed' do
99
+ expect(File).to receive(:exist?).and_return(false)
100
+ expect($stderr).to receive(:puts).with(/Credentials are not set/)
101
+ expect { described_class.setup({}) }.to raise_error(SystemExit, 'exit')
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,6 @@
1
+ {
2
+ "server_url": "https://localhost.localdomain",
3
+ "server_port": 8080,
4
+ "username": "username",
5
+ "password": "password"
6
+ }
@@ -0,0 +1,4 @@
1
+ server_url: https://localhost.localdomain
2
+ server_port: 8080
3
+ username: username
4
+ password: password
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('../spec_helper', __FILE__)
2
2
 
3
3
  def cleanup_compiled_xml(job_name)
4
- Dir["#{job_name}*.xml"].each do |file|
4
+ Dir["#{@generator.out_dir}/#{job_name}*.xml"].each do |file|
5
5
  File.delete(file)
6
6
  end
7
7
  end
@@ -133,7 +133,24 @@ describe JenkinsPipelineBuilder::Generator do
133
133
  before :each do
134
134
  allow(JenkinsPipelineBuilder.client).to receive(:plugin).and_return double(
135
135
  list_installed: { 'description' => '20.0', 'git' => '20.0' })
136
+ @generator.debug = true
136
137
  end
138
+ let(:jobs) do
139
+ {
140
+ '{{name}}-10-SampleJob' => {
141
+ name: '{{name}}-10-SampleJob',
142
+ type: :job,
143
+ value: {
144
+ name: '{{name}}-10-SampleJob',
145
+ scm_branch: 'origin/pr/{{pull_request_number}}/head',
146
+ scm_params: {
147
+ refspec: 'refs/pull/*:refs/remotes/origin/pr/*'
148
+ }
149
+ }
150
+ }
151
+ }
152
+ end
153
+ let(:path) { File.expand_path('../fixtures/generator_tests/pullrequest_pipeline', __FILE__) }
137
154
  it 'produces no errors while creating pipeline PullRequest' do
138
155
  # Dummy data
139
156
  purge = []
@@ -143,29 +160,15 @@ describe JenkinsPipelineBuilder::Generator do
143
160
  type: :project,
144
161
  value: {
145
162
  name: 'PullRequest-PR1',
163
+ pull_request_number: '1',
146
164
  jobs: [
147
165
  '{{name}}-10-SampleJob'
148
166
  ]
149
167
  }
150
168
  }
151
169
  ]
152
- jobs = {
153
- '{{name}}-10-SampleJob' => {
154
- name: '{{name}}-10-SampleJob',
155
- type: :job,
156
- value: {
157
- name: '{{name}}-10-SampleJob',
158
- scm_branch: 'origin/pr/2/head',
159
- scm_params: {
160
- refspec: 'refs/pull/*:refs/remotes/origin/pr/*'
161
- }
162
- }
163
- }
164
- }
165
170
  # Run the test
166
- @generator.debug = true
167
171
  job_name = 'PullRequest'
168
- path = File.expand_path('../fixtures/generator_tests/pullrequest_pipeline', __FILE__)
169
172
  expect(JenkinsPipelineBuilder::PullRequestGenerator).to receive(:new).once.and_return(
170
173
  double(purge: purge, create: create, jobs: jobs)
171
174
  )
@@ -173,6 +176,39 @@ describe JenkinsPipelineBuilder::Generator do
173
176
  expect(success).to be_truthy
174
177
  cleanup_compiled_xml(job_name)
175
178
  end
179
+
180
+ it 'correclty creates jobs when there are multiple pulls open' do
181
+ purge = []
182
+ create = %w(1 2).map do |n|
183
+ {
184
+ name: "PullRequest-PR#{n}",
185
+ type: :project,
186
+ value: {
187
+ pull_request_number: n,
188
+ name: "PullRequest-PR#{n}",
189
+ jobs: [
190
+ '{{name}}-10-SampleJob'
191
+ ]
192
+ }
193
+ }
194
+ end
195
+ job_name = 'PullRequest'
196
+ expect(JenkinsPipelineBuilder::PullRequestGenerator).to receive(:new).once.and_return(
197
+ double(purge: purge, create: create, jobs: jobs)
198
+ )
199
+ expect(@generator).to receive(:compile_job_to_xml).once.with(
200
+ name: 'PullRequest-PR1-10-SampleJob', scm_branch: 'origin/pr/1/head', scm_params: {
201
+ refspec: 'refs/pull/*:refs/remotes/origin/pr/*'
202
+ }
203
+ )
204
+ expect(@generator).to receive(:compile_job_to_xml).once.with(
205
+ name: 'PullRequest-PR2-10-SampleJob', scm_branch: 'origin/pr/2/head', scm_params: {
206
+ refspec: 'refs/pull/*:refs/remotes/origin/pr/*'
207
+ }
208
+ )
209
+ expect(@generator.pull_request(path, job_name)).to be_truthy
210
+ cleanup_compiled_xml(job_name)
211
+ end
176
212
  # Things to check for
177
213
  # Fail - no PR job type found
178
214
  # Encounters failure during build process
@@ -0,0 +1,30 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ require 'webmock/rspec'
3
+
4
+ describe JenkinsPipelineBuilder::PullRequestGenerator do
5
+ let(:pull_request_generator) { JenkinsPipelineBuilder::PullRequestGenerator }
6
+ let(:project) { { name: 'pull_req_test', type: :project, value: { name: 'pull_req_test', jobs: ['{{name}}-00', '{{name}}-10', '{{name}}-11'] } } }
7
+ let(:jobs) { { '{{name}}-10' => { name: '{{name}}-10', type: :'job-template', value: { name: '{{name}}-10', description: '{{description}}', publishers: [{ downstream: { project: '{{job@{{name}}-11}}' } }] } }, '{{name}}-11' => { name: '{{name}}-11', type: :'job-template', value: { name: '{{name}}-11', description: '{{description}}' } } } }
8
+ let(:create_jobs) { [{ name: 'pull_req_test-PR5', type: :project, value: { name: 'pull_req_test-PR5', jobs: ['{{name}}-10', '{{name}}-11'], pull_request_number: '5' } }, { name: 'pull_req_test-PR6', type: :project, value: { name: 'pull_req_test-PR6', jobs: ['{{name}}-10', '{{name}}-11'], pull_request_number: '6' } }] }
9
+ let(:pull_request) { { name: '{{name}}-00', type: :job, name: '{{name}}-00', job_type: 'pull_request_generator', git_url: 'https://www.github.com/', git_repo: 'jenkins_pipeline_builder', git_org: 'constantcontact', jobs: ['{{name}}-10', '{{name}}-11'], builders: [{ shell_command: 'generate -v || gem install jenkins_pipeline_builder\ngenerate pipeline -c config/{{login_config}} pull_request pipeline/ {{name}}\n' }] } }
10
+ before do
11
+ # Request to get current pull requests from github
12
+ stub_request(:any, 'https://www.github.com/api/v3/repos/constantcontact/jenkins_pipeline_builder/pulls').to_return(body: '[{"number": 5,"state": "open","title": "Update README again" },{"number": 6,"state": "open", "title": "Update README again2"}]')
13
+ stub_request(:any, 'http://username:password@127.0.0.1:8080/api/json').to_return(body: '{"assignedLabels":[{}],"mode":"NORMAL","nodeDescription":"the master Jenkins node","nodeName":"","numExecutors":2,"description":null,"jobs":[{"name":"PurgeTest-PR1","url":"http://localhost:8080/job/PurgeTest-PR1/","color":"notbuilt" },{"name":"PurgeTest-PR3","url":"http://localhost:8080/job/PurgeTest-PR3/","color":"notbuilt" },{"name":"PurgeTest-PR4","url":"http://localhost:8080/job/PurgeTest-PR4/","color":"notbuilt"}],"overallLoad":{},"primaryView":{"name":"All","url":"http://localhost:8080/" },"quietingDown":false,"slaveAgentPort":0,"unlabeledLoad":{},"useCrumbs":false,"useSecurity":true,"views":[{"name":"All","url":"http://localhost:8080/"}]}')
14
+ end
15
+ describe '#initialize' do
16
+ after(:all) do
17
+ FileUtils.rm_r 'pull_requests.csv'
18
+ end
19
+ it 'can work without a csv' do
20
+ pull = pull_request_generator.new(project, jobs, pull_request)
21
+ expect(pull.purge.count).to eq(0)
22
+ expect(pull.create).to eq(create_jobs)
23
+ end
24
+ it 'can work with a csv' do
25
+ pull = pull_request_generator.new(project, jobs, pull_request)
26
+ expect(pull.purge.count).to eq(0)
27
+ expect(pull.create).to eq(create_jobs)
28
+ end
29
+ end
30
+ end
@@ -1,34 +1,6 @@
1
1
  require File.expand_path('../spec_helper', __FILE__)
2
2
  require 'webmock/rspec'
3
3
 
4
- describe JenkinsPipelineBuilder::PullRequestGenerator do
5
- let(:pull_request_generator) { JenkinsPipelineBuilder::PullRequestGenerator }
6
- let(:project) { { name: 'pull_req_test', type: :project, value: { name: 'pull_req_test', jobs: ['{{name}}-00', '{{name}}-10', '{{name}}-11'] } } }
7
- let(:jobs) { { '{{name}}-10' => { name: '{{name}}-10', type: :'job-template', value: { name: '{{name}}-10', description: '{{description}}', publishers: [{ downstream: { project: '{{job@{{name}}-11}}' } }] } }, '{{name}}-11' => { name: '{{name}}-11', type: :'job-template', value: { name: '{{name}}-11', description: '{{description}}' } } } }
8
- let(:create_jobs) { [{ name: 'pull_req_test-PR5', type: :project, value: { name: 'pull_req_test-PR5', jobs: ['{{name}}-10', '{{name}}-11'], pull_request_number: '5' } }, { name: 'pull_req_test-PR6', type: :project, value: { name: 'pull_req_test-PR6', jobs: ['{{name}}-10', '{{name}}-11'], pull_request_number: '6' } }] }
9
- let(:pull_request) { { name: '{{name}}-00', type: :job, name: '{{name}}-00', job_type: 'pull_request_generator', git_url: 'https://www.github.com/', git_repo: 'jenkins_pipeline_builder', git_org: 'constantcontact', jobs: ['{{name}}-10', '{{name}}-11'], builders: [{ shell_command: 'generate -v || gem install jenkins_pipeline_builder\ngenerate pipeline -c config/{{login_config}} pull_request pipeline/ {{name}}\n' }] } }
10
- before do
11
- # Request to get current pull requests from github
12
- stub_request(:any, 'https://www.github.com/api/v3/repos/constantcontact/jenkins_pipeline_builder/pulls').to_return(body: '[{"number": 5,"state": "open","title": "Update README again" },{"number": 6,"state": "open", "title": "Update README again2"}]')
13
- stub_request(:any, 'http://username:password@127.0.0.1:8080/api/json').to_return(body: '{"assignedLabels":[{}],"mode":"NORMAL","nodeDescription":"the master Jenkins node","nodeName":"","numExecutors":2,"description":null,"jobs":[{"name":"PurgeTest-PR1","url":"http://localhost:8080/job/PurgeTest-PR1/","color":"notbuilt" },{"name":"PurgeTest-PR3","url":"http://localhost:8080/job/PurgeTest-PR3/","color":"notbuilt" },{"name":"PurgeTest-PR4","url":"http://localhost:8080/job/PurgeTest-PR4/","color":"notbuilt"}],"overallLoad":{},"primaryView":{"name":"All","url":"http://localhost:8080/" },"quietingDown":false,"slaveAgentPort":0,"unlabeledLoad":{},"useCrumbs":false,"useSecurity":true,"views":[{"name":"All","url":"http://localhost:8080/"}]}')
14
- end
15
- describe '#initialize' do
16
- after(:all) do
17
- FileUtils.rm_r 'pull_requests.csv'
18
- end
19
- it 'can work without a csv' do
20
- pull = pull_request_generator.new(project, jobs, pull_request)
21
- expect(pull.purge.count).to eq(0)
22
- expect(pull.create).to eq(create_jobs)
23
- end
24
- it 'can work with a csv' do
25
- pull = pull_request_generator.new(project, jobs, pull_request)
26
- expect(pull.purge.count).to eq(0)
27
- expect(pull.create).to eq(create_jobs)
28
- end
29
- end
30
- end
31
-
32
4
  describe JenkinsPipelineBuilder::PullRequest do
33
5
  let(:pull_request_class) { JenkinsPipelineBuilder::PullRequest }
34
6
  let(:project) { { name: 'pull_req_test', type: :project, value: { name: 'pull_req_test', jobs: ['{{name}}-00', '{{name}}-10', '{{name}}-11'] } } }
@@ -37,7 +9,7 @@ describe JenkinsPipelineBuilder::PullRequest do
37
9
  describe '#initialize' do
38
10
  it 'process pull_request' do
39
11
  pull = pull_request_class.new(project, 2, jobs, pull_request)
40
- post_jobs = { '{{name}}-10' => { name: '{{name}}-10', type: :'job-template', value: { name: '{{name}}-10', description: '{{description}}', publishers: [{ downstream: { project: '{{job@{{name}}-11}}' } }], scm_branch: 'origin/pr/2/head', scm_params: { refspec: 'refs/pull/*:refs/remotes/origin/pr/*' } } }, '{{name}}-11' => { name: '{{name}}-11', type: :'job-template', value: { name: '{{name}}-11', description: '{{description}}', scm_branch: 'origin/pr/2/head', scm_params: { refspec: 'refs/pull/*:refs/remotes/origin/pr/*' } } } }
12
+ post_jobs = { '{{name}}-10' => { name: '{{name}}-10', type: :'job-template', value: { name: '{{name}}-10', description: '{{description}}', publishers: [{ downstream: { project: '{{job@{{name}}-11}}' } }], scm_branch: 'origin/pr/{{pull_request_number}}/head', scm_params: { refspec: 'refs/pull/*:refs/remotes/origin/pr/*' } } }, '{{name}}-11' => { name: '{{name}}-11', type: :'job-template', value: { name: '{{name}}-11', description: '{{description}}', scm_branch: 'origin/pr/{{pull_request_number}}/head', scm_params: { refspec: 'refs/pull/*:refs/remotes/origin/pr/*' } } } }
41
13
  post_project = { name: 'pull_req_test-PR2', type: :project, value: { name: 'pull_req_test-PR2', jobs: ['{{name}}-00', '{{name}}-10', '{{name}}-11'], pull_request_number: '2' } }
42
14
 
43
15
  expect(pull.project).to eq(post_project)
@@ -51,7 +23,7 @@ describe JenkinsPipelineBuilder::PullRequest do
51
23
  end
52
24
  it 'process pull_request' do
53
25
  pull = pull_request_class.new(project, 2, jobs, pull_request)
54
- post_jobs = { '{{name}}-10' => { name: '{{name}}-10', type: :'job-template', value: { name: '{{name}}-10', description: '{{description}}', publishers: [{ downstream: { project: '{{job@{{name}}-11}}' } }], scm_branch: 'origin/pr/2/head', scm_params: { refspec: 'refs/pull/*:refs/remotes/origin/pr/*' } } }, '{{name}}-11' => { name: '{{name}}-11', type: :'job-template', value: { name: '{{name}}-11', description: '{{description}}', scm_branch: 'origin/pr/2/head', scm_params: { refspec: 'refs/pull/*:refs/remotes/origin/pr/*' } } } }
26
+ post_jobs = { '{{name}}-10' => { name: '{{name}}-10', type: :'job-template', value: { name: '{{name}}-10', description: '{{description}}', publishers: [{ downstream: { project: '{{job@{{name}}-11}}' } }], scm_branch: 'origin/pr/{{pull_request_number}}/head', scm_params: { refspec: 'refs/pull/*:refs/remotes/origin/pr/*' } } }, '{{name}}-11' => { name: '{{name}}-11', type: :'job-template', value: { name: '{{name}}-11', description: '{{description}}', scm_branch: 'origin/pr/{{pull_request_number}}/head', scm_params: { refspec: 'refs/pull/*:refs/remotes/origin/pr/*' } } } }
55
27
  expect(pull.jobs).to eq(post_jobs)
56
28
  end
57
29
  end
@@ -62,7 +34,7 @@ describe JenkinsPipelineBuilder::PullRequest do
62
34
  end
63
35
  it 'process pull_request' do
64
36
  pull = pull_request_class.new(project, 2, jobs, pull_request)
65
- post_jobs = { '{{name}}-10' => { name: '{{name}}-10', type: :'job-template', value: { name: '{{name}}-10', description: '{{description}}', publishers: [{ downstream: { project: '{{job@{{name}}-11}}' } }], scm_branch: 'origin/pr/2/head', scm_params: { refspec: 'refs/pull/*:refs/remotes/origin/pr/*', changelog_to_branch: { remote: 'origin', branch: 'pr-{{pull_request_number}}' } } } }, '{{name}}-11' => { name: '{{name}}-11', type: :'job-template', value: { name: '{{name}}-11', description: '{{description}}', scm_branch: 'origin/pr/2/head', scm_params: { refspec: 'refs/pull/*:refs/remotes/origin/pr/*', changelog_to_branch: { remote: 'origin', branch: 'pr-{{pull_request_number}}' } } } } }
37
+ post_jobs = { '{{name}}-10' => { name: '{{name}}-10', type: :'job-template', value: { name: '{{name}}-10', description: '{{description}}', publishers: [{ downstream: { project: '{{job@{{name}}-11}}' } }], scm_branch: 'origin/pr/{{pull_request_number}}/head', scm_params: { refspec: 'refs/pull/*:refs/remotes/origin/pr/*', changelog_to_branch: { remote: 'origin', branch: 'pr-{{pull_request_number}}' } } } }, '{{name}}-11' => { name: '{{name}}-11', type: :'job-template', value: { name: '{{name}}-11', description: '{{description}}', scm_branch: 'origin/pr/{{pull_request_number}}/head', scm_params: { refspec: 'refs/pull/*:refs/remotes/origin/pr/*', changelog_to_branch: { remote: 'origin', branch: 'pr-{{pull_request_number}}' } } } } }
66
38
  expect(pull.jobs).to eq(post_jobs)
67
39
  end
68
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jenkins_pipeline_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.5
4
+ version: 0.10.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Moochnick
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-04 00:00:00.000000000 Z
12
+ date: 2015-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -359,6 +359,7 @@ files:
359
359
  - lib/jenkins_pipeline_builder/generator.rb
360
360
  - lib/jenkins_pipeline_builder/module_registry.rb
361
361
  - lib/jenkins_pipeline_builder/pull_request.rb
362
+ - lib/jenkins_pipeline_builder/pull_request_generator.rb
362
363
  - lib/jenkins_pipeline_builder/utils.rb
363
364
  - lib/jenkins_pipeline_builder/version.rb
364
365
  - lib/jenkins_pipeline_builder/view.rb
@@ -366,6 +367,7 @@ files:
366
367
  - out/xml/.keep
367
368
  - pipeline/Jenkins-Pipeline-Builder.yaml
368
369
  - pipeline/project.yaml
370
+ - spec/lib/jenkins_pipeline_builder/cli/helper_spec.rb
369
371
  - spec/lib/jenkins_pipeline_builder/compiler_spec.rb
370
372
  - spec/lib/jenkins_pipeline_builder/extensions/builders_spec.rb
371
373
  - spec/lib/jenkins_pipeline_builder/extensions/job_attributes_spec.rb
@@ -395,11 +397,14 @@ files:
395
397
  - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_json_files/view.json
396
398
  - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_yaml_files/project.yaml
397
399
  - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_yaml_files/view.yaml
400
+ - spec/lib/jenkins_pipeline_builder/fixtures/sample_creds.json
401
+ - spec/lib/jenkins_pipeline_builder/fixtures/sample_creds.yaml
398
402
  - spec/lib/jenkins_pipeline_builder/fixtures/view_test/duplicate_view.yaml
399
403
  - spec/lib/jenkins_pipeline_builder/fixtures/view_test/parent_view.yaml
400
404
  - spec/lib/jenkins_pipeline_builder/fixtures/view_test/regular_view.yaml
401
405
  - spec/lib/jenkins_pipeline_builder/generator_spec.rb
402
406
  - spec/lib/jenkins_pipeline_builder/module_registry_spec.rb
407
+ - spec/lib/jenkins_pipeline_builder/pull_request_generator_spec.rb
403
408
  - spec/lib/jenkins_pipeline_builder/pull_request_spec.rb
404
409
  - spec/lib/jenkins_pipeline_builder/spec_helper.rb
405
410
  - spec/lib/jenkins_pipeline_builder/utils_spec.rb
@@ -430,6 +435,7 @@ signing_key:
430
435
  specification_version: 4
431
436
  summary: This gem is will boostrap your Jenkins pipelines
432
437
  test_files:
438
+ - spec/lib/jenkins_pipeline_builder/cli/helper_spec.rb
433
439
  - spec/lib/jenkins_pipeline_builder/compiler_spec.rb
434
440
  - spec/lib/jenkins_pipeline_builder/extensions/builders_spec.rb
435
441
  - spec/lib/jenkins_pipeline_builder/extensions/job_attributes_spec.rb
@@ -459,11 +465,14 @@ test_files:
459
465
  - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_json_files/view.json
460
466
  - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_yaml_files/project.yaml
461
467
  - spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/test_yaml_files/view.yaml
468
+ - spec/lib/jenkins_pipeline_builder/fixtures/sample_creds.json
469
+ - spec/lib/jenkins_pipeline_builder/fixtures/sample_creds.yaml
462
470
  - spec/lib/jenkins_pipeline_builder/fixtures/view_test/duplicate_view.yaml
463
471
  - spec/lib/jenkins_pipeline_builder/fixtures/view_test/parent_view.yaml
464
472
  - spec/lib/jenkins_pipeline_builder/fixtures/view_test/regular_view.yaml
465
473
  - spec/lib/jenkins_pipeline_builder/generator_spec.rb
466
474
  - spec/lib/jenkins_pipeline_builder/module_registry_spec.rb
475
+ - spec/lib/jenkins_pipeline_builder/pull_request_generator_spec.rb
467
476
  - spec/lib/jenkins_pipeline_builder/pull_request_spec.rb
468
477
  - spec/lib/jenkins_pipeline_builder/spec_helper.rb
469
478
  - spec/lib/jenkins_pipeline_builder/utils_spec.rb