sleet 0.2.0 → 0.3.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: 933041f7651895c7bab30f37d49946f5ce0a0ceeb481d3bb82651fe065301d73
4
- data.tar.gz: e1552d7eb0e635beb108c6d45313c814f8c67aa38efe49902c1ce7e94ba33750
3
+ metadata.gz: e54ca1197ed430d12b8d49cd3b9fcb96a981f724eebf5e6f3afca849791b54b3
4
+ data.tar.gz: fd63926e9cfa4c26e4dcd3191eb424ed5dac608a2561c8b7b7a70df3a295c34c
5
5
  SHA512:
6
- metadata.gz: 60a77f2b55d572b2bfa89a2c5c05d9c5f77e8bcf2078f7d7f7dc3fe4f01e05e21114a2b7f85bed0fd1f36ff127d7bfc92b4be8af5ecd7e041ec0d92c0e35ac49
7
- data.tar.gz: 8d178fe995d03c2840c7b4704b0afa3e640c9aa4cddef877f58d1c5cb0dade06bf28b882862d5bb918c421bad88205143df67e9d4cf1057ce42584d988fcf856
6
+ metadata.gz: fd5bb69da431a2741955b8c62ae95a7fd00ddc6723996c5511768dcae36c09a99750d0958c3bb478b2fe32dd7e7089563422c9c7cdacc12321c918cee6aab41f
7
+ data.tar.gz: 4f215f9a5281b712915b23a276ab570f905a235220ab50f34986183d4a7d7f018a53269d17021ad7ed035943752076fda37ee1ceb5896becdcd3526d93a9a64a
data/.rubocop.yml CHANGED
@@ -17,6 +17,7 @@ Metrics/ClassLength:
17
17
  Metrics/BlockLength:
18
18
  Exclude:
19
19
  - 'spec/**/*'
20
+ - '*.gemspec'
20
21
 
21
22
  Documentation:
22
23
  Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -1,16 +1,12 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2018-01-14 18:15:04 -0500 using RuboCop version 0.52.1.
3
+ # on 2018-01-15 00:27:38 -0500 using RuboCop version 0.52.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 1
10
- Metrics/AbcSize:
11
- Max: 27
12
-
13
9
  # Offense count: 1
14
10
  # Configuration parameters: CountComments.
15
11
  Metrics/MethodLength:
16
- Max: 19
12
+ Max: 15
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Change Log
2
+
3
+ ## [Unreleased](https://github.com/coreyja/sleet/tree/HEAD)
4
+
5
+ [Full Changelog](https://github.com/coreyja/sleet/compare/v0.2.0...HEAD)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Error Messages [\#3](https://github.com/coreyja/sleet/pull/3) ([coreyja](https://github.com/coreyja))
10
+
11
+ ## [v0.2.0](https://github.com/coreyja/sleet/tree/v0.2.0) (2018-01-14)
12
+ **Merged pull requests:**
13
+
14
+ - Gemify [\#2](https://github.com/coreyja/sleet/pull/2) ([coreyja](https://github.com/coreyja))
15
+
16
+
17
+
18
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Sleet
4
4
  class CircleCiBuild
5
+ attr_reader :build_num
6
+
5
7
  def initialize(github_user:, github_repo:, build_num:)
6
8
  @github_user = github_user
7
9
  @github_repo = github_repo
@@ -14,10 +16,10 @@ module Sleet
14
16
 
15
17
  private
16
18
 
17
- attr_reader :github_user, :github_repo, :build_num
19
+ attr_reader :github_user, :github_repo
18
20
 
19
21
  def url
20
- "https://circleci.com/api/v1.1/project/github/#{github_user}/#{github_repo}/#{build_num}/artifacts"
22
+ "https://circleci.com/api/v1.1/project/github/#{github_user}/#{github_repo}/#{build_num}/artifacts?filter=completed" # rubocop:disable Metrics/LineLength
21
23
  end
22
24
  end
23
25
  end
data/lib/sleet/cli.rb CHANGED
@@ -8,34 +8,56 @@ module Sleet
8
8
  option :source_dir, type: :string, aliases: [:s]
9
9
  option :input_file, type: :string, aliases: [:i]
10
10
  option :output_file, type: :string, aliases: [:o]
11
+ option :workflows, type: :hash, aliases: [:w]
11
12
  def fetch
12
- source_dir = options.fetch(:source_dir, default_dir)
13
- file_name = options.fetch(:input_file, '.rspec_example_statuses')
14
- output_file = options.fetch(:output_file, '.rspec_example_statuses')
15
-
16
- current_branch = Sleet::CurrentBranchGithub.from_dir(source_dir)
17
-
18
- branch = Sleet::CircleCiBranch.new(
19
- github_user: current_branch.github_user,
20
- github_repo: current_branch.github_repo,
21
- branch: current_branch.remote_branch
22
- )
13
+ if options[:workflows]
14
+ workflow_fetch
15
+ else
16
+ single_fetch
17
+ end
18
+ end
23
19
 
24
- build = branch.builds_with_artificats.first
20
+ private
25
21
 
26
- build = Sleet::CircleCiBuild.new(
27
- github_user: current_branch.github_user,
28
- github_repo: current_branch.github_repo,
29
- build_num: build['build_num']
30
- )
22
+ def single_fetch
23
+ Sleet::Fetcher.new(
24
+ base_fetcher_params.merge(
25
+ output_filename: options.fetch(:output_file, '.rspec_example_statuses')
26
+ )
27
+ ).do!
28
+ rescue Sleet::Error => e
29
+ error(e.message)
30
+ exit 1
31
+ end
31
32
 
32
- files = Sleet::ArtifactDownloader.new(file_name: file_name, artifacts: build.artifacts).files
33
- Dir.chdir(source_dir) do
34
- File.write(output_file, Sleet::RspecFileMerger.new(files).output)
33
+ def workflow_fetch
34
+ failed = false
35
+ options[:workflows].each do |job_name, output_filename|
36
+ begin
37
+ Sleet::Fetcher.new(
38
+ base_fetcher_params.merge(
39
+ output_filename: output_filename,
40
+ job_name: job_name
41
+ )
42
+ ).do!
43
+ rescue Sleet::Error => e
44
+ failed = true
45
+ error(e.message)
46
+ end
35
47
  end
48
+ exit 1 if failed
36
49
  end
37
50
 
38
- private
51
+ def base_fetcher_params
52
+ {
53
+ source_dir: options.fetch(:source_dir, default_dir),
54
+ input_filename: options.fetch(:input_file, '.rspec_example_statuses')
55
+ }
56
+ end
57
+
58
+ def error(message)
59
+ puts "ERROR: #{message}".red
60
+ end
39
61
 
40
62
  def default_dir
41
63
  Rugged::Repository.discover(Dir.pwd).path + '..'
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sleet
4
+ class Error < ::StandardError
5
+ end
6
+ end
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sleet
4
+ class Fetcher
5
+ class Error < ::Sleet::Error; end
6
+
7
+ def initialize(source_dir:, input_filename:, output_filename:, job_name: nil)
8
+ @source_dir = source_dir
9
+ @input_filename = input_filename
10
+ @output_filename = output_filename
11
+ @job_name = job_name
12
+ end
13
+
14
+ def do!
15
+ validate!
16
+ create_output_file!
17
+ end
18
+
19
+ def validate!
20
+ must_be_on_branch!
21
+ must_have_an_upstream_branch!
22
+ upstream_remote_must_be_github!
23
+ must_find_a_build_with_artifacts!
24
+ chosen_build_must_have_input_file!
25
+ true
26
+ end
27
+
28
+ def create_output_file!
29
+ Dir.chdir(source_dir) do
30
+ File.write(output_filename, combined_file)
31
+ end
32
+ puts "Created file (#{output_filename}) from build (##{circle_ci_build.build_num})".green
33
+ end
34
+
35
+ private
36
+
37
+ attr_reader :source_dir, :input_filename, :output_filename, :job_name
38
+
39
+ def error(msg)
40
+ raise Error, msg
41
+ end
42
+
43
+ def combined_file
44
+ @_combined_file ||= Sleet::RspecFileMerger.new(build_persistance_artifacts).output
45
+ end
46
+
47
+ def build_persistance_artifacts
48
+ @_build_persistance_artifacts ||= Sleet::ArtifactDownloader.new(
49
+ file_name: input_filename,
50
+ artifacts: circle_ci_build.artifacts
51
+ ).files
52
+ end
53
+
54
+ def circle_ci_build
55
+ @_circle_ci_build ||= Sleet::CircleCiBuild.new(
56
+ github_user: repo.github_user,
57
+ github_repo: repo.github_repo,
58
+ build_num: chosen_build_json['build_num']
59
+ )
60
+ end
61
+
62
+ def repo
63
+ @_repo ||= Sleet::Repo.from_dir(source_dir)
64
+ end
65
+
66
+ def chosen_build_json
67
+ if job_name
68
+ circle_ci_branch.builds_with_artificats.find { |b| b.fetch('workflows', {})&.fetch('job_name', {}) == job_name }
69
+ else
70
+ circle_ci_branch.builds_with_artificats.first
71
+ end
72
+ end
73
+
74
+ def circle_ci_branch
75
+ @_circle_ci_branch ||= Sleet::CircleCiBranch.new(
76
+ github_user: repo.github_user,
77
+ github_repo: repo.github_repo,
78
+ branch: repo.remote_branch
79
+ )
80
+ end
81
+
82
+ def must_be_on_branch!
83
+ repo.on_branch? ||
84
+ error('Not on a branch')
85
+ end
86
+
87
+ def must_have_an_upstream_branch!
88
+ repo.remote? ||
89
+ error("No upstream branch set for the current branch of #{repo.current_branch_name}")
90
+ end
91
+
92
+ def upstream_remote_must_be_github!
93
+ repo.github? ||
94
+ error('Upstream remote is not GitHub')
95
+ end
96
+
97
+ def must_find_a_build_with_artifacts!
98
+ !chosen_build_json.nil? ||
99
+ error("No builds with artifcats found #{"for job name [#{job_name}]" if job_name}")
100
+ end
101
+
102
+ def chosen_build_must_have_input_file!
103
+ circle_ci_build.artifacts.any? ||
104
+ error("No Rspec example file found in the latest build (##{circle_ci_build.build_num}) with artifacts")
105
+ end
106
+ end
107
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sleet
4
- class CurrentBranchGithub
4
+ class Repo
5
5
  REMOTE_BRANCH_REGEX = %r{^([^\/.]+)\/(.+)}
6
6
  CURRENT_BRANCH_REGEX = %r{^refs\/heads\/}
7
7
  GITHUB_MATCH_REGEX = %r{github.com[:\/](.+)\/(.+)\.git}
@@ -12,7 +12,18 @@ module Sleet
12
12
 
13
13
  def initialize(repo:)
14
14
  @repo = repo
15
- raise 'NOT GITHUB' unless github_match
15
+ end
16
+
17
+ def remote?
18
+ !current_branch.remote.nil?
19
+ end
20
+
21
+ def github?
22
+ !github_match.nil?
23
+ end
24
+
25
+ def on_branch?
26
+ !current_branch.nil?
16
27
  end
17
28
 
18
29
  def remote_branch
@@ -27,6 +38,10 @@ module Sleet
27
38
  github_match[2]
28
39
  end
29
40
 
41
+ def current_branch_name
42
+ repo.head.name.sub(CURRENT_BRANCH_REGEX, '')
43
+ end
44
+
30
45
  private
31
46
 
32
47
  attr_reader :repo
@@ -35,10 +50,6 @@ module Sleet
35
50
  repo.branches[current_branch_name]
36
51
  end
37
52
 
38
- def current_branch_name
39
- repo.head.name.sub(CURRENT_BRANCH_REGEX, '')
40
- end
41
-
42
53
  def github_match
43
54
  @_github_match ||= GITHUB_MATCH_REGEX.match(current_branch.remote.url)
44
55
  end
data/lib/sleet/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sleet
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/sleet.rb CHANGED
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'thor'
4
- require 'json'
5
- require 'rugged'
3
+ require 'colorize'
6
4
  require 'faraday'
5
+ require 'json'
7
6
  require 'rspec'
7
+ require 'rugged'
8
+ require 'thor'
8
9
  require 'yaml'
10
+
11
+ # This is to load the classes that are defined in the same file as this one
9
12
  begin
10
13
  RSpec::Core::ExampleStatusPersister
11
14
  end
@@ -14,8 +17,10 @@ require 'sleet/artifact_downloader'
14
17
  require 'sleet/circle_ci'
15
18
  require 'sleet/circle_ci_branch'
16
19
  require 'sleet/circle_ci_build'
17
- require 'sleet/current_branch_github'
20
+ require 'sleet/error'
21
+ require 'sleet/fetcher'
18
22
  require 'sleet/option_defaults'
23
+ require 'sleet/repo'
19
24
  require 'sleet/rspec_file_merger'
20
25
  require 'sleet/version'
21
26
 
data/sleet.gemspec CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ['lib']
28
28
 
29
+ spec.add_dependency 'colorize'
29
30
  spec.add_dependency 'faraday'
30
31
  spec.add_dependency 'rspec', '~> 3.0'
31
32
  spec.add_dependency 'rugged'
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sleet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Alexander
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-14 00:00:00.000000000 Z
11
+ date: 2018-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: faraday
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -139,6 +153,7 @@ files:
139
153
  - ".rubocop.yml"
140
154
  - ".rubocop_todo.yml"
141
155
  - ".sleet.yml"
156
+ - CHANGELOG.md
142
157
  - CODE_OF_CONDUCT.md
143
158
  - Gemfile
144
159
  - LICENSE
@@ -153,8 +168,10 @@ files:
153
168
  - lib/sleet/circle_ci_branch.rb
154
169
  - lib/sleet/circle_ci_build.rb
155
170
  - lib/sleet/cli.rb
156
- - lib/sleet/current_branch_github.rb
171
+ - lib/sleet/error.rb
172
+ - lib/sleet/fetcher.rb
157
173
  - lib/sleet/option_defaults.rb
174
+ - lib/sleet/repo.rb
158
175
  - lib/sleet/rspec_file_merger.rb
159
176
  - lib/sleet/version.rb
160
177
  - sleet.gemspec