jenkins-builder 0.2.1 → 0.2.2

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: b4d6b880d68ab2944b3b897fc2e0a4211abaf0649ebb81184f33891ed96f6af3
4
- data.tar.gz: 62622ae525c0c80d90e9385c5748126a5764e64a8ee93e6ea3ab7c05bb895b03
3
+ metadata.gz: c8539764b2a462cde75417d8d87ce5248ad38f1804dfafc29cda15d6f450c8ac
4
+ data.tar.gz: a54a9fc99b568d807f20394adfd4209f926b8da951ddb5fc961056261932d76f
5
5
  SHA512:
6
- metadata.gz: 6b9a70fb62f8d6ad0c27b337af6a0a878506851be9a2206efc32c247ca57b2e97b9e7f8f21a9c5e0c95182c005dab522301aab5f1975e151f163d122d2703fa6
7
- data.tar.gz: 240e6787b99afeb2b8f2d29dd47508a5bd791d23c0273a85230198aaeb3fb6b8dbaaa7d3e7fe2d59836eb5a3c8456d5153ad155294fb73d6fa028a786340c4a1
6
+ metadata.gz: aa33092a43f0d46d1a8ecad68b2db695674def411296a0e2616af5314c17088bfd84f93d29468c9690b411445e3c4b14ccefeac5279815f8a30bd0fbdaa432df
7
+ data.tar.gz: 81069b1a9c51907933babc709871e8fd00a98199c6bfaec38800971fea4cd9364421d7200995fb08e84bc4d5933b168da40ca52db21dadbc5cc2d309149ae863
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jenkins-builder (0.2.1)
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)
@@ -26,7 +26,7 @@ GEM
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.4)
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,8 +63,8 @@ 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
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)
@@ -1,6 +1,5 @@
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'
@@ -24,47 +23,33 @@ module JenkinsApi
24
23
  end
25
24
  end
26
25
 
27
- $is_mac = `uname`.chomp == 'Darwin'
28
-
29
26
  module Jenkins
30
27
  module Builder
31
28
  class App
32
29
 
33
- attr_accessor :config, :secret, :client, :options
30
+ attr_accessor :config, :client, :options
34
31
 
35
32
  def initialize(options={})
36
33
  @options = options
37
- @config = Jenkins::Builder::Config.new
38
- @secret = ($is_mac ? Jenkins::Builder::Secret.new : @config)
34
+ @service = @options[:service]
35
+ @config = Jenkins::Builder::Config.new(@service)
39
36
 
40
- if @config.url && @config.username && @secret.password
37
+ if @config.url && @config.username && @config.password
41
38
  @client = JenkinsApi::Client.new(server_url: @config.url,
42
39
  username: @config.username,
43
- password: @secret.password)
40
+ password: @config.password)
44
41
  end
45
42
  end
46
43
 
47
- def main(args)
48
- # validate_os!
49
- validate_fzf!
50
- Jenkins::Builder::CLI.create_alias_commands(@config.aliases || [])
51
- Jenkins::Builder::CLI.start(args)
52
- rescue => e
53
- STDERR.puts(e.message)
54
- end
55
-
56
44
  def setup(options)
57
45
  validate_credentials!(options)
58
46
 
59
47
  config.url = options[:url]
60
48
  config.username = options[:username]
61
49
  config.branches = options[:branches]
50
+ config.password = options[:password]
62
51
  config.save!
63
52
 
64
- secret.username = options[:username]
65
- secret.password = options[:password]
66
- secret.save!
67
-
68
53
  puts 'Credentials setup successfully.'
69
54
  end
70
55
 
@@ -74,7 +59,7 @@ module Jenkins
74
59
  Username: #{@config.username}
75
60
  INFO
76
61
 
77
- puts "Password: #{@secret.password}" if options[:password]
62
+ puts "Password: #{@config.password}" if options[:password]
78
63
  end
79
64
 
80
65
  def create_alias(name, command)
@@ -115,11 +100,11 @@ module Jenkins
115
100
 
116
101
  def fetch_all_jobs
117
102
  refresh_jobs_cache unless validate_jobs_cache
118
- @config['jobs-cache']['jobs']
103
+ @config['services'][@service]['jobs-cache']['jobs']
119
104
  end
120
105
 
121
106
  def refresh_jobs_cache
122
- @config['jobs-cache'] = {
107
+ @config['services'][@service]['jobs-cache'] = {
123
108
  'expire' => (Time.now + 86400*30).strftime('%F %T'),
124
109
  'jobs' => all_jobs
125
110
  }
@@ -127,8 +112,8 @@ module Jenkins
127
112
  end
128
113
 
129
114
  def validate_jobs_cache
130
- @config['jobs-cache'] && !@config['jobs-cache'].empty? && \
131
- 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
132
117
  end
133
118
 
134
119
  def all_jobs
@@ -173,7 +158,6 @@ module Jenkins
173
158
  all_console_output = ''
174
159
 
175
160
  loop do
176
- # require 'pry'; binding.pry;
177
161
  console_output = @client.job.get_console_output(job_name, build_no, 0, 'text')
178
162
  all_console_output = console_output['output']
179
163
  print console_output['output'][printed_size..-1] unless @options[:silent]
@@ -213,16 +197,6 @@ module Jenkins
213
197
 
214
198
  private
215
199
 
216
- def validate_os!
217
- raise 'Darwin is the only supported OS now.' unless `uname`.chomp == 'Darwin'
218
- end
219
-
220
- def validate_fzf!
221
- `fzf --version`
222
- rescue Errno::ENOENT
223
- raise 'Required command fzf is not installed.'
224
- end
225
-
226
200
  def validate_credentials!(options)
227
201
  @client = JenkinsApi::Client.new(server_url: options[:url],
228
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)
@@ -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)
@@ -26,19 +27,19 @@ module Jenkins
26
27
  end
27
28
 
28
29
  def username
29
- @config['username']
30
+ @config['services'][@service]['username']
30
31
  end
31
32
 
32
33
  def username=(name)
33
- @config['username'] = name
34
+ @config['services'][@service]['username'] = name
34
35
  end
35
36
 
36
37
  def password
37
- @config['password']
38
+ @config['services'][@service]['password']
38
39
  end
39
40
 
40
41
  def password=(passwd)
41
- @config['password'] = passwd
42
+ @config['services'][@service]['password'] = passwd
42
43
  end
43
44
 
44
45
  def aliases
@@ -50,11 +51,11 @@ module Jenkins
50
51
  end
51
52
 
52
53
  def url
53
- @config['url']
54
+ @config['services'][@service]['url']
54
55
  end
55
56
 
56
57
  def url=(url)
57
- @config['url'] = url
58
+ @config['services'][@service]['url'] = url
58
59
  end
59
60
 
60
61
  def branches
@@ -66,7 +67,7 @@ module Jenkins
66
67
  end
67
68
 
68
69
  def hooks_of(job)
69
- hooks = @config['hooks'] && @config['hooks'][job]
70
+ hooks = @config['services'][@service]['hooks'] && @config['services'][@service]['hooks'][job]
70
71
  hooks = [hooks] if hooks.is_a?(String)
71
72
  hooks
72
73
  end
@@ -1,5 +1,5 @@
1
1
  module Jenkins
2
2
  module Builder
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
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.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liu Xiang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-26 00:00:00.000000000 Z
11
+ date: 2020-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor