jenkins-builder 0.1.6 → 0.2.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8b209297de2b2cd6d62f0bf706183c9e3bee95afb241c414b9d4f36a6212245
4
- data.tar.gz: 5cb72fead99328e598dbe12de2d63bc6e99a0d527ccd926880863721ac3e0ba0
3
+ metadata.gz: d859f94d866333f40f01c75294f3a661aa3405d3dd5708413a41d541c492fd3d
4
+ data.tar.gz: e07d8c00473081eade301747df108a8f0a25b06136a49391328741459f4c6a0c
5
5
  SHA512:
6
- metadata.gz: 238a4c4613fef743649e793fa2add8bee79c667cf26fd3077d67921c8266633a4f78ea5b5053319a76ffe3540e28e52e3ee7ef0b88e026e24b0847bd9fc9cae5
7
- data.tar.gz: 34720b7470b71d88cb9c742f0976a2cf1c4827d48b4956c219fb4c6d8cc33143f49de92d83a6c1f92b674f267772f043cccd306fff88de800f5c3d76a076f1e2
6
+ metadata.gz: 42578f536ef60c4a738367fae25116eb64b6c82ec1c968914be3f31a4c1560279ffd66120d2573a4531ba553a27a34c2bc95f021814053bd57ede7f68726aa9b
7
+ data.tar.gz: 4f691e4dcc7cea39bdd455166b01437004ec59c96c0e38a4ee30828e16cea5b20cc074ea6262380cc20ef7d13249366d637bf8d1d337bd846532bfb65261bfe4
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
1
+ source "https://gems.ruby-china.com"
2
2
 
3
3
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jenkins-builder (0.1.6)
4
+ jenkins-builder (0.2.3)
5
5
  jenkins_api_client (~> 1.5.3)
6
6
  pastel (~> 0.7.2)
7
7
  security (~> 0.1.3)
@@ -9,7 +9,7 @@ PATH
9
9
  tty-spinner (~> 0.8.0)
10
10
 
11
11
  GEM
12
- remote: https://rubygems.org/
12
+ remote: https://gems.ruby-china.com/
13
13
  specs:
14
14
  byebug (10.0.2)
15
15
  coderay (1.1.2)
@@ -22,11 +22,11 @@ GEM
22
22
  socksify (>= 1.7.0)
23
23
  terminal-table (>= 1.4.0)
24
24
  thor (>= 0.16.0)
25
- json (2.1.0)
25
+ json (2.3.0)
26
26
  method_source (0.9.1)
27
27
  mini_portile2 (2.4.0)
28
28
  mixlib-shellout (2.4.0)
29
- nokogiri (1.10.3)
29
+ nokogiri (1.10.9)
30
30
  mini_portile2 (~> 2.4.0)
31
31
  pastel (0.7.2)
32
32
  equatable (~> 0.5.0)
@@ -63,14 +63,14 @@ GEM
63
63
  tty-cursor (0.6.0)
64
64
  tty-spinner (0.8.0)
65
65
  tty-cursor (>= 0.5.0)
66
- unicode-display_width (1.4.0)
67
- yard (0.9.16)
66
+ unicode-display_width (1.7.0)
67
+ yard (0.9.24)
68
68
 
69
69
  PLATFORMS
70
70
  ruby
71
71
 
72
72
  DEPENDENCIES
73
- bundler (~> 1.16)
73
+ bundler (~> 2.1.2)
74
74
  jenkins-builder!
75
75
  pry (~> 0.11.3)
76
76
  pry-byebug (~> 3.6.0)
@@ -79,4 +79,4 @@ DEPENDENCIES
79
79
  rspec (~> 3.0)
80
80
 
81
81
  BUNDLED WITH
82
- 1.17.2
82
+ 2.1.2
data/exe/jk CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'jenkins/builder'
4
4
 
5
- Jenkins::Builder::App.new.main(ARGV)
5
+ Jenkins::Builder::CLI.main(ARGV)
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency 'pastel', '~> 0.7.2'
37
37
  spec.add_dependency 'tty-spinner', '~> 0.8.0'
38
38
 
39
- spec.add_development_dependency "bundler", "~> 1.16"
39
+ spec.add_development_dependency "bundler", "~> 2.1.2"
40
40
  spec.add_development_dependency "rake", "~> 10.0"
41
41
  spec.add_development_dependency "rspec", "~> 3.0"
42
42
  spec.add_development_dependency "pry", "~> 0.11.3"
@@ -1,50 +1,55 @@
1
1
  require 'jenkins/builder/cli'
2
2
  require 'jenkins/builder/config'
3
- require 'jenkins/builder/secret'
4
3
  require 'jenkins_api_client'
5
4
  require 'pastel'
6
5
  require 'tty-spinner'
7
6
  require 'time'
7
+ require 'cgi'
8
+
9
+
10
+ module JenkinsApi
11
+ module UriHelper
12
+ # Encode a string for using in the query part of an URL
13
+ #
14
+ def form_encode(string)
15
+ URI.encode_www_form_component string.encode(Encoding::UTF_8)
16
+ end
17
+
18
+ # Encode a string for use in the hiearchical part of an URL
19
+ #
20
+ def path_encode(path)
21
+ CGI.escape(path.encode(Encoding::UTF_8))
22
+ end
23
+ end
24
+ end
8
25
 
9
26
  module Jenkins
10
27
  module Builder
11
28
  class App
12
29
 
13
- attr_accessor :config, :secret, :client, :options
30
+ attr_accessor :config, :client, :options
14
31
 
15
- def initialize(options={})
32
+ def initialize(service, options={})
16
33
  @options = options
17
- @config = Jenkins::Builder::Config.new
18
- @secret = Jenkins::Builder::Secret.new
34
+ @service = service
35
+ @config = Jenkins::Builder::Config.new(@service)
19
36
 
20
- if @config.url && @config.username && @secret.password
37
+ if @config.url && @config.username && @config.password
21
38
  @client = JenkinsApi::Client.new(server_url: @config.url,
22
39
  username: @config.username,
23
- password: @secret.password)
40
+ password: @config.password)
24
41
  end
25
42
  end
26
43
 
27
- def main(args)
28
- validate_os!
29
- validate_fzf!
30
- Jenkins::Builder::CLI.create_alias_commands(@config.aliases || [])
31
- Jenkins::Builder::CLI.start(args)
32
- rescue => e
33
- STDERR.puts(e.message)
34
- end
35
-
36
44
  def setup(options)
37
45
  validate_credentials!(options)
38
46
 
39
47
  config.url = options[:url]
40
48
  config.username = options[:username]
41
49
  config.branches = options[:branches]
50
+ config.password = options[:password]
42
51
  config.save!
43
52
 
44
- secret.username = options[:username]
45
- secret.password = options[:password]
46
- secret.save!
47
-
48
53
  puts 'Credentials setup successfully.'
49
54
  end
50
55
 
@@ -54,7 +59,7 @@ module Jenkins
54
59
  Username: #{@config.username}
55
60
  INFO
56
61
 
57
- puts "Password: #{@secret.password}" if options[:password]
62
+ puts "Password: #{@config.password}" if options[:password]
58
63
  end
59
64
 
60
65
  def create_alias(name, command)
@@ -80,9 +85,19 @@ module Jenkins
80
85
 
81
86
  def build_each(jobs)
82
87
  if @options[:failfast]
83
- jobs.find { |job| build(job).nil? }
88
+ failed_job = jobs.find { |job| build(job).nil? }
89
+ if failed_job
90
+ exit 1
91
+ else
92
+ exit 0
93
+ end
84
94
  else
85
- jobs.each { |job| build(job) }
95
+ results = jobs.map { |job| build(job) }
96
+ if results.any? { |r| r.nil? }
97
+ exit 1
98
+ else
99
+ exit 0
100
+ end
86
101
  end
87
102
  end
88
103
 
@@ -95,11 +110,11 @@ module Jenkins
95
110
 
96
111
  def fetch_all_jobs
97
112
  refresh_jobs_cache unless validate_jobs_cache
98
- @config['jobs-cache']['jobs']
113
+ @config['services'][@service]['jobs-cache']['jobs']
99
114
  end
100
115
 
101
116
  def refresh_jobs_cache
102
- @config['jobs-cache'] = {
117
+ @config['services'][@service]['jobs-cache'] = {
103
118
  'expire' => (Time.now + 86400*30).strftime('%F %T'),
104
119
  'jobs' => all_jobs
105
120
  }
@@ -107,8 +122,8 @@ module Jenkins
107
122
  end
108
123
 
109
124
  def validate_jobs_cache
110
- @config['jobs-cache'] && !@config['jobs-cache'].empty? && \
111
- Time.parse(@config['jobs-cache']['expire']) > Time.now
125
+ @config['services'][@service]['jobs-cache'] && !@config['services'][@service]['jobs-cache'].empty? && \
126
+ Time.parse(@config['services'][@service]['jobs-cache']['expire']) > Time.now
112
127
  end
113
128
 
114
129
  def all_jobs
@@ -153,7 +168,6 @@ module Jenkins
153
168
  all_console_output = ''
154
169
 
155
170
  loop do
156
- # require 'pry'; binding.pry;
157
171
  console_output = @client.job.get_console_output(job_name, build_no, 0, 'text')
158
172
  all_console_output = console_output['output']
159
173
  print console_output['output'][printed_size..-1] unless @options[:silent]
@@ -193,16 +207,6 @@ module Jenkins
193
207
 
194
208
  private
195
209
 
196
- def validate_os!
197
- raise 'Darwin is the only supported OS now.' unless `uname`.chomp == 'Darwin'
198
- end
199
-
200
- def validate_fzf!
201
- `fzf --version`
202
- rescue Errno::ENOENT
203
- raise 'Required command fzf is not installed.'
204
- end
205
-
206
210
  def validate_credentials!(options)
207
211
  @client = JenkinsApi::Client.new(server_url: options[:url],
208
212
  username: options[:username],
@@ -7,6 +7,12 @@ module Jenkins
7
7
  class CLI < ::Thor
8
8
 
9
9
  class << self
10
+ def main(args)
11
+ validate_fzf!
12
+ @config = Jenkins::Builder::Config.new
13
+ create_alias_commands(@config.aliases || [])
14
+ start(args)
15
+ end
10
16
  def create_alias_commands(aliases)
11
17
  aliases.each do |name, command|
12
18
  desc "#{name}", "Alias for: `#{command}'"
@@ -15,8 +21,17 @@ module Jenkins
15
21
  end
16
22
  end
17
23
  end
24
+
25
+ def validate_fzf!
26
+ `fzf --version`
27
+ rescue Errno::ENOENT
28
+ raise 'Required command fzf is not installed.'
29
+ end
30
+
18
31
  end
19
32
 
33
+ class_option :service, type: :string, aliases: ['-s'], desc: 'Specify service name'
34
+
20
35
  desc 'setup [-e]', 'Setup URL, username and password, or open config file in an editor when -e specified.'
21
36
  option :edit, type: :boolean, aliases: ['-e'], desc: 'open config file in an editor'
22
37
  def setup
@@ -39,8 +54,8 @@ module Jenkins
39
54
  Jenkins::Builder::App.new.print_info(options)
40
55
  end
41
56
 
42
- desc 'build [-s] [-f] <JOB_IDENTIFIERS>', 'Build jobs'
43
- option :silent, type: :boolean, aliases: ['-s'], desc: 'suppress console output.'
57
+ desc 'build [-q] [-f] <JOB_IDENTIFIERS>', 'Build jobs'
58
+ option :quiet, type: :boolean, aliases: ['-q'], desc: 'suppress console output.'
44
59
  option :failfast, type: :boolean, aliases: ['-f'], desc: 'stop immediately when building fails.'
45
60
  option :version, type: :boolean, aliases: ['-v'], desc: 'Show version.'
46
61
  def build(*jobs)
@@ -48,7 +63,13 @@ module Jenkins
48
63
  puts Jenkins::Builder::VERSION
49
64
  exit
50
65
  end
51
- app = Jenkins::Builder::App.new(options)
66
+ if options.service.nil?
67
+ service = fzf(Config.new().services).first
68
+ exit if service.nil?
69
+ else
70
+ service = options.service
71
+ end
72
+ app = Jenkins::Builder::App.new(service, options)
52
73
  if jobs.empty?
53
74
  jobs = fzf(app.fetch_all_jobs)
54
75
  exit if jobs.empty?
@@ -4,10 +4,11 @@ module Jenkins
4
4
  module Builder
5
5
  class Config
6
6
 
7
- attr_accessor :file, :config
7
+ attr_accessor :file, :config, :service
8
8
 
9
- def initialize
9
+ def initialize(service = nil)
10
10
 
11
+ @service = service
11
12
  @file = File.expand_path('~/.jenkins-builder.yaml')
12
13
 
13
14
  if File.exist?(@file)
@@ -25,12 +26,24 @@ module Jenkins
25
26
  @config[k] = v
26
27
  end
27
28
 
29
+ def services
30
+ @config['services'].keys
31
+ end
32
+
28
33
  def username
29
- @config['username']
34
+ @config['services'][@service]['username']
30
35
  end
31
36
 
32
37
  def username=(name)
33
- @config['username'] = name
38
+ @config['services'][@service]['username'] = name
39
+ end
40
+
41
+ def password
42
+ @config['services'][@service]['password']
43
+ end
44
+
45
+ def password=(passwd)
46
+ @config['services'][@service]['password'] = passwd
34
47
  end
35
48
 
36
49
  def aliases
@@ -42,11 +55,11 @@ module Jenkins
42
55
  end
43
56
 
44
57
  def url
45
- @config['url']
58
+ @config['services'][@service]['url']
46
59
  end
47
60
 
48
61
  def url=(url)
49
- @config['url'] = url
62
+ @config['services'][@service]['url'] = url
50
63
  end
51
64
 
52
65
  def branches
@@ -58,7 +71,7 @@ module Jenkins
58
71
  end
59
72
 
60
73
  def hooks_of(job)
61
- hooks = @config['hooks'] && @config['hooks'][job]
74
+ hooks = @config['services'][@service]['hooks'] && @config['services'][@service]['hooks'][job]
62
75
  hooks = [hooks] if hooks.is_a?(String)
63
76
  hooks
64
77
  end
@@ -1,4 +1,5 @@
1
- require 'security'
1
+ $is_mac = `uname`.chomp == 'Darwin'
2
+ require 'security' if $is_mac
2
3
 
3
4
  module Jenkins
4
5
  module Builder
@@ -1,5 +1,5 @@
1
1
  module Jenkins
2
2
  module Builder
3
- VERSION = "0.1.6"
3
+ VERSION = "0.2.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jenkins-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liu Xiang
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-25 00:00:00.000000000 Z
11
+ date: 2020-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.16'
89
+ version: 2.1.2
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.16'
96
+ version: 2.1.2
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -196,7 +196,7 @@ licenses:
196
196
  - MIT
197
197
  metadata:
198
198
  allowed_push_host: https://rubygems.org
199
- post_install_message:
199
+ post_install_message:
200
200
  rdoc_options: []
201
201
  require_paths:
202
202
  - lib
@@ -211,8 +211,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
211
  - !ruby/object:Gem::Version
212
212
  version: '0'
213
213
  requirements: []
214
- rubygems_version: 3.0.3
215
- signing_key:
214
+ rubygems_version: 3.1.2
215
+ signing_key:
216
216
  specification_version: 4
217
217
  summary: Build Jenkins Jobs
218
218
  test_files: []