git-story-workflow 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a59013fb08e6b4782e2a0c9639d0743d33d80a616134caffd1b0a8cbbefad0ac
4
- data.tar.gz: 9f0aa8fed701287a779f033ef7e17b3e37139104c6e3ff113b0966f4567bcc03
3
+ metadata.gz: dfb4794483a9fc8fae288f546621e9b2b3ca26cb4957a1b38234ed5a5c224f38
4
+ data.tar.gz: b41cfb8c0e1b5fe6aea8e7093b19a0d34aa743a2dbd4da89cb5fcc5fcf077a67
5
5
  SHA512:
6
- metadata.gz: 89032b278d2faf60ef6eb40bf22dd472584cd7b52bc9ffc34ed83008e1a55924277cd709f461d68300f91c180f2d2888144c6651ec0f0683cc72336043c2cc2a
7
- data.tar.gz: 0ff7fc99a9f59fbdc5cc8afd1368780030be99a81a962899434303e38d012d38c1d4a58fd6f2fc04bc58eb6a74656e9ef65512c5551422963b1b070671806bd8
6
+ metadata.gz: 529663aa542c6afc333d21bf6f3155d5a361456f05f76abfcb41581834fffb1f0271e3ea3a2a2ff97a8620c9805b9bedc6b33b77172617fb0b39868bc3cf363c
7
+ data.tar.gz: 971b4044b632e27edda167a514fffc97967bc73c5b17ff685ecfda07b73dfdaaa6d825412e5033d0f4b5988f69f53e14271f77a58b33e346c86315da52349b4b
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.5.0
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: git-story-workflow 0.4.2 ruby lib
2
+ # stub: git-story-workflow 0.5.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "git-story-workflow".freeze
6
- s.version = "0.4.2"
6
+ s.version = "0.5.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
data/lib/git/story/app.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'time'
2
2
  require 'open-uri'
3
+ require 'tins/go'
3
4
 
4
5
  class Git::Story::App
5
6
  class ::String
@@ -9,6 +10,7 @@ class Git::Story::App
9
10
  include Git::Story::Utils
10
11
  extend Git::Story::Utils
11
12
  include ComplexConfig::Provider::Shortcuts
13
+ include Tins::GO
12
14
 
13
15
  annotate :command
14
16
 
@@ -26,8 +28,9 @@ class Git::Story::App
26
28
  attr_accessor :story_author
27
29
  end
28
30
 
29
- def initialize(argv = ARGV, debug: ENV['DEBUG'].to_i == 1)
31
+ def initialize(argv = ARGV.dup, debug: ENV['DEBUG'].to_i == 1)
30
32
  @argv = argv
33
+ @opts = go 'n:', @argv
31
34
  @command = @argv.shift&.to_sym
32
35
  @debug = debug
33
36
  end
@@ -93,46 +96,52 @@ class Git::Story::App
93
96
 
94
97
  command doc: '[BRANCH] display test status of branch'
95
98
  def test_status(branch = current(check: false))
96
- auth_token = complex_config.story.semaphore_auth_token
97
- project = complex_config.story.semaphore_test_project
98
- url = "https://semaphoreci.com/api/v1/projects/#{project}/#{branch}/status?auth_token=#{auth_token}"
99
- Git::Story::SemaphoreResponse.get(url, debug: @debug)
99
+ watch do
100
+ auth_token = complex_config.story.semaphore_auth_token
101
+ project = complex_config.story.semaphore_test_project
102
+ url = "https://semaphoreci.com/api/v1/projects/#{project}/#{branch}/status?auth_token=#{auth_token}"
103
+ Git::Story::SemaphoreResponse.get(url, debug: @debug)
104
+ end
100
105
  rescue => e
101
106
  "Getting #{url.inspect} => #{e.class}: #{e}".red
102
107
  end
103
108
 
104
109
  command doc: '[BRANCH] display docker build status of branch'
105
110
  def docker_status
106
- auth_token = complex_config.story.semaphore_auth_token
107
- project = complex_config.story.semaphore_docker_project
108
- url = "https://semaphoreci.com/api/v1/projects/#{project}/docker/status?auth_token=#{auth_token}"
109
- Git::Story::SemaphoreResponse.get(url, debug: @debug)
111
+ watch do
112
+ auth_token = complex_config.story.semaphore_auth_token
113
+ project = complex_config.story.semaphore_docker_project
114
+ url = "https://semaphoreci.com/api/v1/projects/#{project}/docker/status?auth_token=#{auth_token}"
115
+ Git::Story::SemaphoreResponse.get(url, debug: @debug)
116
+ end
110
117
  rescue => e
111
118
  "Getting #{url.inspect} => #{e.class}: #{e}".red
112
119
  end
113
120
 
114
121
  command doc: '[SERVER] display deploy status of branch'
115
122
  def deploy_status(server = complex_config.story.semaphore_default_server)
116
- auth_token = complex_config.story.semaphore_auth_token
117
- project = complex_config.story.semaphore_docker_project
118
- url = "https://semaphoreci.com/api/v1/projects/#{project}/servers/#{server}?auth_token=#{auth_token}"
119
- server = Git::Story::SemaphoreResponse.get(url, debug: @debug)
120
- deploys = server.deploys
121
- upcoming = deploys.select(&:pending?)&.last
122
- passed = deploys.select(&:passed?)
123
- current = passed.first
124
- if !passed.empty? && upcoming
125
- upcoming.estimated_duration = passed.sum { |d| d.duration.to_f } / passed.size
126
- end
127
- <<~end
128
- Server: #{server.server_name&.green}
129
- Branch: #{server.branch_name&.color('#ff5f00')}
130
- Semaphore: #{server.server_url}
131
- Strategy: #{server.strategy}
132
- Upcoming:
133
- #{upcoming}
134
- Current:
135
- #{current}
123
+ watch do
124
+ auth_token = complex_config.story.semaphore_auth_token
125
+ project = complex_config.story.semaphore_docker_project
126
+ url = "https://semaphoreci.com/api/v1/projects/#{project}/servers/#{server}?auth_token=#{auth_token}"
127
+ server = Git::Story::SemaphoreResponse.get(url, debug: @debug)
128
+ deploys = server.deploys
129
+ upcoming = deploys.select(&:pending?)&.last
130
+ passed = deploys.select(&:passed?)
131
+ current = passed.first
132
+ if !passed.empty? && upcoming
133
+ upcoming.estimated_duration = passed.sum { |d| d.duration.to_f } / passed.size
134
+ end
135
+ <<~end
136
+ Server: #{server.server_name&.green}
137
+ Branch: #{server.branch_name&.color('#ff5f00')}
138
+ Semaphore: #{server.server_url}
139
+ Strategy: #{server.strategy}
140
+ Upcoming:
141
+ #{upcoming}
142
+ Current:
143
+ #{current}
144
+ end
136
145
  end
137
146
  rescue => e
138
147
  "Getting #{url.inspect} => #{e.class}: #{e}".red
@@ -140,14 +149,16 @@ class Git::Story::App
140
149
 
141
150
  command doc: '[BRANCH] display build status for branch'
142
151
  def build_status(branch = current(check: false))
143
- [
144
- "Test Status".bold,
145
- test_status(branch) || 'n/a',
146
- "Docker Status".bold,
147
- docker_status || 'n/a',
148
- "Deploy Status".bold,
149
- deploy_status || 'n/a',
150
- ] * "\n\n"
152
+ watch do
153
+ [
154
+ "Test Status".bold,
155
+ test_status(branch) || 'n/a',
156
+ "Docker Status".bold,
157
+ docker_status || 'n/a',
158
+ "Deploy Status".bold,
159
+ deploy_status || 'n/a',
160
+ ] * "\n\n"
161
+ end
151
162
  end
152
163
 
153
164
 
@@ -316,6 +327,29 @@ class Git::Story::App
316
327
 
317
328
  private
318
329
 
330
+ def watch(&block)
331
+ if seconds = @opts[?n]&.to_i and !@watching
332
+ @watching = true
333
+ if seconds == 0
334
+ seconds = 60
335
+ end
336
+ loop do
337
+ r = block.()
338
+ system('clear')
339
+ start = Time.now
340
+ puts r
341
+ refresh_at = start + seconds
342
+ duration = refresh_at - start
343
+ if duration > 0
344
+ puts "<<< #{Time.now.iso8601} Refresh every #{seconds} seconds >>>".rjust(Tins::Terminal.cols)
345
+ sleep duration
346
+ end
347
+ end
348
+ else
349
+ block.()
350
+ end
351
+ end
352
+
319
353
  def normalize_name(name, max_size: nil)
320
354
  name = name.downcase
321
355
  name = name.tr('äöü', 'aou').tr(?ß, 'ss')
@@ -101,12 +101,11 @@ class Git::Story::SemaphoreResponse < JSON::GenericObject
101
101
  end
102
102
  r = StringIO.new(r)
103
103
  duration_seconds = duration.to_f.to_i
104
- total_seconds =
105
- if passed? || failed?
106
- [ estimated_duration.to_i, duration_seconds ].min
107
- else
108
- estimated_duration.to_i
109
- end
104
+ if passed? || failed?
105
+ total_seconds = duration_seconds
106
+ else
107
+ total_seconds = estimated_duration.to_i
108
+ end
110
109
  Infobar(
111
110
  current: duration_seconds,
112
111
  total: total_seconds,
@@ -1,6 +1,6 @@
1
1
  module Git::Story
2
2
  # Git::Story version
3
- VERSION = '0.4.2'
3
+ VERSION = '0.5.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-story-workflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank