git_scf 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/git_scf/env_config.rb +15 -13
- data/lib/git_scf/jira.rb +21 -19
- data/lib/git_scf/logger.rb +14 -12
- data/lib/git_scf/subcommands/finish.rb +15 -13
- data/lib/git_scf/subcommands/review.rb +14 -12
- data/lib/git_scf/subcommands/show.rb +21 -19
- data/lib/git_scf/subcommands/start.rb +15 -14
- data/lib/git_scf/ticket.rb +44 -42
- data/lib/git_scf/version.rb +1 -1
- metadata +1 -1
data/lib/git_scf/env_config.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
-
|
1
|
+
module GitScf
|
2
|
+
class EnvConfig
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
def initialize(repo)
|
5
|
+
@repo = repo
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def get(key)
|
9
|
+
ENV[key] || @repo.config["gitscf.#{git_key(key)}"]
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def repo
|
13
|
+
@repo
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
+
private
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
def git_key(key)
|
19
|
+
key.downcase.gsub('_','')
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
data/lib/git_scf/jira.rb
CHANGED
@@ -1,23 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
module GitScf
|
2
|
+
class Jira
|
3
|
+
require 'jira'
|
4
|
+
|
5
|
+
def initialize(config)
|
6
|
+
@config = config
|
7
|
+
options = { username: config.get('JIRA_USERNAME'),
|
8
|
+
password: config.get('JIRA_PASSWORD'),
|
9
|
+
use_ssl: true,
|
10
|
+
site: 'https://seeclickfix.atlassian.net',
|
11
|
+
context_path: '/',
|
12
|
+
rest_base_path: 'rest/api/2',
|
13
|
+
auth_type: :basic }
|
14
|
+
@jira = JIRA::Client.new(options)
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def config
|
18
|
+
@config
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
def ticket(id)
|
22
|
+
@jira.Issue.find(id)
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
data/lib/git_scf/logger.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
|
-
|
1
|
+
module GitScf
|
2
|
+
class Logger
|
2
3
|
|
3
|
-
|
4
|
+
LOG_PATH = '.gitscf'
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
def initialize(ticket)
|
7
|
+
`mkdir -p #{LOG_PATH}`
|
8
|
+
@filename = "#{ticket.id}"
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def add(string)
|
12
|
+
`echo '#{string} #{`date`}' >> #{log_file}`
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
+
private
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
def log_file
|
18
|
+
"#{LOG_PATH}/#{@filename}"
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
@@ -1,16 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module GitScf
|
2
|
+
class Finish
|
3
|
+
def initialize(ticket, logger)
|
4
|
+
@ticket = ticket
|
5
|
+
@logger = logger
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
def execute
|
9
|
+
@logger.add("Closing out #{@ticket.branch_name}")
|
10
|
+
`git add .`
|
11
|
+
`git commit -am "#{@ticket.id} #done"`
|
12
|
+
`git push`
|
13
|
+
`git flow feature finish #{@ticket.branch_name}`
|
14
|
+
`git push`
|
15
|
+
`git push origin :refs/heads/feature/#{@ticket.branch_name}`
|
16
|
+
end
|
15
17
|
end
|
16
18
|
end
|
@@ -1,16 +1,18 @@
|
|
1
|
-
|
1
|
+
module GitScf
|
2
|
+
class Review
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
def initialize(ticket, logger)
|
5
|
+
@ticket = ticket
|
6
|
+
@logger = logger
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
def execute
|
10
|
+
@logger.add("Reviewing #{@ticket.branch_name}")
|
11
|
+
`git add .`
|
12
|
+
`git commit -am "#{@ticket.id} #review"`
|
13
|
+
`git push`
|
14
|
+
`hub pull-request "Addresses #{@ticket.id} #{@ticket.summary} please review." | pbcopy`
|
15
|
+
puts "The code-review URL is in your clipboard."
|
16
|
+
end
|
15
17
|
end
|
16
18
|
end
|
@@ -1,21 +1,23 @@
|
|
1
|
-
|
1
|
+
module GitScf
|
2
|
+
class Show
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
def initialize(ticket, verbose)
|
5
|
+
@ticket = ticket
|
6
|
+
@verbose = verbose
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
9
|
+
def execute
|
10
|
+
jira_ticket = @ticket.jira_ticket
|
11
|
+
puts "Summary: #{jira_ticket.summary}"
|
12
|
+
puts "Status: #{jira_ticket.status.name}"
|
13
|
+
puts "Created at: #{jira_ticket.created}"
|
14
|
+
if @verbose
|
15
|
+
puts "Description: #{jira_ticket.description}"
|
16
|
+
jira_ticket.comments.each do |comment|
|
17
|
+
puts ""
|
18
|
+
puts "#{comment.author['name']} wrote: #{comment.body}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,17 +1,18 @@
|
|
1
|
-
|
1
|
+
module GitScf
|
2
|
+
class Start
|
3
|
+
def initialize(ticket, logger)
|
4
|
+
@ticket = ticket
|
5
|
+
@logger = logger
|
6
|
+
end
|
2
7
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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}`
|
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
|
16
17
|
end
|
17
18
|
end
|
data/lib/git_scf/ticket.rb
CHANGED
@@ -1,53 +1,55 @@
|
|
1
|
-
|
1
|
+
module GitScf
|
2
|
+
class Ticket
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
def initialize(jira)
|
5
|
+
@repo = jira.config.repo
|
6
|
+
@jira = jira
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def id
|
10
|
+
@id ||= id_by_argument_or_branch
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def branch_name
|
14
|
+
"#{id}-#{parameterize(summary)[0..50]}"
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def jira_ticket
|
18
|
+
@jira && @jira.ticket(id)
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def summary
|
22
|
+
jira_ticket && jira_ticket.summary
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
+
private
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
def id_by_argument_or_branch
|
28
|
+
ARGV.size == 2 ? ARGV.pop : id_from_branch
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
def name_from_branch
|
32
|
+
@repo.head.name.split('/')[-1][/^.*-.*$/]
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
def id_from_branch
|
36
|
+
parts = name_from_branch.split('-')
|
37
|
+
"#{parts[0]}-#{parts[1]}"
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
40
|
+
# Stolen from ActiveSupport
|
41
|
+
def parameterize(string, sep = '-')
|
42
|
+
# Turn unwanted chars into the separator
|
43
|
+
string.gsub!(/[^a-zA-Z0-9\-_]+/, sep)
|
44
|
+
unless sep.nil? || sep.empty?
|
45
|
+
re_sep = Regexp.escape(sep)
|
46
|
+
# No more than one of the separator in a row.
|
47
|
+
string.gsub!(/#{re_sep}{2,}/, sep)
|
48
|
+
# Remove leading/trailing separator.
|
49
|
+
string.gsub!(/^#{re_sep}|#{re_sep}$/, '')
|
50
|
+
end
|
51
|
+
string.downcase
|
52
|
+
end
|
52
53
|
|
53
|
-
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/git_scf/version.rb
CHANGED