more breakout for feature
This commit is contained in:
15
bin/feature
15
bin/feature
@@ -1,17 +1,6 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
require_relative '../lib/feature/start'
|
require_relative '../lib/feature/commander'
|
||||||
require_relative '../lib/feature/end'
|
|
||||||
require_relative '../lib/feature/rebase'
|
|
||||||
require_relative '../lib/feature/merge_to'
|
|
||||||
require_relative '../lib/feature/branch'
|
|
||||||
|
|
||||||
command = case ARGV[0]
|
|
||||||
when "start" then Feature::Start.new(ARGV)
|
|
||||||
when "end" then Feature::End.new(ARGV)
|
|
||||||
when "rebase" then Feature::Rebase.new(ARGV)
|
|
||||||
when "merge" then Feature::MergeTo.new(ARGV)
|
|
||||||
else Feature::Branch.new(ARGV)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
command = Feature::Commander.new(ARGV)
|
||||||
command.execute
|
command.execute
|
||||||
|
|||||||
@@ -1,54 +1,18 @@
|
|||||||
|
require_relative '../shared/branchability'
|
||||||
|
require_relative '../shared/runnable'
|
||||||
|
|
||||||
module Feature
|
module Feature
|
||||||
|
|
||||||
class Base
|
class Base
|
||||||
|
|
||||||
|
include Shared::Branchability
|
||||||
|
include Shared::Runnable
|
||||||
|
|
||||||
attr_reader :argv
|
attr_reader :argv
|
||||||
|
|
||||||
def initialize (argv)
|
def initialize (argv)
|
||||||
@argv = argv
|
@argv = argv
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_cmd ( cmd, fallback_branch = current_branch )
|
|
||||||
puts
|
|
||||||
puts cmd
|
|
||||||
success = system cmd
|
|
||||||
unless success
|
|
||||||
system "git checkout #{fallback_branch}"
|
|
||||||
error "(see above)"
|
|
||||||
end
|
|
||||||
puts
|
|
||||||
end
|
|
||||||
|
|
||||||
def current_branch
|
|
||||||
@current_branch ||= `git branch|grep '\*'|sed 's/\*\s*//'`.strip
|
|
||||||
end
|
|
||||||
|
|
||||||
def remote_branch (branch)
|
|
||||||
@remote_branch ||= `git branch -r|grep origin|grep -v 'HEAD'|grep #{branch}`.strip
|
|
||||||
end
|
|
||||||
|
|
||||||
def standard_branches
|
|
||||||
['master','develop','integration']
|
|
||||||
end
|
|
||||||
|
|
||||||
def parse_branch (branch)
|
|
||||||
parts = branch.split('-')
|
|
||||||
error "invalid branch: user-standard-feature" unless parts.size > 2
|
|
||||||
|
|
||||||
user = parts.shift
|
|
||||||
standard = parts.shift
|
|
||||||
error "invalid user: #{user}" unless ENV['USER'] == user
|
|
||||||
error "invalid branch: #{standard}" unless standard_branches.include? standard
|
|
||||||
feature = parts.join('-')
|
|
||||||
{ user: user, standard: standard, feature: feature }
|
|
||||||
end
|
|
||||||
|
|
||||||
def error ( msg )
|
|
||||||
puts
|
|
||||||
puts "ERROR: #{msg}"
|
|
||||||
puts
|
|
||||||
exit
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
29
lib/feature/commander.rb
Normal file
29
lib/feature/commander.rb
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
require_relative './start'
|
||||||
|
require_relative './end'
|
||||||
|
require_relative './rebase'
|
||||||
|
require_relative './merge_to'
|
||||||
|
require_relative './branch'
|
||||||
|
|
||||||
|
module Feature
|
||||||
|
|
||||||
|
class Commander
|
||||||
|
attr_reader :argv
|
||||||
|
|
||||||
|
def initialize (argv)
|
||||||
|
@argv = argv
|
||||||
|
end
|
||||||
|
|
||||||
|
def execute
|
||||||
|
command = case argv[0]
|
||||||
|
when "start" then Feature::Start.new(argv)
|
||||||
|
when "end" then Feature::End.new(argv)
|
||||||
|
when "rebase" then Feature::Rebase.new(argv)
|
||||||
|
when "merge" then Feature::MergeTo.new(argv)
|
||||||
|
else Feature::Branch.new(argv)
|
||||||
|
end
|
||||||
|
command.execute
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
29
lib/shared/branchability.rb
Normal file
29
lib/shared/branchability.rb
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
module Shared
|
||||||
|
|
||||||
|
module Branchability
|
||||||
|
def current_branch
|
||||||
|
@current_branch ||= `git branch|grep '\*'|sed 's/\*\s*//'`.strip
|
||||||
|
end
|
||||||
|
|
||||||
|
def remote_branch (branch)
|
||||||
|
@remote_branch ||= `git branch -r|grep origin|grep -v 'HEAD'|grep #{branch}`.strip
|
||||||
|
end
|
||||||
|
|
||||||
|
def standard_branches
|
||||||
|
['master','develop','integration']
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_branch (branch)
|
||||||
|
parts = branch.split('-')
|
||||||
|
error "invalid branch: user-standard-feature" unless parts.size > 2
|
||||||
|
|
||||||
|
user = parts.shift
|
||||||
|
standard = parts.shift
|
||||||
|
error "invalid user: #{user}" unless ENV['USER'] == user
|
||||||
|
error "invalid branch: #{standard}" unless standard_branches.include? standard
|
||||||
|
feature = parts.join('-')
|
||||||
|
{ user: user, standard: standard, feature: feature }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
23
lib/shared/runnable.rb
Normal file
23
lib/shared/runnable.rb
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
module Shared
|
||||||
|
|
||||||
|
module Runnable
|
||||||
|
def run_cmd ( cmd, fallback_branch = current_branch )
|
||||||
|
puts
|
||||||
|
puts cmd
|
||||||
|
success = system cmd
|
||||||
|
unless success
|
||||||
|
system "git checkout #{fallback_branch}"
|
||||||
|
error "(see above)"
|
||||||
|
end
|
||||||
|
puts
|
||||||
|
end
|
||||||
|
|
||||||
|
def error ( msg )
|
||||||
|
puts
|
||||||
|
puts "ERROR: #{msg}"
|
||||||
|
puts
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user