termcity 0.5.0 → 1.0.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
  SHA1:
3
- metadata.gz: f1fe6111612429630e0d33e5812ca88f64a64277
4
- data.tar.gz: 2ddf23d6ed8c78cc5f0430a7cd8f1e3bb45d6613
3
+ metadata.gz: c892485b183a6b842bc3423e3e763e46cf7290f0
4
+ data.tar.gz: 9624a4743a97c74b8615a0ab6131fdedc9f800e2
5
5
  SHA512:
6
- metadata.gz: 3e427dd57a1a013ee9b51654b05ad08e5ba64c7291e4e6eb65aa93bf2f148f1808eafa7730bb64a08fc3352e7ae1b9d54efe3c78add9042fa598ca8afd98ce53
7
- data.tar.gz: 4bb7a19d404fc7a2a1d5f84e31b951f5a33b83f285cbba8dd9ec6a2b97792cb0aae3a322902f19a2073505b7c682590c5832ce010abc6877bf27a6866b7f0488
6
+ metadata.gz: 57adcd164a8300e3b36d43a2696c9cde192cd9147fd7c1aef643c8643fb412dd1a09b873ceae23d1679f7663939f48a3dab40ee44f9144c6965827a530f38312
7
+ data.tar.gz: e2ff976bdf83a13e6341f0bd2e81b509d1a2ae5861bd437906c1fb4447dbdf08b73595d78a631d6292b29c58344573557c2dd024db64ba8c61837b28bf3c6ac0
data/exe/termcity CHANGED
@@ -13,7 +13,8 @@ HELP = <<~TXT
13
13
  [Options]
14
14
 
15
15
  -b, --branch: defaults to current repo branch
16
- -p, --project: defaults to camelcasing repo directory
16
+ -p, --teamcity-project: defaults to camelcasing repo directory
17
+ -n, --circleci-reponame: defaults to repo directory
17
18
  -r, --revision: defaults to latest revision known to CI
18
19
 
19
20
  [CREDENTIALS]:
@@ -51,10 +52,14 @@ OptionParser.new do |opts|
51
52
  options[:branch] = b
52
53
  end
53
54
 
54
- opts.on("-p PROJECT_ID", "--project PROJECT_ID", "The project id (defaults to camelCasing on repo directory)") do |p|
55
+ opts.on("-p PROJECT_ID", "--teamcity-project PROJECT_ID", "The project id (defaults to camelCasing on repo directory)") do |p|
55
56
  options[:project_id] = p
56
57
  end
57
58
 
59
+ opts.on("-n REPONAME", "--circleci-reponame REPONAME", "The reponame (defaults to repo directory)") do |p|
60
+ options[:reponame] = p
61
+ end
62
+
58
63
  opts.on("-r REVISION", "--revision REVISION", "The git revision to look for (defaults to revision of latest test run)") do |r|
59
64
  options[:revision] = r
60
65
 
@@ -84,21 +89,35 @@ if !options[:branch]
84
89
  end
85
90
  end
86
91
 
92
+ root_dir = nil
93
+
87
94
  if !options[:project_id]
88
- root_dir =
89
- `git rev-parse --show-toplevel`
95
+ root_dir ||=
96
+ File.basename(
97
+ `git rev-parse --show-toplevel`
90
98
  .chomp
91
99
  .tap { raise "detecting root dir failed" unless $?==0}
100
+ )
92
101
 
93
102
  camelcase_root_dir =
94
- File
95
- .basename(root_dir)
103
+ root_dir
96
104
  .sub(/^[a-z\d]*/) { $&.capitalize }
97
105
  .gsub(/(?:_|(\/))([a-z\d]*)/) { $2.capitalize }
98
106
 
99
107
  options[:project_id] = camelcase_root_dir
100
108
  end
101
109
 
110
+ if !options[:reponame]
111
+ root_dir ||=
112
+ File.basename(
113
+ `git rev-parse --show-toplevel`
114
+ .chomp
115
+ .tap { raise "detecting root dir failed" unless $?==0}
116
+ )
117
+
118
+ options[:reponame] = root_dir
119
+ end
120
+
102
121
  creds_file = File.expand_path("~/.termcity")
103
122
  if !File.exist?(creds_file)
104
123
  warn "Could not find a credentials file. See --help for info."
@@ -122,5 +141,6 @@ Termcity::CLI.simple_format(
122
141
  host: yaml["host"],
123
142
  branch: options[:branch],
124
143
  revision: options[:revision],
125
- project_id: options[:project_id]
144
+ project_id: options[:project_id],
145
+ reponame: options[:reponame]
126
146
  )
data/lib/termcity/api.rb CHANGED
@@ -19,8 +19,8 @@ module Termcity
19
19
  @host = host
20
20
  end
21
21
 
22
- def summary(branch:, project_id:, revision:)
23
- path = "/builds?branch=#{branch}&project_id=#{project_id}"
22
+ def summary(branch:, project_id:, revision:, reponame:)
23
+ path = "/builds?branch=#{branch}&project_id=#{project_id}&reponame=#{reponame}"
24
24
  path = "#{path}&revision=#{revision}" if revision
25
25
  url = URI.join(@host, path).to_s
26
26
  get(url)
data/lib/termcity/cli.rb CHANGED
@@ -10,12 +10,13 @@ module Termcity
10
10
  new(**args).simple_format
11
11
  end
12
12
 
13
- def initialize(branch:, token:, host:, project_id:, revision:)
13
+ def initialize(branch:, token:, host:, project_id:, revision:, reponame:)
14
14
  @branch = branch
15
15
  @token = token
16
16
  @host = host
17
17
  @project_id = project_id
18
18
  @revision = revision
19
+ @reponame = reponame
19
20
  end
20
21
 
21
22
  def simple_format
@@ -29,6 +30,7 @@ module Termcity
29
30
  branch: @branch,
30
31
  revision: @revision,
31
32
  project_id: @project_id,
33
+ reponame: @reponame,
32
34
  )
33
35
 
34
36
  formatter =
@@ -11,15 +11,15 @@ module Termcity
11
11
  end
12
12
 
13
13
  def format(summary)
14
- rows = summary.builds.map do |raw:, status:|
14
+ rows = summary.builds.map do |build|
15
15
  cols = []
16
16
 
17
- text = simple_formatter.status_string(status) { |t|
18
- "#{linkify(t, raw.fetch("web_url"))}#{" "*(10-t.length)}"
17
+ text = simple_formatter.status_string(build) { |t|
18
+ "#{linkify(t, build.fetch("web_url"))}#{" "*(10-t.length)}"
19
19
  }
20
20
 
21
- cols << linkify(text, raw.fetch("web_url"))
22
- cols << raw.fetch("build_type")
21
+ cols << linkify(text, build.fetch("web_url"))
22
+ cols << build.fetch("build_type")
23
23
  cols.join(" ")
24
24
  end
25
25
 
@@ -5,22 +5,13 @@ module Termcity
5
5
  class Simple
6
6
  include Utils::Color
7
7
 
8
- STATUSES = {
9
- queued: "queued",
10
- failing: "failing",
11
- running: "running",
12
- failed_to_start: "failstrt",
13
- failed: "failed",
14
- success: "success"
15
- }
16
-
17
8
  COLORS = {
18
- failing: :red,
19
- queued: :yellow,
20
- running: :blue,
21
- failed_to_start: :default,
22
- failed: :red,
23
- success: :green
9
+ "failing" => :red,
10
+ "queued" => :yellow,
11
+ "running" => :blue,
12
+ "failstrt" => :default,
13
+ "failed" => :red,
14
+ "success" => :green
24
15
  }
25
16
 
26
17
  attr_reader :io
@@ -29,22 +20,22 @@ module Termcity
29
20
  end
30
21
 
31
22
  def format(summary)
32
- rows = summary.builds.map do |raw:, status:|
23
+ rows = summary.builds.map { |build|
33
24
  cols = []
34
- cols << status_string(status)
35
- cols << raw.fetch("build_type")
36
- cols << raw.fetch("web_url")
25
+ cols << status_string(build)
26
+ cols << build.fetch("build_type")
27
+ cols << build.fetch("web_url")
37
28
 
38
29
  cols.join(" : ")
39
- end
30
+ }
40
31
 
41
32
  @io.puts(summarize(summary, rows))
42
33
  end
43
34
 
44
- def status_string(type:, re_enqueued:)
45
- name = STATUSES.fetch(type)
46
- name = "#{name},q" if re_enqueued
47
- color = COLORS[type]
35
+ def status_string(build)
36
+ name = build.fetch("status")
37
+ name = "#{name},q" if build.fetch("re_enqueued")
38
+ color = COLORS[build.fetch("status")]
48
39
 
49
40
  text =
50
41
  if block_given?
@@ -62,12 +53,13 @@ module Termcity
62
53
  "This revision may still be in the queue (or may be unkown/old)"
63
54
  else
64
55
 
65
- revision = summary.builds.map {|b| b.dig(:raw, "sha")}.compact.first
56
+ revision = summary.builds.map {|b| b.dig("sha")}.compact.first
66
57
  [
67
58
  rows,
68
59
  "",
69
60
  "Revision: #{revision}",
70
- "Overview: #{summary.overview_link}",
61
+ "Teamcity Overview: #{summary.teamcity_link}",
62
+ "CircleCI Overview: #{summary.circle_link}",
71
63
  counts(summary),
72
64
  ].join("\n")
73
65
  end
@@ -79,7 +71,7 @@ module Termcity
79
71
  ["Success", summary.counts[:success]],
80
72
  ["Failure", summary.counts[:failure]],
81
73
  ["Running", summary.counts[:running]],
82
- ["FailedToStart", summary.counts[:failed_to_start]],
74
+ ["FailedToStart", summary.counts[:failstrt]],
83
75
  ["Queued", summary.counts[:queued]],
84
76
  ["Re-Queued", summary.counts[:re_enqueued]]
85
77
  ]
@@ -1,10 +1,11 @@
1
1
  module Termcity
2
2
  class Summary
3
- def initialize(revision:, api:, branch:, project_id:)
3
+ def initialize(revision:, api:, branch:, project_id:, reponame:)
4
4
  @branch = branch
5
5
  @project_id = project_id
6
6
  @api = api
7
7
  @revision = revision
8
+ @reponame = reponame
8
9
  end
9
10
 
10
11
  def builds
@@ -15,8 +16,12 @@ module Termcity
15
16
  data[:counts]
16
17
  end
17
18
 
18
- def overview_link
19
- data.dig(:links, :overview)
19
+ def teamcity_link
20
+ data.dig(:links, :teamcity_overview)
21
+ end
22
+
23
+ def circle_link
24
+ data.dig(:links, :circle_overview)
20
25
  end
21
26
 
22
27
  def data
@@ -28,18 +33,26 @@ module Termcity
28
33
  failure: 0,
29
34
  running: 0,
30
35
  queued: 0,
31
- failed_to_start: 0,
36
+ failstrt: 0,
32
37
  re_enqueued: 0,
33
38
  }
34
39
 
35
- summary = @api.summary(branch: @branch, project_id: @project_id, revision: @revision)
40
+ summary = @api.summary(
41
+ branch: @branch,
42
+ project_id: @project_id,
43
+ revision: @revision,
44
+ reponame: @reponame
45
+ )
36
46
 
37
47
  builds = summary.fetch("builds")
38
48
  .sort_by {|b| b.fetch("build_type")}
39
49
  .map {|b| summarize(b, counts) }
40
50
 
41
51
  {
42
- links: {overview: summary.dig("links", "overview")},
52
+ links: {
53
+ teamcity_overview: summary.dig("links", "teamcity_overview"),
54
+ circle_overview: summary.dig("links", "circle_overview")
55
+ },
43
56
  builds: builds,
44
57
  counts: counts
45
58
  }
@@ -47,44 +60,16 @@ module Termcity
47
60
  end
48
61
 
49
62
  def summarize(build, counts)
50
- status = status(build)
51
-
52
63
  count_type =
53
- if [:failing, :failed].include?(status[:type])
64
+ if ["failing", "failed"].include?(build.fetch("status"))
54
65
  :failure
55
66
  else
56
- status[:type]
67
+ build.fetch("status").to_sym
57
68
  end
58
69
  counts[count_type] += 1
59
70
  counts[:total] += 1
60
- counts[:re_enqueued] +=1 if status[:re_enqueued]
61
-
62
- {
63
- raw: build,
64
- status: status
65
- }
66
- end
67
-
68
- def status(build)
69
- re_enqueued = build.fetch("re_enqueued")
70
-
71
- if build.fetch("state") == "queued"
72
- {type: :queued, re_enqueued: false}
73
- elsif build.fetch("state") == "running"
74
- if build.fetch("status") == "FAILURE"
75
- {type: :failing, re_enqueued: re_enqueued}
76
- else
77
- {type: :running, re_enqueued: re_enqueued}
78
- end
79
- else
80
- if build.fetch("failed_to_start", false)
81
- {type: :failed_to_start, re_enqueued: re_enqueued}
82
- elsif build.fetch("status") == "FAILURE"
83
- {type: :failed, re_enqueued: re_enqueued}
84
- else
85
- {type: :success, re_enqueued: re_enqueued}
86
- end
87
- end
71
+ counts[:re_enqueued] +=1 if build.fetch("re_enqueued")
72
+ build
88
73
  end
89
74
  end
90
75
  end
@@ -1,3 +1,3 @@
1
1
  module Termcity
2
- VERSION = "0.5.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/termcity.gemspec CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Pete Kinnecom"]
10
10
  spec.email = ["git@k7u7.com"]
11
11
 
12
- spec.summary = %q{Terminal view of TeamCity}
13
- spec.description = %q{See TeamCity build status for a branch in your terminal. Pipe it to grep or whatever. Get nicely formatted links if you use iTerm2.}
12
+ spec.summary = %q{Terminal view of TeamCity/CircleCI}
13
+ spec.description = %q{See TeamCity/CircleCI build status for a branch in your terminal. Pipe it to grep or whatever. Get nicely formatted links if you use iTerm2.}
14
14
  # spec.homepage = "none"
15
15
 
16
16
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: termcity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Kinnecom
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-05 00:00:00.000000000 Z
11
+ date: 2018-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,8 +38,8 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
- description: See TeamCity build status for a branch in your terminal. Pipe it to grep
42
- or whatever. Get nicely formatted links if you use iTerm2.
41
+ description: See TeamCity/CircleCI build status for a branch in your terminal. Pipe
42
+ it to grep or whatever. Get nicely formatted links if you use iTerm2.
43
43
  email:
44
44
  - git@k7u7.com
45
45
  executables:
@@ -85,5 +85,5 @@ rubyforge_project:
85
85
  rubygems_version: 2.5.2
86
86
  signing_key:
87
87
  specification_version: 4
88
- summary: Terminal view of TeamCity
88
+ summary: Terminal view of TeamCity/CircleCI
89
89
  test_files: []