jenkins-builder 0.1.5 → 0.2.3

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: ac6853704b49650d7fcc0aea65472c83d73caa2021b395ce4bbc76c5702bd5be
4
- data.tar.gz: 61a216a6375e66a00ab6054a8a7a2f55bd67846449dd774bb12579df4bae1af1
3
+ metadata.gz: 4344c5bd63933b7a95d76310f4aca60aa7f8b8914bb85519f9de589ed60956f4
4
+ data.tar.gz: 7cd18dd16185f3650d85103f075bd45d43a6db4142232fedb554ecc1b9cf7ed4
5
5
  SHA512:
6
- metadata.gz: 858baeb43ab21458cb942f7d74cf94198af95b6625ec1270ad15fc5b7be890c8a585e6f19bfb05ca4ce0215d87002db54122b647b9e151e16b1f4940fb44fbb6
7
- data.tar.gz: 870b366c39210fd66a31d7ea2518116c7588c186b1906abf2cfa94eba4ff50cf6fcc230aed17c317ae9033c262037bd104a082f925fd8eecee3c13ca8958c523
6
+ metadata.gz: 6efc476422ddc43a5f408f5b12c9cfc67d8a2297a3e62958e4fe540f0204afb6e8186f38cf50fec42cc134dba8a5a55c7f7d37f9fa221086a23265de973c36c1
7
+ data.tar.gz: b4e38a74ed226ca256849ee306d6c907810cf2089014d24780d4b866ebeb39745d0bf6248a38a361528ee3f6167988b069c217ac7be06ab6f834d2d0a2a018b9
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.5)
4
+ jenkins-builder (0.2.2)
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,12 +22,12 @@ 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
- mini_portile2 (2.3.0)
27
+ mini_portile2 (2.4.0)
28
28
  mixlib-shellout (2.4.0)
29
- nokogiri (1.8.5)
30
- mini_portile2 (~> 2.3.0)
29
+ nokogiri (1.10.9)
30
+ mini_portile2 (~> 2.4.0)
31
31
  pastel (0.7.2)
32
32
  equatable (~> 0.5.0)
33
33
  tty-color (~> 0.4.0)
@@ -58,19 +58,19 @@ GEM
58
58
  socksify (1.7.1)
59
59
  terminal-table (1.8.0)
60
60
  unicode-display_width (~> 1.1, >= 1.1.1)
61
- thor (0.20.0)
61
+ thor (0.20.3)
62
62
  tty-color (0.4.3)
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.16.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)
@@ -95,11 +100,11 @@ module Jenkins
95
100
 
96
101
  def fetch_all_jobs
97
102
  refresh_jobs_cache unless validate_jobs_cache
98
- @config['jobs-cache']['jobs']
103
+ @config['services'][@service]['jobs-cache']['jobs']
99
104
  end
100
105
 
101
106
  def refresh_jobs_cache
102
- @config['jobs-cache'] = {
107
+ @config['services'][@service]['jobs-cache'] = {
103
108
  'expire' => (Time.now + 86400*30).strftime('%F %T'),
104
109
  'jobs' => all_jobs
105
110
  }
@@ -107,8 +112,8 @@ module Jenkins
107
112
  end
108
113
 
109
114
  def validate_jobs_cache
110
- @config['jobs-cache'] && !@config['jobs-cache'].empty? && \
111
- Time.parse(@config['jobs-cache']['expire']) > Time.now
115
+ @config['services'][@service]['jobs-cache'] && !@config['services'][@service]['jobs-cache'].empty? && \
116
+ Time.parse(@config['services'][@service]['jobs-cache']['expire']) > Time.now
112
117
  end
113
118
 
114
119
  def all_jobs
@@ -153,12 +158,12 @@ module Jenkins
153
158
  all_console_output = ''
154
159
 
155
160
  loop do
156
- console_output = @client.job.get_console_output(job_name, build_no, printed_size, 'text')
157
- all_console_output << console_output['output']
158
- print console_output['output'].gsub("\r", '') unless @options[:silent]
159
- printed_size += console_output['size'].to_i
161
+ console_output = @client.job.get_console_output(job_name, build_no, 0, 'text')
162
+ all_console_output = console_output['output']
163
+ print console_output['output'][printed_size..-1] unless @options[:silent]
164
+ printed_size = console_output['output'].size
160
165
  break unless console_output['more']
161
- sleep 2
166
+ sleep 0.5
162
167
  end
163
168
  if @options[:silent]
164
169
  spinner.stop
@@ -192,16 +197,6 @@ module Jenkins
192
197
 
193
198
  private
194
199
 
195
- def validate_os!
196
- raise 'Darwin is the only supported OS now.' unless `uname`.chomp == 'Darwin'
197
- end
198
-
199
- def validate_fzf!
200
- `fzf --version`
201
- rescue Errno::ENOENT
202
- raise 'Required command fzf is not installed.'
203
- end
204
-
205
200
  def validate_credentials!(options)
206
201
  @client = JenkinsApi::Client.new(server_url: options[:url],
207
202
  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.5"
3
+ VERSION = "0.2.3"
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.5
4
+ version: 0.2.3
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: 2018-11-19 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,9 +211,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
211
  - !ruby/object:Gem::Version
212
212
  version: '0'
213
213
  requirements: []
214
- rubyforge_project:
215
- rubygems_version: 2.7.7
216
- signing_key:
214
+ rubygems_version: 3.1.2
215
+ signing_key:
217
216
  specification_version: 4
218
217
  summary: Build Jenkins Jobs
219
218
  test_files: []