startling 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.ruby-gemset +1 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +78 -0
  7. data/Rakefile +15 -0
  8. data/bin/start +5 -0
  9. data/lib/generators/startling/configuration_generator.rb +78 -0
  10. data/lib/startling.rb +30 -0
  11. data/lib/startling/cache.rb +20 -0
  12. data/lib/startling/cli_options.rb +46 -0
  13. data/lib/startling/colorize_string.rb +58 -0
  14. data/lib/startling/command.rb +67 -0
  15. data/lib/startling/commands/base.rb +83 -0
  16. data/lib/startling/commands/check_for_local_mods.rb +17 -0
  17. data/lib/startling/commands/create_branch.rb +53 -0
  18. data/lib/startling/commands/create_pull_request.rb +35 -0
  19. data/lib/startling/commands/label_pull_request.rb +15 -0
  20. data/lib/startling/configuration.rb +106 -0
  21. data/lib/startling/git_local.rb +61 -0
  22. data/lib/startling/github.rb +16 -0
  23. data/lib/startling/github/api.rb +106 -0
  24. data/lib/startling/github/pull_request.rb +54 -0
  25. data/lib/startling/github/repo.rb +44 -0
  26. data/lib/startling/handlers/default_pull_request_handler.rb +21 -0
  27. data/lib/startling/handlers/pull_request_handler_base.rb +21 -0
  28. data/lib/startling/markdown.rb +7 -0
  29. data/lib/startling/shell.rb +11 -0
  30. data/lib/startling/version.rb +3 -0
  31. data/spec/spec_helper.rb +19 -0
  32. data/spec/startling/commands/base_spec.rb +32 -0
  33. data/spec/startling/configuration_spec.rb +127 -0
  34. data/spec/startling/git_local_spec.rb +22 -0
  35. data/spec/startling/github/pull_request_spec.rb +37 -0
  36. data/spec/startling_configuration_spec.rb +16 -0
  37. data/spec/startling_spec.rb +122 -0
  38. data/spec/support/dotenv.rb +2 -0
  39. data/spec/support/tokens.rb +5 -0
  40. data/spec/support/vcr.rb +16 -0
  41. data/spec/vcr_cassettes/bin_start_starts_stories.yml +564 -0
  42. data/spec/vcr_cassettes/bin_start_starts_stories_pr_body.yml +644 -0
  43. data/startling.gemspec +36 -0
  44. metadata +297 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5d5a7dbbb13c70a2436e297e48f04e779ebf61b1
4
+ data.tar.gz: 2a646b11cc120532e165cef6aa7d542f26dc48ac
5
+ SHA512:
6
+ metadata.gz: 5fe2483c92aa1b83c263d2c2da8a6282862cd1872ed8d2e690104bd259a891a444c8629ab211a560dd88b8042515b78a697562100748bec9ba764b7a0cea88ae
7
+ data.tar.gz: 8ac53ad87a606d4a76a7b4b77378b5ec65d12daa62505be3b1f4226fa1348cf92cfd39dfba4b8f9d866c1e7ef60f8a21acabce256a198564ccd247186936aa34
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .env
6
+ .github_access_token
7
+ .pivotal_api_token
8
+ .ruby-version
9
+ .yardoc
10
+ Gemfile.lock
11
+ InstalledFiles
12
+ _yardoc
13
+ coverage
14
+ doc/
15
+ lib/bundler/man
16
+ pkg
17
+ rdoc
18
+ spec/reports
19
+ test/tmp
20
+ test/version_tmp
21
+ tmp
@@ -0,0 +1 @@
1
+ teaching-channel_start
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in startling.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Shaun Dern
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,78 @@
1
+ # Startling
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ gem 'startling'
8
+
9
+ And then execute:
10
+
11
+ $ bundle
12
+
13
+ Or install it yourself as:
14
+
15
+ $ gem install startling
16
+
17
+ Generate configuration file in rails.
18
+ Use -H to generate a handler folder and -C to generate a commands folder
19
+
20
+ $ rails g startling:configuration
21
+
22
+ ## Configuration
23
+
24
+ Startlingfile.rb or startlingfile.rb should be defined in the root of the project. It can contain a block for configuration:
25
+
26
+ ```ruby
27
+ Startling.configure do |config|
28
+ # WIP Limit
29
+ # config.wip_limit = 4
30
+
31
+ # Repos to check against for WIP limit
32
+ # config.repos << 'substantial/startling-dev'
33
+
34
+ # Valid story estimations
35
+ # config.valid_estimates = [1, 2, 4, 8, 16, 32, 64, 128]
36
+
37
+ # Commands to be run before a story is stared
38
+ # config.hook_commands.before_story_start = [:check_wip]
39
+
40
+ # Command to be run after a story has started
41
+ # config.hook_commands.after_story_start = []
42
+
43
+ # Commands to be run before a pull request is created
44
+ # config.hook_commands.before_pull_request = []
45
+
46
+ # Commands to be run after a pull request is created
47
+ # config.hook_commands.after_pull_request = []
48
+
49
+ # Handler used to start a provider specific story related to the pull request
50
+ config.story_handler = :pivotal_start
51
+
52
+ # Message for pull request commit
53
+ # config.pull_request_commit_message = "Startling"
54
+
55
+ # Labels for a pull request
56
+ # config.pull_request_labels = [WIP, REVIEW, HOLD]
57
+
58
+ # Handler used for setting the title and body of a pull request
59
+ #config.pull_request_handler = :custom_pull_request_handler
60
+ end
61
+ ```
62
+
63
+ ## Usage
64
+
65
+ Start a new story with a given story id
66
+
67
+ $ start 12345
68
+
69
+ Start a new story with a given story id and branch name
70
+
71
+ $ start 12345 foo
72
+
73
+ TODO: Write usage instructions here
74
+
75
+ ## Contributing
76
+
77
+ 1. Create `.env` from the Secure Note `startling .env` in
78
+ LastPass.
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'bundler/gem_tasks'
6
+ require 'rspec/core/rake_task'
7
+
8
+ desc 'Default: run unit tests.'
9
+ task :default => :spec
10
+
11
+ desc "Run all specs"
12
+ RSpec::Core::RakeTask.new do |t|
13
+ t.pattern = 'spec/**/*_spec.rb'
14
+ t.rspec_opts = '--color'
15
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/startling'
4
+
5
+ Startling::Command.run
@@ -0,0 +1,78 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/base'
3
+
4
+ module Startling
5
+ module Generators
6
+ class ConfigurationGenerator < Rails::Generators::Base
7
+ class_option :handlers,
8
+ {
9
+ type: :boolean,
10
+ aliases: "-H",
11
+ desc: "Generate handlers folder"
12
+ }
13
+ class_option :commands,
14
+ {
15
+ type: :boolean,
16
+ aliases: "-C",
17
+ desc: "Generate commands folder"
18
+ }
19
+
20
+ def create_startling_folders
21
+ pull_request_handler_file = "#{destination_root.split('/').last.underscore}_pull_request_handler"
22
+ create_file "startlingfile.rb" do
23
+ <<CONFIG
24
+ Startling.configure do |config|
25
+ # WIP Limit
26
+ # config.wip_limit = 4
27
+
28
+ # Repos to check against for WIP limit
29
+ # config.repos << 'substantial/startling-dev'
30
+
31
+ # Valid story estimations
32
+ # config.valid_estimates = [1, 2, 4, 8, 16, 32, 64, 128]
33
+
34
+ # Commands to be run before a story is stared
35
+ # config.hook_commands.before_story_start = [:check_wip]
36
+
37
+ # Command to be run after a story has started
38
+ # config.hook_commands.after_story_start = []
39
+
40
+ # Commands to be run before a pull request is created
41
+ # config.hook_commands.before_pull_request = []
42
+
43
+ # Commands to be run after a pull request is created
44
+ # config.hook_commands.after_pull_request = []
45
+
46
+ # Handler used to start a provider specific story related to the pull request
47
+ # config.story_handler = :pivotal_start
48
+
49
+ # Message for pull request commit
50
+ # config.pull_request_commit_message = "Startling"
51
+
52
+ # Message for pull request body
53
+ # config.pull_request_body = "Startling Body"
54
+
55
+ # Labels for a pull request
56
+ # config.pull_request_labels = [WIP, REVIEW, HOLD]
57
+
58
+ # Handler used for setting the title and body of a pull request
59
+ #config.pull_request_handler = :#{pull_request_handler_file}
60
+ end
61
+ CONFIG
62
+ end
63
+
64
+ empty_directory "startling"
65
+ empty_directory "startling/commands" if options.commands?
66
+ if options.handlers?
67
+ empty_directory "startling/handlers"
68
+ create_file "startling/handlers/#{pull_request_handler_file}.rb" do
69
+ <<HANDLER_CLASS
70
+ class #{pull_request_handler_file.camelize} < Startling::Handlers::PullRequestHandlerBase
71
+ end
72
+ HANDLER_CLASS
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,30 @@
1
+ require 'startling/command'
2
+ require 'startling/cli_options'
3
+ require 'startling/cache'
4
+ require 'startling/configuration'
5
+
6
+ module Startling
7
+ class << self
8
+ attr_writer :configuration
9
+
10
+ def method_missing(method, *args, &block)
11
+ configuration.send(method, *args, &block)
12
+ end
13
+ end
14
+
15
+ def self.configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+
19
+ def self.configure
20
+ yield(configuration)
21
+ end
22
+
23
+ def self.reset
24
+ @configuration = Configuration.new
25
+ end
26
+
27
+ def self.cache
28
+ @cache ||= Cache.new(configuration.cache_dir)
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ module Startling
2
+ class Cache
3
+ attr_reader :cache_dir
4
+
5
+ def initialize(cache_dir)
6
+ @cache_dir = cache_dir
7
+ end
8
+
9
+ def fetch(path, &block)
10
+ path = File.join(cache_dir, path)
11
+ if File.exists? path
12
+ File.read path
13
+ else
14
+ block.call.tap do |value|
15
+ File.write path, value
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,46 @@
1
+ require "optparse"
2
+
3
+ module Startling
4
+ class CliOptions
5
+ USAGE = <<USE
6
+ Usage: start [options]
7
+
8
+ Example:
9
+
10
+ $ start 12345 my branch name
11
+ USE
12
+ def self.parse
13
+ options = {story_id: nil, branch_name: nil}
14
+ parser = OptionParser.new do |opts|
15
+ opts.banner = USAGE
16
+
17
+ opts.on('-s', '--story_id story_id', 'Story id') do |story_id|
18
+ options[:story_id] = story_id
19
+ end
20
+
21
+ opts.on('-b', '--branch branch', 'Branch name (Can be separated by spaces or dashes.)') do |branch|
22
+ options[:branch_name] = branch
23
+ end
24
+
25
+ Startling.cli_options.each do |user_opt|
26
+ options.merge!(user_opt.sym => nil)
27
+ opts.on(user_opt.abbr_switch, user_opt.long_switch, user_opt.description) do |value|
28
+ options[user_opt.sym] = value
29
+ end
30
+ end
31
+
32
+ opts.on('-h', '--help', 'Displays Help') do
33
+ puts opts
34
+ exit
35
+ end
36
+ end
37
+ begin
38
+ parser.parse!
39
+ rescue
40
+ puts parser.help
41
+ exit
42
+ end
43
+ options.merge!({args: ARGV})
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,58 @@
1
+ require 'paint'
2
+
3
+ # Refine the string class to have a interface similar to colored gem.
4
+
5
+ # Look @ https://github.com/janlelis/paint for a bunch of possible
6
+ # keywords
7
+
8
+ module Startling
9
+ module ColorizeString
10
+ refine String do
11
+ COLORS = %i[
12
+ black
13
+ blue
14
+ cyan
15
+ green
16
+ red
17
+ white
18
+ yellow
19
+ ]
20
+
21
+ EXTRAS = %i[
22
+ bold
23
+ bright
24
+ clean
25
+ conceal
26
+ hide
27
+ inverse
28
+ nothing
29
+ reset
30
+ underline
31
+ show
32
+ ]
33
+
34
+ COLORS.each do |color|
35
+ define_method(color) do
36
+ Paint[self, color]
37
+ end
38
+
39
+ define_method("on_#{color}") do
40
+ Paint[self, nil, color]
41
+ end
42
+
43
+ COLORS.each do |highlight|
44
+ next if color == highlight
45
+ define_method("#{color}_on_#{highlight}") do
46
+ Paint[self, color, highlight]
47
+ end
48
+ end
49
+ end
50
+
51
+ EXTRAS.each do|extra|
52
+ define_method(extra) do
53
+ Paint[self, extra]
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,67 @@
1
+ require 'cgi'
2
+ require 'json'
3
+ require 'highline/import'
4
+ require 'shellwords'
5
+ require_relative "commands/base"
6
+ require_relative 'commands/check_for_local_mods'
7
+ require_relative 'commands/create_pull_request'
8
+
9
+ module Startling
10
+ class Command < Commands::Base
11
+ RUN = "run"
12
+
13
+ def self.run(attrs={})
14
+ load_configuration
15
+
16
+ options = Startling::CliOptions.parse
17
+ options.merge!(attrs)
18
+ options.merge({argv: ARGV, args: ARGV})
19
+
20
+ load_commands
21
+ load_handlers
22
+ super(options)
23
+ end
24
+
25
+ def execute
26
+ Commands::CheckForLocalMods.run(git: git)
27
+ command_args = cli_options.merge(git: git)
28
+
29
+ # Before Start Story
30
+ Startling.hook_commands.before_story_start.map do |command|
31
+ command_class(command).send(RUN, command_args)
32
+ end
33
+
34
+ # Start story
35
+ story = command_class(Startling.story_handler)
36
+ .send(RUN, command_args) if Startling.story_handler
37
+ command_args.merge!(story: story)
38
+
39
+ # After Story Start
40
+ Startling.hook_commands.after_story_start.map do |command|
41
+ command_class(command)
42
+ .send(RUN, command_args)
43
+ end
44
+
45
+ #Before Pull Request Creation
46
+ Startling.hook_commands.before_pull_request.map do |command|
47
+ command_class(command)
48
+ .send(RUN, command_args)
49
+ end
50
+
51
+ # Create pull request
52
+ pull_request = command_class(:create_pull_request)
53
+ .send(RUN, command_args)
54
+ command_args.merge!(pull_request: pull_request)
55
+
56
+ # After Pull Request Creation
57
+ Startling.hook_commands.after_pull_request.map do |command|
58
+ command_class(command)
59
+ .send(RUN, command_args)
60
+ end
61
+ end
62
+
63
+ def git
64
+ @git ||= GitLocal.new
65
+ end
66
+ end
67
+ end