ora-dev-tools 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.5
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem "simplecov"
5
+ gem "codeclimate-test-reporter", "~> 1.0.0"
6
+ end
7
+
8
+ # Specify your gem's dependencies in devtools.gemspec
9
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Donovan Young
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ [![Build Status](https://travis-ci.org/dyoung522/devtools.svg?branch=master)](https://travis-ci.org/dyoung522/devtools)
2
+ [![Code Climate](https://codeclimate.com/github/dyoung522/devtools/badges/gpa.svg)](https://codeclimate.com/github/dyoung522/devtools)
3
+ [![Test Coverage](https://codeclimate.com/github/dyoung522/devtools/badges/coverage.svg)](https://codeclimate.com/github/dyoung522/devtools/coverage)
4
+
5
+ # DevTools
6
+
7
+ DevTools is a compilation of utilities created to make the development process easier.
8
+
9
+ ## Installation
10
+
11
+ Install it from the command line
12
+
13
+ $ gem install ora-dev-tools
14
+
15
+ ## Usage
16
+
17
+ Once installed, this gem provides several, mostly independent, utilities
18
+
19
+ - `runtest` : Runs test suites with an optional search pattern
20
+ - `jdiff` t co: Compares two git branches and shows a diff of JIRA stories
21
+ - `prlist` : Polls git repos and displays a queue of stories ready for QA
22
+
23
+ Future Development
24
+
25
+ - RunEnv : Starts and manages a development environment
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`.
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on [our GitHub page](https://github.com/dyoung522/devtools)
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
40
+
@@ -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,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "devtools"
5
+ require "runtest"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "pry"
15
+ Pry.start
16
+
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "devtools/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ora-dev-tools"
8
+ spec.version = DevTools::VERSION
9
+ spec.authors = ["Donovan Young"]
10
+ spec.email = ["dyoung522@gmail.com"]
11
+
12
+ spec.summary = %q{Miscellaneous utilities to make a developers life easier}
13
+ spec.description = %q{Utilities include:\nRunTest - Runs specs based on local configuration} +
14
+ %q{\nRunEnv - Run the dev environment based on local configuration} +
15
+ %q{\nPRlist - Polls git repos and displays a queue of stories ready for QA}
16
+ spec.homepage = "https://github.com/dyoung522/devtools"
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "config", "~> 1.3"
25
+ spec.add_dependency "octokit", "~> 4.0"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.13"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_development_dependency "pry", "~> 0.4"
31
+ spec.add_development_dependency "factory_girl", "~> 4.0"
32
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ lib = File.expand_path("../../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require "jira_diff"
6
+
7
+ JIRADiff.run!
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby -w
2
+ lib = File.expand_path("../../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require "pr_list"
6
+
7
+ module DevTools
8
+ module PRlist
9
+ begin
10
+ OptParse.parse(ARGV)
11
+ rescue RuntimeError
12
+ puts "Whoops!\n\n"
13
+
14
+ unless Options.token
15
+ puts "You didn't give us a GitHub token to authenticate with."
16
+ end
17
+
18
+ if Options.repos.nil? || Options.repos.empty?
19
+ puts "You didn't give us any GitHub repos to work with."
20
+ end
21
+
22
+ puts "\nThe easiest way to provide required information is to create a ./#{DevTools::PROGRAM}.conf file with the following content..."
23
+ puts "\ntoken: <GITHUB-TOKEN-SHA>\nrepos:\n - repo-name-1\n - repo-name-2"
24
+ exit 1
25
+ end
26
+
27
+ pull_requests = PullRequests.new Options.token, Options.repos
28
+
29
+ puts "QA Queue for #{pull_requests.repos.join(", ")}\n\n" if Options.verbose > 0
30
+
31
+ pull_requests.by_date do |pr|
32
+ next unless pr.has_label?(OptParse.label_values) if Options.queue
33
+
34
+ printf "%sPR #%s (%s) %s",
35
+ Options.markdown ? "- " : "",
36
+ Options.markdown ? "[#{pr.number}](#{pr.pull_request.html_url})" : pr.number,
37
+ Options.verbose > 1 ? pr.repo : pr.repo(short: true),
38
+ pr.title
39
+ printf " (labels: %s)", pr.labels.join(", ") if Options.verbose > 2
40
+ puts
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env ruby
2
+ lib = File.expand_path("../../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require "devtools"
6
+ require "runtest"
7
+ require "find"
8
+ require "pp"
9
+
10
+ module RunTest
11
+ def self.run_command(command)
12
+ puts "COMMAND> #{command}" if Options.verbose >= 4
13
+ system command unless Options.dryrun
14
+ end
15
+
16
+ files = { jest: [], mocha: [], diff: [] }
17
+
18
+ RunTest::OptParse.parse(ARGV)
19
+
20
+ pp Options if Options.verbose >= 5
21
+
22
+ if Options.changed
23
+ files[:diff] = %x(#{Options.commands.diff}).split("\n").collect do |f|
24
+ f =~ /-spec/ ? File.basename(f, ".js") : "#{File.basename(f, ".js")}-spec"
25
+ end.uniq.compact
26
+
27
+ DevTools::Utils.die "No modified spec files found" if files[:diff].empty? && ARGV.empty?
28
+ end
29
+
30
+ if !files[:diff].empty? || ARGV.length > 0
31
+ [files[:diff], ARGV].flatten.compact.uniq.each do |arg|
32
+ found = false
33
+
34
+ puts "looking for tests matching \"#{arg}\"" if Options.verbose > 1
35
+
36
+ Find.find(Options.basedir) do |path|
37
+ if FileTest.directory?(path)
38
+ if File.basename(path)[0] == ?.
39
+ Find.prune # Don't look any further into this directory.
40
+ else
41
+ next
42
+ end
43
+ else
44
+ if path =~ /_*(spec|test)s?_*\/.*#{arg}.*/
45
+ files[$1 =~ /test/ ? :jest : :mocha].push path
46
+ found = true
47
+ end
48
+ end
49
+ end
50
+
51
+ puts "No tests found matching #{arg}" unless found
52
+ end
53
+
54
+ [:jest, :mocha].each do |suite|
55
+ next unless Options[suite]
56
+
57
+ if files[suite].length > 0
58
+ if Options.verbose > 2
59
+ puts "\nRunning #{suite.capitalize} on..."
60
+ puts " #{files[suite].join("\n ")}\n\n"
61
+ else
62
+ puts "\nRunning #{files[suite].length} #{suite.capitalize} test(s)" if Options.verbose > 0
63
+ end
64
+
65
+ run_command "#{Options.commands[suite]} #{files[suite].join(" ")}"
66
+ end
67
+ end
68
+
69
+ exit files[:jest].length > 0 || files[:mocha].length > 0 ? 0 : 1
70
+
71
+ else
72
+ [:jest, :mocha].each do |suite|
73
+ if Options[suite]
74
+ puts "Running full #{suite.capitalize} test suite" if Options.verbose > 0
75
+ run_command Options.commands[suite.to_s + "_full"]
76
+ end
77
+ end
78
+ end
79
+ end # module RunTest
80
+
@@ -0,0 +1,3 @@
1
+ require "devtools/options"
2
+ require "devtools/utils"
3
+ require "devtools/version"
@@ -0,0 +1,81 @@
1
+ require "config"
2
+ require "optparse"
3
+ require "ostruct"
4
+ require "pp"
5
+
6
+ module DevTools
7
+ class OptParse
8
+ attr_reader :parser, :version
9
+
10
+ def initialize(opts)
11
+ program_path = DevTools::PROGRAM
12
+ program_files = []
13
+
14
+ %W(~/.#{program_path} ./.#{program_path} ./#{program_path}.conf ./#{program_path}.rc).each do |path|
15
+ program_files.push File.expand_path(path)
16
+ end
17
+
18
+ Config.setup do |config|
19
+ config.const_name = 'Options'
20
+ config.use_env = true
21
+ end
22
+
23
+ Config.load_and_set_settings opts[:testing] ? String.new : program_files
24
+
25
+ default_options(Options, opts[:defaults]) if opts[:defaults]
26
+
27
+ Options.verbose = Options.verbose ? 1 : 0 unless Options.verbose.is_a?(Numeric)
28
+ Options.debug = true if Options.verbose >= 5
29
+
30
+ @parser ||= common_options opts[:testing]
31
+ @version ||= sprintf "%s v%s (%s v%s)\n",
32
+ opts[:name] || DevTools::PROGRAM, opts[:version] || DevTools::VERSION,
33
+ "DevTools", DevTools::VERSION
34
+ end
35
+
36
+ def common_options(unit_testing = false)
37
+ OptionParser.new do |opts|
38
+ opts.on_tail("-h", "--help", "Show this message") do
39
+ unless unit_testing
40
+ puts version + "\n"
41
+ puts opts
42
+ exit
43
+ end
44
+ end
45
+
46
+ # Config file
47
+ opts.on_tail("-c", "--config FILE", "Specify an alternate configuration file") do |file|
48
+ Options.add_source! file
49
+ Options.reload!
50
+ end
51
+
52
+ # dry-run switch
53
+ opts.on_tail("--dry-run", "Don't actually run commands") do
54
+ Options.dryrun = true
55
+ end
56
+
57
+ # Verbose switch
58
+ opts.on_tail("-q", "--quiet", "Run quietly") do
59
+ Options.verbose = 0
60
+ end
61
+
62
+ opts.on_tail("-v", "--verbose", "Run verbosely (may be specified more than once)") do
63
+ Options.verbose += 1
64
+ end
65
+
66
+ opts.on_tail("--version", "Show version") do
67
+ unless unit_testing
68
+ puts version
69
+ exit
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ def default_options(options, opts)
76
+ opts.each do |key, value|
77
+ options[key] = value unless options.keys.include?(key)
78
+ end
79
+ end
80
+ end # class Option
81
+ end # module DevTools
@@ -0,0 +1,8 @@
1
+ module DevTools
2
+ module Utils
3
+ def self.die(message)
4
+ puts message
5
+ exit 1
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ module DevTools
2
+ PROGRAM = File.basename($0, ".rb")
3
+ VERSION = "1.2.1"
4
+ end
@@ -0,0 +1,43 @@
1
+ require "jira_diff/globals"
2
+ require "jira_diff/options"
3
+ require "jira_diff/stories"
4
+
5
+ module JIRADiff
6
+ def self.not_implemented(feature)
7
+ puts "Sorry, #{feature} has not yet been implemented"
8
+ exit 2
9
+ end
10
+
11
+ def self.run!
12
+ begin
13
+ opts = OptParse.parse ARGV
14
+ rescue => error
15
+ puts error
16
+ exit 1
17
+ end
18
+
19
+ puts opts.inspect if opts.debug
20
+
21
+ begin
22
+ puts 'Searching for stories...' if opts.verbose
23
+ stories = Stories.new(opts)
24
+ rescue RuntimeError => error
25
+ puts error
26
+ exit 1
27
+ end
28
+
29
+ if opts.verbose
30
+ puts "From #{stories.directory}"
31
+ puts "-> All stories from #{stories.source.join(', ')}"
32
+ puts "-> Which are not in #{stories.master}"
33
+ stories.diff.each do |story|
34
+ puts "%-120.120s" % story.to_s
35
+ end
36
+ else
37
+ puts stories.diff.shas
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+
@@ -0,0 +1,30 @@
1
+ require 'open3'
2
+
3
+ module JIRADiff
4
+ class Git
5
+
6
+ def initialize(dir = '.')
7
+ raise StandardError, "Directory '#{dir}' is not valid" unless Dir.exist?(dir)
8
+ raise RuntimeError, "Doesn't look like '#{dir}' is a Git repository" unless Dir.exist?(File.join(dir, '.git'))
9
+
10
+ @working_dir = dir
11
+ end
12
+
13
+ def log(branch)
14
+ raise RuntimeError, "Invalid branch: #{branch}" unless branch_valid? branch
15
+ run_command("\\git --no-pager log --no-merges --pretty='%H|%s' #{branch}")
16
+ end
17
+
18
+ def branch_valid?(branch)
19
+ run_command("\\git branch --list #{branch}")[0] =~ /#{branch}/
20
+ end
21
+
22
+ private
23
+
24
+ def run_command(cmd)
25
+ Open3.popen3(cmd, chdir: @working_dir) do |i, o, e, t|
26
+ o.read.split("\n")
27
+ end
28
+ end
29
+ end
30
+ end