raygun 1.1.1 → 1.2.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: eeaeb612fe4e56ab156e26d6d8299598274e0e5a8baf66647a62a399c3245067
4
- data.tar.gz: c41f24ad804b4e7301bc54de9d1ecb0f04390fc909cb9823e7855cc820c2442f
3
+ metadata.gz: 6464c730d406fd0cd161d886375e52ef103781865bfb7c81f382987351c08597
4
+ data.tar.gz: f01fc5f9e573314b6852e002e79e18ca49a1163fbcc9052008ab94ac24ab4d1e
5
5
  SHA512:
6
- metadata.gz: 88423daeb034fca34d5db7c3b97836e61a462064c87788c07a3fa20d36774a9f86be6b782dff428eccc52651a919a1483dce2caae0591842577fb19ef6ef56bf
7
- data.tar.gz: 86dd56014f3ddb0255f9ebc0796cdf038f06f8e7b7fc57c0fe9f72efeff9912a92a9c565c16bc4020b483013f667e6be4673a0a05a237ab4edddac79dcfbd094
6
+ metadata.gz: 9ac1c6b995395e8dffeb309443f204b7bd7799083b45e2ac3cf51dcc0d73a15621dcb9648da7fadb8aae133aa94bf06619d7285bc03c2c9b5b627e55bc9e2361
7
+ data.tar.gz: 1a6b817213c3ed7138a231e2f8b728b6d509c17a3e72f1a0e23248e6582261673156453c36f37fda3796774b2f0bd2946c66c32165ce9dc54281334a2a938828
data/CHANGES.md CHANGED
@@ -3,11 +3,17 @@
3
3
  **Note:** Don't let the apparent lack of activity here scare you away. Almost all changes are captured in the
4
4
  prototype repo (see [raygun-rails](https://github.com/carbonfive/raygun-rails)), and it's kept pretty well up to date.
5
5
 
6
+ ## 1.2.0 [2021-05-20]
7
+
8
+ New features:
9
+
10
+ * Copy the new rubocop conventions from the `main` branch of the c5-conventions repo (#163).
11
+
6
12
  ## 1.1.1 [2020-07-02]
7
13
 
8
14
  Housekeeping:
9
15
 
10
- * Fix compatibility so that any supported Rudy (currently 2.5+) is allowed (#165).
16
+ * Fix compatibility so that any supported Ruby (currently 2.5+) is allowed (#165).
11
17
 
12
18
  ## 1.1.0 [2020-07-02]
13
19
 
@@ -0,0 +1,65 @@
1
+ require "colorize"
2
+ require "open-uri"
3
+
4
+ module Raygun
5
+ class C5Conventions
6
+ REPO = "carbonfive/c5-conventions".freeze
7
+
8
+ SOURCES = [
9
+ "https://raw.githubusercontent.com/#{REPO}/main/rubocop/.rubocop.yml",
10
+ "https://raw.githubusercontent.com/#{REPO}/main/rubocop/.rubocop-common.yml",
11
+ "https://raw.githubusercontent.com/#{REPO}/main/rubocop/.rubocop-performance.yml",
12
+ "https://raw.githubusercontent.com/#{REPO}/main/rubocop/.rubocop-rails.yml",
13
+ "https://raw.githubusercontent.com/#{REPO}/main/rubocop/.rubocop-rspec.yml"
14
+ ].freeze
15
+
16
+ ATTRIBUTION_HEADER = <<~TEXT
17
+ # Sourced from #{REPO} @ %<sha>s
18
+ #
19
+ # If you make changes to this file, consider opening a PR to backport them to the c5-conventions repo:
20
+ # https://github.com/#{REPO}
21
+ TEXT
22
+
23
+ # Install the latest copy of c5-conventions rubocop config in the given directory.
24
+ # If the latest files can't be downloaded from GitHub, print a warning, don't raise an exception.
25
+ # Any existing .rubocop.yml will be overwritten.
26
+ def self.install(target:, sources: SOURCES)
27
+ new(target: target, sources: sources).install
28
+ rescue Errno::ENOENT, OpenURI::HTTPError => e
29
+ puts ""
30
+ puts "Failed to install the CarbonFive conventions from the #{REPO} GitHub repo".colorize(:light_red)
31
+ puts "Error: #{e}".colorize(:light_red)
32
+ puts "You'll have to manage your own `.rubocop.yml` setup".colorize(:light_red)
33
+ end
34
+
35
+ def initialize(sources:, target:)
36
+ @sources = sources
37
+ @target = target
38
+ end
39
+
40
+ def install
41
+ sources.each do |url_str|
42
+ uri = URI(url_str)
43
+ contents = [attribution_header, uri.open.read].join("\n")
44
+ filename = File.basename(uri.path)
45
+
46
+ IO.write(File.join(target, filename), contents)
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ attr_reader :sources, :target
53
+
54
+ def attribution_header
55
+ format(ATTRIBUTION_HEADER, sha: latest_commit_sha)
56
+ end
57
+
58
+ def latest_commit_sha
59
+ @latest_commit_sha ||= begin
60
+ stdout = `git ls-remote https://github.com/#{REPO} main`
61
+ stdout[/^(\h{7})/, 1] || "main"
62
+ end
63
+ end
64
+ end
65
+ end
data/lib/raygun/raygun.rb CHANGED
@@ -3,17 +3,16 @@ require "ostruct"
3
3
  require "fileutils"
4
4
  require "securerandom"
5
5
  require "net/http"
6
- require "open-uri"
7
6
  require "json"
8
7
  require "colorize"
9
8
 
10
9
  require_relative "version"
10
+ require_relative "c5_conventions"
11
11
  require_relative "template_repo"
12
12
 
13
13
  module Raygun
14
14
  class Runner
15
15
  CARBONFIVE_REPO = "carbonfive/raygun-rails"
16
- C5_CONVENTIONS_REPO = "carbonfive/c5-conventions"
17
16
 
18
17
  attr_accessor :target_dir, :app_dir, :app_name, :dash_name, :snake_name,
19
18
  :camel_name, :title_name, :prototype_repo,
@@ -108,7 +107,7 @@ module Raygun
108
107
  FileUtils.mv dirs_to_move, app_dir
109
108
  FileUtils.remove_dir extraneous_dir
110
109
 
111
- fetch_rubocop_file if @prototype_repo == CARBONFIVE_REPO
110
+ C5Conventions.install(target: app_dir) if @prototype_repo == CARBONFIVE_REPO
112
111
  end
113
112
 
114
113
  def rename_new_app
@@ -222,30 +221,6 @@ module Raygun
222
221
 
223
222
  protected
224
223
 
225
- def fetch_rubocop_file
226
- sha = shell("git ls-remote https://github.com/#{C5_CONVENTIONS_REPO} master") || ""
227
- sha = sha.slice(0..6)
228
-
229
- rubocop_file = "https://raw.githubusercontent.com/#{C5_CONVENTIONS_REPO}/master/rubocop/rubocop.yml"
230
- begin
231
- rubocop_contents = URI.open(rubocop_file)
232
- IO.write("#{@app_dir}/.rubocop.yml", <<~RUBOCOP_YML)
233
- # Sourced from #{C5_CONVENTIONS_REPO} @ #{sha}
234
- #
235
- # If you make changes to this file, consider opening
236
- # a PR to backport them to the c5-conventions repo:
237
- # https://github.com/#{C5_CONVENTIONS_REPO}/blob/master/rubocop/rubocop.yml
238
-
239
- #{rubocop_contents.string}
240
- RUBOCOP_YML
241
- rescue Errno::ENOENT, OpenURI::HTTPError => e
242
- puts ""
243
- puts "Failed to find the CarbonFive conventions rubocop file at #{rubocop_file}".colorize(:light_red)
244
- puts "Error: #{e}".colorize(:light_red)
245
- puts "You'll have to manage you're own `.rubocop.yml` setup".colorize(:light_red)
246
- end
247
- end
248
-
249
224
  def camelize(string)
250
225
  result = string.sub(/^[a-z\d]*/) { $&.capitalize }
251
226
  result.gsub(%r{(?:_|(/))([a-z\d]*)}) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" }
@@ -1,3 +1,3 @@
1
1
  module Raygun
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -0,0 +1,41 @@
1
+ require_relative "../spec_helper"
2
+ require_relative "../../lib/raygun/c5_conventions"
3
+
4
+ require "tmpdir"
5
+
6
+ describe Raygun::C5Conventions do
7
+ subject(:install) { described_class.install(target: target, sources: sources) }
8
+
9
+ let(:target) { Dir.mktmpdir }
10
+ let(:sources) { described_class::SOURCES }
11
+
12
+ describe ".install" do
13
+ it "puts rubocop files into the target directory" do
14
+ install
15
+
16
+ paths = %w[
17
+ .rubocop.yml
18
+ .rubocop-common.yml
19
+ .rubocop-performance.yml
20
+ .rubocop-rails.yml
21
+ .rubocop-rspec.yml
22
+ ].map { |path| Pathname.new(File.join(target, path)) }
23
+
24
+ expect(paths).to all(be_file)
25
+ end
26
+
27
+ it "inserts an attribution header" do
28
+ install
29
+ rubocop_config = IO.read(File.join(target, ".rubocop.yml"))
30
+ expect(rubocop_config).to match(%r{^# Sourced from carbonfive/c5-conventions @ \h{7}$})
31
+ end
32
+ end
33
+
34
+ context "when a source doesn't exist" do
35
+ let(:sources) { ["https://raw.githubusercontent.com/carbonfive/c5-conventions/main/rubocop/.rubocop-whatever.yml"] }
36
+
37
+ it "prints a warning to stdout" do
38
+ expect { install }.to output(/Failed to install/).to_stdout
39
+ end
40
+ end
41
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raygun
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Nelson
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-01-12 00:00:00.000000000 Z
13
+ date: 2021-05-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -90,12 +90,13 @@ files:
90
90
  - bin/raygun
91
91
  - bin/setup
92
92
  - lib/colorize.rb
93
+ - lib/raygun/c5_conventions.rb
93
94
  - lib/raygun/raygun.rb
94
95
  - lib/raygun/template_repo.rb
95
96
  - lib/raygun/version.rb
96
97
  - marvin.jpg
97
98
  - raygun.gemspec
98
- - spec/raygun/runner_spec.rb
99
+ - spec/raygun/c5_conventions_spec.rb
99
100
  - spec/spec_helper.rb
100
101
  homepage: https://github.com/carbonfive/raygun
101
102
  licenses:
@@ -116,11 +117,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
117
  - !ruby/object:Gem::Version
117
118
  version: '0'
118
119
  requirements: []
119
- rubygems_version: 3.1.4
120
+ rubygems_version: 3.2.2
120
121
  signing_key:
121
122
  specification_version: 4
122
123
  summary: Generates and customizes Rails applications with Carbon Five best practices
123
124
  baked in.
124
125
  test_files:
125
- - spec/raygun/runner_spec.rb
126
+ - spec/raygun/c5_conventions_spec.rb
126
127
  - spec/spec_helper.rb
@@ -1,27 +0,0 @@
1
- require_relative "../spec_helper"
2
- require_relative "../../lib/raygun/raygun"
3
-
4
- describe Raygun::Runner do
5
- describe "#fetch_rubocop_file" do
6
- context "the repo is the standard carbonfive raygun-rails repo" do
7
- before do
8
- @runner = described_class.new("target/dir", "carbonfive/raygun-rails")
9
- allow(URI).to receive(:open).and_return(StringIO.new("# rubocop contents"))
10
- allow(IO).to receive(:write)
11
- allow(@runner).to receive(:shell).and_return("GitSHAgoeshere")
12
- end
13
- it "inserts a copy of the rubocop file pulled from the carbonfive/c5-conventions repo" do
14
- @runner.send(:fetch_rubocop_file)
15
- expect(@runner).to have_received(:shell)
16
- .with("git ls-remote https://github.com/carbonfive/c5-conventions master")
17
- expect(URI).to have_received(:open)
18
- .with("https://raw.githubusercontent.com/carbonfive/c5-conventions/master/rubocop/rubocop.yml")
19
- expect(IO).to have_received(:write) do |path, contents|
20
- expect(path).to eq(File.absolute_path("target/dir/.rubocop.yml"))
21
- expect(contents).to include("@ GitSHA")
22
- expect(contents).to include("# rubocop contents")
23
- end
24
- end
25
- end
26
- end
27
- end