jiragit 0.5.1 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0b9e5fb059f4e4a481b1a8790b9c744da7c7923
4
- data.tar.gz: 9f5b09b6e372d0ab464468773f7431b03f481a2a
3
+ metadata.gz: 3934b14132024fc659b50eeee4af934b9c4a873f
4
+ data.tar.gz: c34ecbdfddfba26150405510569a76d16a24c054
5
5
  SHA512:
6
- metadata.gz: 032443a2011cfe360d4be3ef610be4a9aab7197b73002d4d68789217860e03e776e1f54463b17792edfa7454960dffd43a4fc02fcd1f25a462b87b6ab8d7f94c
7
- data.tar.gz: a2d287d10166c6311ccc24abbe018599aab94e3cc95704a06a2c6fafae200370c592b05509e0e4dafc4eae2f816428763db5844c8d5a0eafa9e9c9e5949103aa
6
+ metadata.gz: f22b118a55b3dacc7242f8369b98f47af5c6475bb64ac130afef0c9ab8e15c73d6c7e81750a1e8770d73f66c609cd4bf45ee7310a3f56317917bcea0a6e4ba6d
7
+ data.tar.gz: 25ec4819eb6df828f20338bd5d9615eeb3c72d1a4f63100bdf8c7d2fa4a7580c59df6204b9c04d5e224c5c556538f6ce0881cd7f1233ce664ed678746e124486
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ namespace :gem do
12
12
  end
13
13
 
14
14
  task :install => [:build] do
15
- `gem install pkg/jiragit-1.0.0.gem`
15
+ `gem install pkg/jiragit*.gem`
16
16
  end
17
17
 
18
18
  end
data/hooks/post-checkout CHANGED
@@ -23,11 +23,11 @@ def branch_switch?
23
23
  end
24
24
 
25
25
  def current_branch
26
- Jiragit::Git.current_branch
26
+ @current_branch ||= Jiragit::Git.current_branch
27
27
  end
28
28
 
29
29
  def previous_branch
30
- Jiragit::Git.previous_branch
30
+ @previous_branch ||= Jiragit::Git.previous_branch
31
31
  end
32
32
 
33
33
  def new_branch?
@@ -84,8 +84,15 @@ def message_jiras_related_to_current_branch
84
84
  message("JIRA(s): #{related_jiras(branch: current_branch).join(', ')}")
85
85
  end
86
86
 
87
+ def jiras_from_current_branch_name
88
+ current_branch.scan(/([A-Z]{1,4}-[1-9][0-9]{0,6})/).to_a
89
+ end
90
+
87
91
  def query_for_related_jiras
88
- default = related_jiras(branch: previous_branch).join(', ') if new_branch?
92
+ related = related_jiras(branch: previous_branch)
93
+ branch = jiras_from_current_branch_name
94
+ puts "default branch: #{branch}"
95
+ default = [related, branch].flatten.join(', ')
89
96
  query("What is the JIRA Number?", default)
90
97
  end
91
98
 
data/lib/jiragit.rb CHANGED
@@ -4,6 +4,7 @@ require 'jiragit/configuration'
4
4
  require 'jiragit/cli'
5
5
  require 'jiragit/git/repository'
6
6
  require 'jiragit/git/commit_response'
7
+ require 'jiragit/git/commit'
7
8
  require 'jiragit/git/branch'
8
9
  require 'jiragit/tag'
9
10
  require 'jiragit/vault'
data/lib/jiragit/cli.rb CHANGED
@@ -12,7 +12,8 @@ module Jiragit
12
12
  :remote,
13
13
  :local,
14
14
  :configure,
15
- :configuration
15
+ :configuration,
16
+ :build
16
17
  ]
17
18
 
18
19
  FLAGS = [
@@ -68,21 +69,18 @@ module Jiragit
68
69
  return
69
70
  end
70
71
  puts "Listing all relations for jira #{@params[0]}"
71
- js = JiraStore.new("#{Jiragit::Git.repository_root}/.git/jiragit/jira_store")
72
- puts js.relations(jira: @params[0]).to_a
72
+ puts jira_store.relations(jira: @params[0]).to_a
73
73
  end
74
74
 
75
75
  def branch
76
76
  branch = @params[0] || Jiragit::Git.current_branch
77
77
  puts "Listing all relations for branch #{branch}"
78
- js = JiraStore.new("#{Jiragit::Git.repository_root}/.git/jiragit/jira_store")
79
- puts js.relations(branch: branch).to_a
78
+ puts jira_store.relations(branch: branch).to_a
80
79
  end
81
80
 
82
81
  def jira_branch
83
82
  puts "Relating jira #{@params[0]} and branch #{@params[1]}"
84
- js = JiraStore.new("#{Jiragit::Git.repository_root}/.git/jiragit/jira_store")
85
- js.relate(jira: @params[0], branch: @params[1])
83
+ jira_store.relate(jira: @params[0], branch: @params[1])
86
84
  end
87
85
 
88
86
  def browse
@@ -135,8 +133,23 @@ module Jiragit
135
133
  end
136
134
  end
137
135
 
136
+ def build
137
+ commits = Jiragit::Git.log
138
+ commits.each do |commit|
139
+ commit.jiras.each do |jira|
140
+ puts "relating: commit #{commit.sha} to jira: #{jira}"
141
+ jira_store.relate(commit: commit.sha, jira: jira, save: false)
142
+ end
143
+ end
144
+ jira_store.save
145
+ end
146
+
138
147
  private
139
148
 
149
+ def jira_store
150
+ @jira_store ||= JiraStore.new("#{Jiragit::Git.repository_root}/.git/jiragit/jira_store")
151
+ end
152
+
140
153
  def run(command)
141
154
  `#{command}`
142
155
  end
@@ -192,8 +205,7 @@ module Jiragit
192
205
  end
193
206
 
194
207
  def related(type, relation)
195
- js = JiraStore.new("#{Jiragit::Git.repository_root}/.git/jiragit/jira_store")
196
- jiras = js
208
+ jiras = jira_store
197
209
  .relations(relation)
198
210
  .to_a
199
211
  .select { |r| r.type == type }
@@ -0,0 +1,43 @@
1
+ module Jiragit
2
+
3
+ module Git
4
+
5
+ class Commit
6
+
7
+ attr_accessor :log
8
+
9
+ def initialize(log)
10
+ @log = log
11
+ end
12
+
13
+ def sha
14
+ @sha ||= log[/(?<=commit )[0-9a-f]{40}/]
15
+ end
16
+
17
+ def date
18
+ @date ||= log[/(?<=Date:)\s+\b.*?$/].gsub(/^\s+/,'')
19
+ end
20
+
21
+ def author
22
+ @author ||= log[/(?<=Author:)\s+\b.*?$/].gsub(/^\s+/,'')
23
+ end
24
+
25
+ def merge
26
+ @merge ||= log[/(?<=Merge:)\s+\b.*?$/].gsub(/^\s+/,'')
27
+ end
28
+
29
+ def body
30
+ @body ||= log.gsub(/^.*Date:.*?\n/m,'')
31
+ end
32
+
33
+ IS_JIRA = /\b([A-Z]{1,4}-[1-9][0-9]{0,6})\b/
34
+
35
+ def jiras
36
+ @jiras ||= log.scan(IS_JIRA).to_a.flatten.uniq
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -101,6 +101,13 @@ module Jiragit
101
101
  value
102
102
  end
103
103
 
104
+ def self.log
105
+ log = `git log 2>&1`.chomp
106
+ raise NoRepositoryError if log=~/^Not a git repository/
107
+ commits = log.split(/(?=commit [0-9a-f]{40})/)
108
+ commits.map { |commit| Commit.new(commit) }
109
+ end
110
+
104
111
  class Repository
105
112
 
106
113
  def self.create(path)
@@ -11,7 +11,7 @@ module Jiragit
11
11
  def relate(params)
12
12
  tags = extract_tags(params).compact
13
13
  vault.relate(*tags)
14
- vault.save
14
+ vault.save unless params[:save] == false
15
15
  end
16
16
 
17
17
  def relations(params)
@@ -26,6 +26,10 @@ module Jiragit
26
26
  vault.load
27
27
  end
28
28
 
29
+ def save
30
+ vault.save
31
+ end
32
+
29
33
  private
30
34
 
31
35
  attr_accessor :location
@@ -1,3 +1,3 @@
1
1
  module Jiragit
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.3"
3
3
  end
data/spec/branch_spec.rb CHANGED
@@ -42,6 +42,20 @@ describe "Repository Branching Behaviors" do
42
42
 
43
43
  end
44
44
 
45
+ context "the new branch name includes a jira" do
46
+
47
+ before do
48
+ checkout_a_new_branch('parent_branch')
49
+ @repo.make_a_commit
50
+ end
51
+
52
+ it "should provide and accept default jira from branch name" do
53
+ checkout_a_new_branch_with_default('PA-12345_branch')
54
+ assert_relation({jira: 'PA-12345'}, {branch: 'PA-12345_branch'})
55
+ end
56
+
57
+ end
58
+
45
59
  end
46
60
 
47
61
  context "when checking out an existing branch" do
data/spec/test_support.rb CHANGED
@@ -8,7 +8,7 @@ module TestSupport
8
8
  rake = Rake.application
9
9
  rake.init
10
10
  rake.load_rakefile
11
- rake['gem:install'].invoke
11
+ rake['install'].invoke
12
12
  end
13
13
 
14
14
  def create_test_repository(repository)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jiragit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derrick Parkhurst
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-15 00:00:00.000000000 Z
11
+ date: 2014-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,6 +58,7 @@ files:
58
58
  - lib/jiragit/cli.rb
59
59
  - lib/jiragit/configuration.rb
60
60
  - lib/jiragit/git/branch.rb
61
+ - lib/jiragit/git/commit.rb
61
62
  - lib/jiragit/git/commit_response.rb
62
63
  - lib/jiragit/git/repository.rb
63
64
  - lib/jiragit/jira_store.rb