circle_status 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5856b0a4973bcc0931a8427560e13110f1bf9b5b
4
+ data.tar.gz: 8787b5faa65f53aeca87a796329acdf56aa35ef7
5
+ SHA512:
6
+ metadata.gz: 93890105a9be66b7cd38b3ff43c97144b1900bd8bd6b07180fe4468e75ca721a48d3c7672259c6f79fa43d5c98ad48e7bbbe8f1cc38e4449f393d1a8f45a1b57
7
+ data.tar.gz: 0d9cd00e6295b4c1a55c1d71c86788750eb17e051745c5b5425ab09c0b3ea954d6fec73c8abd111ce1f6f9681a8062771569dcb68ef560479c941eadf798def1
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.6
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in circle_status.gemspec
4
+ gemspec
@@ -0,0 +1,59 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rsspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separetly)
25
+ # * 'just' rspec: 'rspec'
26
+ guard :rspec, cmd: 'bundle exec rspec' do
27
+ watch(%r{^spec/.+_spec\.rb$})
28
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
29
+ watch('spec/spec_helper.rb') { "spec" }
30
+
31
+ # Rails example
32
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
33
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
34
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
35
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
36
+ watch('config/routes.rb') { "spec/routing" }
37
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
38
+ watch('spec/rails_helper.rb') { "spec" }
39
+
40
+ # Capybara features specs
41
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
42
+
43
+ # Turnip features and steps
44
+ watch(%r{^spec/acceptance/(.+)\.feature$})
45
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
46
+ end
47
+
48
+
49
+ # Add files and commands to this file, like the example:
50
+ # watch(%r{file/path}) { `command(s)` }
51
+ #
52
+ guard :shell do
53
+ watch(/bin\/circle-status/) {|m| build_and_run }
54
+ watch(/\.rb$/) {|m| build_and_run }
55
+ end
56
+
57
+ def build_and_run
58
+ `rake install && circle-status`
59
+ end
@@ -0,0 +1,51 @@
1
+ # circle_status
2
+
3
+ This gem is a CLI tool to fetch your Circle CI server's build status report for your current git repo/branch. It was built because Circle CI's user interface lacks a way to easily get a simple list of test failure files, for use when debugging a failing spec locally.
4
+
5
+ The output looks like this:
6
+
7
+ ![](https://raw.githubusercontent.com/jakeonrails/circle_status/master/screenshot.png)
8
+
9
+ ## Installation
10
+
11
+ ```sh
12
+ gem install circle_status
13
+ ```
14
+
15
+ ## Connecting to your Circle CI account
16
+
17
+ The circle_status tool requires a Circle API token. It can be found or created here: https://circleci.com/account/api
18
+
19
+ Put the token in your `.bashrc` or `.zshrc` file, like this:
20
+
21
+ `export CIRCLE_CI_TOKEN="your token here"`
22
+
23
+ ## Usage
24
+
25
+ Navigate to a git repository that is hooked up to Circle CI and type:
26
+
27
+ `circle-status`
28
+
29
+ You should see something like the following:
30
+
31
+ ![](https://raw.githubusercontent.com/jakeonrails/circle_status/master/screenshot.png)
32
+
33
+ ## How it works
34
+
35
+ `circle-status` looks at the origin remote of your Git repo and parses out the Github Username and the Project/Repo name from the remote URL. It works with both the SSH URL and the HTTPS URL. Then it uses the API token stored in the environment variable CIRCLE_CI_TOKEN to connect to that project's Circle CI builds list, for the currently checked out branch in Git.
36
+
37
+ ## Todo:
38
+
39
+ - Improve the feedback when `circle-status` can't connect to the Circle API
40
+ - allow for CLI flags/options to control the git username, repo, and branch
41
+ - allow for more detailed information about specs, including the failure message and a few lines of stacktrace
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
46
+
47
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/circle_status.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'circle_status'
3
+
4
+ CircleStatus::Script.new.run
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "circle_status"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'circle_status/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'circle_status'
8
+ spec.version = CircleStatus::VERSION
9
+ spec.authors = ['Jake Moffatt']
10
+ spec.email = ['jakeonrails@gmail.com']
11
+ spec.license = 'The MIT License (MIT)'
12
+
13
+ spec.summary = %q{A CLI tool to report your Circle CI build status.}
14
+ spec.description = %q{A CLI tool to report your Circle CI build status.}
15
+ spec.homepage = %q{https://github.com/jakeonrails/circle_status}
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'bin'
27
+ spec.executables = ['circle-status']
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.10'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rspec'
33
+ spec.add_development_dependency 'guard'
34
+ spec.add_development_dependency 'guard-rspec'
35
+ spec.add_development_dependency 'guard-shell'
36
+ spec.add_development_dependency 'pry-byebug'
37
+
38
+ spec.add_dependency 'circleci'
39
+ spec.add_dependency 'git'
40
+ spec.add_dependency 'awesome_print'
41
+ end
@@ -0,0 +1,10 @@
1
+ require 'circle_status/version'
2
+ require 'circle_status/script'
3
+
4
+ require 'circleci'
5
+ require 'git'
6
+ require 'awesome_print'
7
+
8
+ module CircleStatus
9
+ class ProjectError < StandardError; end
10
+ end
@@ -0,0 +1,100 @@
1
+ module CircleStatus
2
+ class Script
3
+ def run
4
+ config
5
+
6
+ puts "Status: #{latest_build_status.upcase.white}"
7
+ puts "Successes: #{successes.size.to_s.green}"
8
+ puts "Failures: #{failures.size.to_s.red}"
9
+ puts "Failing specs: #{failing_files.join(' ').red}"
10
+ puts "Details: #{latest_build_url}"
11
+ puts
12
+ puts "Pending builds: #{pending_builds.size}"
13
+ pending_builds.map do |pending|
14
+ puts " - #{pending['status']}: #{pending['build_url']}"
15
+ end
16
+ rescue ProjectError => e
17
+ puts "Circle Status failure: #{e.message}"
18
+ end
19
+
20
+ def config
21
+ token = ENV.fetch('CIRCLE_CI_TOKEN')
22
+ raise ProjectError, 'no CIRCLE_CI_TOKEN ENV var' if token.nil?
23
+ CircleCi.configure do |config|
24
+ config.token = token
25
+ end
26
+ end
27
+
28
+ def builds
29
+ @builds ||= begin
30
+ builds = CircleCi::Project.recent_builds_branch(user_name, repo_name, branch).body
31
+ fail ProjectError, 'no builds for this repository' if builds.empty?
32
+ builds
33
+ end
34
+ end
35
+
36
+ def latest_build
37
+ @latest_build ||= begin
38
+ build = builds.find { |build| %w(failed success).include?(build['status']) }
39
+ fail ProjectError, 'no builds for this branch yet' if build.nil?
40
+ build
41
+ end
42
+ end
43
+
44
+ def pending_builds
45
+ @builds.select { |build| build['outcome'].nil? }
46
+ end
47
+
48
+ def latest_build_status
49
+ latest_build['status']
50
+ end
51
+
52
+ def latest_build_url
53
+ latest_build['build_url']
54
+ end
55
+
56
+ def tests
57
+ @tests ||= CircleCi::Build.tests(user_name, repo_name, latest_build['build_num']).body
58
+ end
59
+
60
+ def successes
61
+ @sucesses ||= split_tests.first
62
+ end
63
+
64
+ def failures
65
+ @failures ||= split_tests.last
66
+ end
67
+
68
+ def split_tests
69
+ @split_tests ||= tests['tests'].partition { |test| test['result'] != 'failure' }
70
+ end
71
+
72
+ def failing_files
73
+ @failing_files ||= failures.map { |test| test['file'] }.uniq.sort
74
+ end
75
+
76
+ def user_name
77
+ remote_url[/github.com[\/:](?<user>.+)?\//, :user]
78
+ end
79
+
80
+ def repo_name
81
+ remote_url[/.+\/(?<repo>.+).git/, :repo]
82
+ end
83
+
84
+ def remote_url
85
+ origin_remote.url
86
+ end
87
+
88
+ def origin_remote
89
+ @origin_remote ||= git.remotes.find { |r| r.name == 'origin' }
90
+ end
91
+
92
+ def branch
93
+ git.current_branch
94
+ end
95
+
96
+ def git
97
+ @git ||= Git.open(Dir.pwd)
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,3 @@
1
+ module CircleStatus
2
+ VERSION = "0.1.0"
3
+ end
Binary file
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: circle_status
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jake Moffatt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-shell
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: circleci
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: git
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: awesome_print
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: A CLI tool to report your Circle CI build status.
154
+ email:
155
+ - jakeonrails@gmail.com
156
+ executables:
157
+ - circle-status
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - ".gitignore"
162
+ - ".rspec"
163
+ - ".travis.yml"
164
+ - Gemfile
165
+ - Guardfile
166
+ - README.md
167
+ - Rakefile
168
+ - bin/circle-status
169
+ - bin/console
170
+ - bin/setup
171
+ - circle_status.gemspec
172
+ - lib/circle_status.rb
173
+ - lib/circle_status/script.rb
174
+ - lib/circle_status/version.rb
175
+ - screenshot.png
176
+ homepage: https://github.com/jakeonrails/circle_status
177
+ licenses:
178
+ - The MIT License (MIT)
179
+ metadata:
180
+ allowed_push_host: https://rubygems.org
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 2.4.8
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: A CLI tool to report your Circle CI build status.
201
+ test_files: []