git_scf 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -0
- data/bin/git-scf +10 -0
- data/lib/git_scf/env_config.rb +10 -0
- data/lib/git_scf/jira.rb +18 -0
- data/lib/git_scf/logger.rb +19 -0
- data/lib/git_scf/subcommands/finish.rb +16 -0
- data/lib/git_scf/subcommands/review.rb +16 -0
- data/lib/git_scf/subcommands/show.rb +21 -0
- data/lib/git_scf/subcommands/start.rb +17 -0
- data/lib/git_scf/subcommands.rb +5 -0
- data/lib/git_scf/ticket.rb +53 -0
- data/lib/git_scf/version.rb +3 -0
- data/lib/git_scf.rb +66 -0
- metadata +122 -0
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
TODO
|
data/bin/git-scf
ADDED
data/lib/git_scf/jira.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class Jira
|
2
|
+
require 'jira'
|
3
|
+
|
4
|
+
def initialize(config)
|
5
|
+
options = { username: config.get('JIRA_USERNAME'),
|
6
|
+
password: config.get('JIRA_PASSWORD'),
|
7
|
+
use_ssl: true,
|
8
|
+
site: 'https://seeclickfix.atlassian.net',
|
9
|
+
context_path: '/',
|
10
|
+
rest_base_path: 'rest/api/2',
|
11
|
+
auth_type: :basic }
|
12
|
+
@jira = JIRA::Client.new(options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def ticket(id)
|
16
|
+
@jira.Issue.find(id)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Logger
|
2
|
+
|
3
|
+
LOG_PATH = 'script/scfgit'
|
4
|
+
LOG_FILE = 'log'
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
`mkdir -p #{LOG_PATH}`
|
8
|
+
end
|
9
|
+
|
10
|
+
def add(string)
|
11
|
+
`echo '#{string} #{`date`}' >> #{log_file}`
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def log_file
|
17
|
+
"#{LOG_PATH}/#{LOG_FILE}"
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Finish
|
2
|
+
def initialize(ticket, logger)
|
3
|
+
@ticket = ticket
|
4
|
+
@logger = logger
|
5
|
+
end
|
6
|
+
|
7
|
+
def execute
|
8
|
+
@logger.add("Closing out #{@ticket.branch_name}")
|
9
|
+
`git add .`
|
10
|
+
`git commit -am "#{@ticket.id} #done"`
|
11
|
+
`git push`
|
12
|
+
`git flow feature finish #{@ticket.branch_name}`
|
13
|
+
`git push`
|
14
|
+
`git push origin :refs/heads/feature/#{@ticket.branch_name}`
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Review
|
2
|
+
|
3
|
+
def initialize(ticket, logger)
|
4
|
+
@ticket = ticket
|
5
|
+
@logger = logger
|
6
|
+
end
|
7
|
+
|
8
|
+
def execute
|
9
|
+
@logger.add("Reviewing #{@ticket.branch_name}")
|
10
|
+
`git add .`
|
11
|
+
`git commit -am "#{@ticket.id} #review"`
|
12
|
+
`git push`
|
13
|
+
`hub pull-request "Addresses #{@ticket.id} please review." | pbcopy`
|
14
|
+
puts "The code-review URL is in your clipboard."
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Show
|
2
|
+
|
3
|
+
def initialize(ticket, verbose)
|
4
|
+
@ticket = ticket
|
5
|
+
@verbose = verbose
|
6
|
+
end
|
7
|
+
|
8
|
+
def execute
|
9
|
+
jira_ticket = @ticket.jira_ticket
|
10
|
+
puts "Summary: #{jira_ticket.summary}"
|
11
|
+
puts "Status: #{jira_ticket.status.name}"
|
12
|
+
puts "Created at: #{jira_ticket.created}"
|
13
|
+
if @verbose
|
14
|
+
puts "Description: #{jira_ticket.description}"
|
15
|
+
jira_ticket.comments.each do |comment|
|
16
|
+
puts ""
|
17
|
+
puts "#{comment.author['name']} wrote: #{comment.body}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Start
|
2
|
+
|
3
|
+
def initialize(ticket, logger)
|
4
|
+
@ticket = ticket
|
5
|
+
@logger = logger
|
6
|
+
end
|
7
|
+
|
8
|
+
def execute
|
9
|
+
`git checkout develop`
|
10
|
+
`git pull`
|
11
|
+
`git flow feature start #{@ticket.branch_name}`
|
12
|
+
@logger.add("Started #{@ticket.branch_name}")
|
13
|
+
`git add .`
|
14
|
+
`git commit -am "#{@ticket.id} #in-progress"`
|
15
|
+
`git flow feature publish #{@ticket.branch_name}`
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class Ticket
|
2
|
+
|
3
|
+
def initialize(repo, jira)
|
4
|
+
@repo = repo
|
5
|
+
@jira = jira
|
6
|
+
end
|
7
|
+
|
8
|
+
def id
|
9
|
+
@id ||= id_by_argument_or_branch
|
10
|
+
end
|
11
|
+
|
12
|
+
def branch_name
|
13
|
+
"#{id}-#{parameterize(summary)}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def jira_ticket
|
17
|
+
@jira && @jira.ticket(id)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def summary
|
23
|
+
jira_ticket && jira_ticket.summary
|
24
|
+
end
|
25
|
+
|
26
|
+
def id_by_argument_or_branch
|
27
|
+
ARGV.size == 2 ? ARGV.pop : id_from_branch
|
28
|
+
end
|
29
|
+
|
30
|
+
def name_from_branch
|
31
|
+
@repo.head.name.split('/')[-1][/^.*-.*$/]
|
32
|
+
end
|
33
|
+
|
34
|
+
def id_from_branch
|
35
|
+
parts = name_from_branch.split('-')
|
36
|
+
"#{parts[0]}-#{parts[1]}"
|
37
|
+
end
|
38
|
+
|
39
|
+
# Stolen from ActiveSupport
|
40
|
+
def parameterize(string, sep = '-')
|
41
|
+
# Turn unwanted chars into the separator
|
42
|
+
string.gsub!(/[^a-zA-Z0-9\-_]+/, sep)
|
43
|
+
unless sep.nil? || sep.empty?
|
44
|
+
re_sep = Regexp.escape(sep)
|
45
|
+
# No more than one of the separator in a row.
|
46
|
+
string.gsub!(/#{re_sep}{2,}/, sep)
|
47
|
+
# Remove leading/trailing separator.
|
48
|
+
string.gsub!(/^#{re_sep}|#{re_sep}$/, '')
|
49
|
+
end
|
50
|
+
string.downcase
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/lib/git_scf.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'rugged'
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
require 'git_scf/ticket'
|
5
|
+
require 'git_scf/version'
|
6
|
+
require 'git_scf/jira'
|
7
|
+
require 'git_scf/env_config'
|
8
|
+
require 'git_scf/logger'
|
9
|
+
require 'git_scf/subcommands'
|
10
|
+
|
11
|
+
module GitScf
|
12
|
+
extend self
|
13
|
+
|
14
|
+
REPO_PATH = '.'
|
15
|
+
|
16
|
+
# Parses command line arguments and does what needs to be done.
|
17
|
+
def execute(*args)
|
18
|
+
options = {}
|
19
|
+
opts = OptionParser.new do |opts|
|
20
|
+
# Set a banner, displayed at the top of the help screen.
|
21
|
+
opts.banner = "Usage: git scf (start|show|review|finish) [issue_number]"
|
22
|
+
|
23
|
+
# Define the options, and what they do
|
24
|
+
options[:verbose] = false
|
25
|
+
opts.on( '-v', '--verbose', 'Output more information' ) do
|
26
|
+
options[:verbose] = true
|
27
|
+
end
|
28
|
+
|
29
|
+
# Displays the help screen.
|
30
|
+
opts.on( '-h', '--help', 'Display this screen' ) do
|
31
|
+
puts opts
|
32
|
+
exit
|
33
|
+
end
|
34
|
+
end
|
35
|
+
opts.parse!
|
36
|
+
|
37
|
+
if ARGV.empty?
|
38
|
+
puts "ERROR: you must specify a subcommand"
|
39
|
+
puts opts
|
40
|
+
exit
|
41
|
+
end
|
42
|
+
|
43
|
+
begin
|
44
|
+
repo = Rugged::Repository.new(REPO_PATH)
|
45
|
+
rescue
|
46
|
+
puts "ERROR: Invalid git directory"
|
47
|
+
puts opts
|
48
|
+
exit
|
49
|
+
end
|
50
|
+
|
51
|
+
jira = Jira.new(EnvConfig.new(repo))
|
52
|
+
ticket = Ticket.new(repo, jira)
|
53
|
+
logger = Logger.new
|
54
|
+
|
55
|
+
case ARGV.first
|
56
|
+
when 'start'
|
57
|
+
Start.new(ticket, logger)
|
58
|
+
when 'show'
|
59
|
+
Show.new(ticket, options[:verbose])
|
60
|
+
when 'review'
|
61
|
+
Review.new(ticket, logger)
|
62
|
+
when 'finish'
|
63
|
+
Finish.new(ticket, logger)
|
64
|
+
end.execute
|
65
|
+
end
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git_scf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jeff Blasius
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: hub
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: jira
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rugged
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: ! " Provides git tools that match the SCF workflow. \n"
|
79
|
+
email: jeff@seeclickfix.com
|
80
|
+
executables:
|
81
|
+
- git-scf
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- README.md
|
86
|
+
- lib/git_scf/env_config.rb
|
87
|
+
- lib/git_scf/jira.rb
|
88
|
+
- lib/git_scf/logger.rb
|
89
|
+
- lib/git_scf/subcommands/finish.rb
|
90
|
+
- lib/git_scf/subcommands/review.rb
|
91
|
+
- lib/git_scf/subcommands/show.rb
|
92
|
+
- lib/git_scf/subcommands/start.rb
|
93
|
+
- lib/git_scf/subcommands.rb
|
94
|
+
- lib/git_scf/ticket.rb
|
95
|
+
- lib/git_scf/version.rb
|
96
|
+
- lib/git_scf.rb
|
97
|
+
- bin/git-scf
|
98
|
+
homepage: http://github.com/SeeClickFix/git_scf
|
99
|
+
licenses: []
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.9.2
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.8.24
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: Git tools for SCF's workflow.
|
122
|
+
test_files: []
|