wagemage 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wagemage"
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(__FILE__)
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rake", "rake")
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Problem: I need a script with which I may test.
4
+ #
5
+ # Command to run:
6
+ #
7
+ # wagemage \
8
+ # --repo 'meowsus/wagemage' \
9
+ # --script examples/add_test_file
10
+
11
+ repo_path, repo_name, branch = ARGV
12
+
13
+ file_path = [repo_path, 'TEST.md'].join('/')
14
+
15
+ abort if File.exist?(file_path)
16
+
17
+ File.open(file_path, 'w') do |file|
18
+ file.write <<~CONTENT
19
+ # TEST
20
+
21
+ This is a test file. It serves no purpose other than to test.
22
+
23
+ It should be committed to the #{repo_name} repository and merged into the #{branch} branch.
24
+
25
+ And now we've reached the exciting conclusion of the file.
26
+ CONTENT
27
+ end
28
+
29
+ puts <<~COMMIT_MESSAGE
30
+ Add test file
31
+
32
+ We're adding a test file for testing purposes to the #{branch} branch.
33
+ COMMIT_MESSAGE
34
+
35
+ exit
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Problem: now that Workarea uses GitHub actions we are running out of minutes
4
+ # due to each plugin pushing a CHANGELOG commit and tags separately.
5
+ #
6
+ # This script should be used for plugins, only. Workarea's Rakefile and plugin
7
+ # template should be handled separately. This might not work on API since it,
8
+ # too, is a meta-gem.
9
+ #
10
+ # Refer to new hotness: https://stackoverflow.com/a/3745250
11
+ #
12
+ # Command to run:
13
+ #
14
+ # wagemage \
15
+ # --org workarea-commerce \
16
+ # --repo '^workarea-commerce/workarea-' \
17
+ # --branch '(-stable$|^master$)' \
18
+ # --script examples/consolidate_pushes_during_release \
19
+ # --reviewers bencrouse,mttdffy,tubbo,jyucis \
20
+ # --branch-prefix WORKAREA-148
21
+
22
+ repo_path = ARGV.first
23
+ rakefile_path = [repo_path, 'Rakefile'].join('/')
24
+
25
+ # Test to see if the Rakefile even exists in the first place
26
+ abort("No Rakefile") unless File.exist?(rakefile_path)
27
+
28
+ # Load Rakefile
29
+ rakefile = File.open(rakefile_path, 'r+')
30
+ rakefile_content = rakefile.read
31
+ rakefile.close
32
+
33
+ # Test for release task
34
+ abort("No release task") unless rakefile_content.include?('task :release')
35
+
36
+ # Uncomment Changelog generator while we're in there
37
+ rakefile_content.gsub!(/(\s+)#(Rake::Task|system)(.*changelog)/i, '\1\2\3')
38
+
39
+ # Remove offending initial push
40
+ rakefile_content.gsub!(/\s+#?system\s*['"]git push origin head['"].*/i, '')
41
+
42
+ # Replace extraneous tags push with new hotness
43
+ rakefile_content.gsub!(/git push --tags/i, 'git push origin HEAD --follow-tags')
44
+
45
+ # Write the file
46
+ rakefile = File.open(rakefile_path, 'w')
47
+ rakefile.write(rakefile_content)
48
+ rakefile.close
49
+
50
+ # Output the commit message
51
+ puts <<~COMMIT_MESSAGE
52
+ Remove extraneous push in Release task
53
+
54
+ We're running out of minutes in our GitHub actions due to duplicate pushes
55
+ during a release. This consolidates the two pushes into one.
56
+
57
+ No changelog
58
+
59
+ WORKAREA-148
60
+ COMMIT_MESSAGE
61
+
62
+ # Exit cleanly
63
+ exit
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'open3'
4
+
5
+ # Problem: During our upgrade to Rails 6 we found that Teaspoon wasn't
6
+ # compatable. As a result we disabled teaspoon tests across all of our builds.A
7
+ #
8
+ # Solution: Scan through each repo to find any teaspoon tests. If found, add
9
+ # the appropriate entry for the corresponding engine to ci.yml.
10
+ #
11
+ # Command to run:
12
+ #
13
+ # wagemage \
14
+ # --org workarea-commerce \
15
+ # --repo '^workarea-commerce/workarea-' \
16
+ # --branch '(-stable$|^master$)' \
17
+ # --script examples/enable_teaspoon_tests \
18
+ # --reviewers bencrouse,mttdffy,tubbo,jyucis \
19
+ # --branch-prefix WORKAREA-185
20
+
21
+ repo_path = ARGV.first
22
+ ci_file_path = [repo_path, '.github', 'workflows', 'ci.yml'].join('/')
23
+ rakefile_path = [repo_path, 'Rakefile'].join('/')
24
+
25
+ # See if there are no tests to run
26
+ tests = Dir["#{repo_path}/test/javascript*/**/*.js"]
27
+ abort('No tests') unless tests.any?
28
+
29
+ # Potential entry for ci.yml
30
+ ci_entry = <<-ENTRY
31
+
32
+ teaspoon:
33
+ runs-on: ubuntu-latest
34
+ steps:
35
+ - uses: actions/checkout@v1
36
+ - uses: actions/setup-ruby@v1
37
+ with:
38
+ ruby-version: 2.6.x
39
+ - uses: workarea-commerce/ci/test@v1
40
+ with:
41
+ command: bin/rails app:teaspoon
42
+ ENTRY
43
+
44
+ # Potential entry for rakefile
45
+ rakefile_entry = <<~ENTRY
46
+
47
+ desc "Run the JavaScript tests"
48
+ ENV["TEASPOON_RAILS_ENV"] = File.expand_path("../test/dummy/config/environment", __FILE__)
49
+ task teaspoon: "app:teaspoon"
50
+
51
+ desc "Start a server at http://localhost:3000/teaspoon for JavaScript tests"
52
+ task :teaspoon_server do
53
+ Dir.chdir("test/dummy")
54
+ teaspoon_env = File.expand_path("../test/teaspoon_env.rb", __FILE__)
55
+ system "RAILS_ENV=test TEASPOON_ENV=#\{teaspoon_env\} rails s"
56
+ end
57
+ ENTRY
58
+
59
+ # Write to ci.yml if no reference to teaspoon is found
60
+ ci_file = File.open(ci_file_path, 'a+')
61
+ ci_file.write(ci_entry) unless ci_file.read =~ /teaspoon/
62
+ ci_file.close
63
+
64
+ # Write to Rakefile if no reference to teaspoon is found
65
+ rakefile = File.open(rakefile_path, 'a+')
66
+ rakefile.write(rakefile_entry) unless rakefile.read =~ /teaspoon/
67
+ rakefile.close
68
+
69
+ # Check to see if any changes were made
70
+ stdout, _ = Open3.capture3('git status', chdir: repo_path)
71
+ abort("No changes made") if stdout =~ /nothing to commit/
72
+
73
+ # Output commit message
74
+ puts <<~COMMIT_MESSAGE
75
+ Enable Teaspoon in CI
76
+
77
+ No changelog
78
+
79
+ WORKAREA-185
80
+ COMMIT_MESSAGE
81
+
82
+ # Exit cleanly
83
+ exit
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Problem: a test failure in the workarea-reviews plugin had eluded us for quite
4
+ # a while. During the hustle-n-bustle of the plugin updates at the end of the
5
+ # last minor release, the theme plugins just decorated the test. Now that the
6
+ # test has been fixed we need to obtain a list of plugins that have decorated
7
+ # this test so that we can go and manually edit them.
8
+ #
9
+ # Adds a file to `/tmp/decorated_tests.log` FYI.
10
+ #
11
+ # Command to run:
12
+ #
13
+ # wagemage \
14
+ # --org workarea-commerce \
15
+ # --repo '-theme$' \
16
+ # --branch '(-stable$|^master$)' \
17
+ # --script examples/find_decorated_test \
18
+ # --debug
19
+
20
+ repo_path, repo_name, branch = ARGV
21
+ logfile = File.open("/tmp/decorated_tests.log", 'a')
22
+
23
+ decorated_files = Dir[[repo_path, '**/reviews_helper_test.decorator'].join('/')]
24
+
25
+ if decorated_files.empty?
26
+ logfile.close
27
+ abort("File not found in #{repo_path}")
28
+ end
29
+
30
+ file_content = "in: #{repo_name}:#{branch}\n"
31
+
32
+ logfile.write(file_content)
33
+ logfile.close
34
+
35
+ exit
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Problem: Teaspoon isn't ready for Rails 6 and we're brainstorming solutions.
4
+ # We need to know what plugins even have teaspoon tests written for them.
5
+ #
6
+ # Adds a file at `/tmp/javascript_tests_in_plugins.log` FYI.
7
+ #
8
+ # Command to run:
9
+ #
10
+ # wagemage \
11
+ # --org workarea-commerce \
12
+ # --repo '^workarea-commerce/workarea-' \
13
+ # --branch '(-stable$|^master$)' \
14
+ # --script examples/find_teaspoon_tests \
15
+ # --debug
16
+
17
+ repo_path, repo_name, branch = ARGV
18
+ logfile = File.open("/tmp/javascript_tests_in_plugins.log", 'a')
19
+
20
+ test_files = Dir[[repo_path, 'test/javascripts/**/*.js'].join('/')]
21
+
22
+ if test_files.empty?
23
+ logfile.close
24
+ abort("Teaspoon tests not found in #{repo_path}")
25
+ end
26
+
27
+ file_content = "Teaspoon tests found in: #{repo_name}:#{branch}\n"
28
+
29
+ logfile.write(file_content)
30
+ logfile.close
31
+
32
+ exit
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Problem: after inheriting our rubocop configuration from the base workarea
4
+ # gem a file is downloaded to the repo each time Rubocop is run. This is a pain
5
+ # during a release because my editor will automatically run Rubocop each time
6
+ # a Ruby file is opened
7
+ #
8
+ # Solution: Check .gitignore for the presence of `.rubocop-http`. If it doesn't
9
+ # exist append `.rubocop-http*` to the end of the file.
10
+ #
11
+ # Command to run:
12
+ #
13
+ # wagemage \
14
+ # --org workarea-commerce \
15
+ # --repo '^workarea-commerce/workarea-' \
16
+ # --branch '(-stable$|^master$)' \
17
+ # --script examples/ignore_remote_rubocop_config \
18
+ # --reviewers bencrouse
19
+
20
+ repo_path = ARGV.first
21
+ gitignore_path = [repo_path, '.gitignore'].join('/')
22
+
23
+ # Test to see if the .gitignore even exists in the first place
24
+ abort("No Gitignore") unless File.exist?(gitignore_path)
25
+
26
+ # Load Gitignore content
27
+ gitignore = File.open(gitignore_path, 'r+')
28
+ gitignore_content = gitignore.read
29
+ gitignore.close
30
+
31
+ # Test for `.rubocop-http` entry
32
+ if gitignore_content.include?('.rubocop-http')
33
+ abort("Already ignoring remote config")
34
+ end
35
+
36
+ gitignore = File.open(gitignore_path, 'a')
37
+ gitignore.write '.rubocop-http*'
38
+ gitignore.close
39
+
40
+ # Output the commit message
41
+ puts <<~COMMIT_MESSAGE
42
+ Ignore remote Rubocop config
43
+
44
+ No changelog
45
+ COMMIT_MESSAGE
46
+
47
+ # Exit cleanly
48
+ exit
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+
5
+ TICKETS = {
6
+ 'workarea-commerce/workarea-address-verification' => 'WEBADDVER-4',
7
+ 'workarea-commerce/workarea-stripe' => 'STRIPE-2',
8
+ 'workarea-commerce/workarea-quotes' => 'QUOTES-3',
9
+ 'workarea-commerce/workarea-oms' => 'OMS-5',
10
+ # 'workarea-commerce/workarea-global-e' => 'GLOBALE-3',
11
+ 'workarea-commerce/workarea-gift-cards' => 'GIFTCARDS-6',
12
+ 'workarea-commerce/workarea-forter' => 'FORTER-2',
13
+ 'workarea-commerce/workarea-bopus' => 'BOPUS-3',
14
+ 'workarea-commerce/workarea-payware-connect' => 'PAYWARE-1'
15
+ }
16
+
17
+ path, repo, _branch = ARGV
18
+ plugin = Pathname.new(path)
19
+ ticket = TICKETS[repo]
20
+ @changed = false
21
+
22
+ plugin.glob('test/**/*.{rb,decorator}').each do |test|
23
+ fixed = test.read.to_s.gsub(/2020,/, 'next_year,')
24
+ .gsub(/'2020'/, 'next_year.to_s')
25
+ .gsub(/"2020",/, 'next_year.to_s,')
26
+ @changed = fixed != test.read.to_s
27
+
28
+ test.write(fixed)
29
+ end
30
+
31
+ gemfile = plugin.join('Gemfile')
32
+ gemfile.write(gemfile.read.to_s.gsub(/:master/, "'v3.5-stable'"))
33
+
34
+ STDERR.puts "Ticket Not Found For Repo '#{repo}'" if ticket.nil? && @changed
35
+
36
+ puts <<~COMMIT_MESSAGE
37
+ Fix Tests for 2020
38
+
39
+ Update all tests so that they no longer depend on the year 2020 as an
40
+ expiration year. Instead, use the `next_year` method provided by Workarea.
41
+
42
+ #{ticket}
43
+ COMMIT_MESSAGE
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path("../lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'wagemage'
7
+
8
+ cli = Wagemage::CLI.new(ARGV)
9
+ cli.run
@@ -0,0 +1,31 @@
1
+ require 'tmpdir'
2
+ require 'open3'
3
+ require 'pathname'
4
+
5
+ require 'slop'
6
+ require 'colorize'
7
+ require 'octokit'
8
+
9
+ module Slop
10
+ class PathOption < Option
11
+ def call(value)
12
+ Pathname.new(value)
13
+ end
14
+ end
15
+ end
16
+
17
+ Octokit.configure do |c|
18
+ c.auto_paginate = true
19
+ end
20
+
21
+ require 'wagemage/version'
22
+ require 'wagemage/helpers'
23
+ require 'wagemage/cli'
24
+ require 'wagemage/repo'
25
+
26
+ module Wagemage
27
+ class Error < StandardError; end
28
+ class OptionError < Slop::MissingRequiredOption; end
29
+
30
+ extend Helpers
31
+ end