ruby_git_hooks 0.0.32 → 0.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -254,6 +254,14 @@ Ruby version managers like rbenv.
254
254
 
255
255
  ## Troubleshooting
256
256
 
257
+ ### Running our tests
258
+ For now, to run the tests you need to be sure to have the latest code
259
+ actually installed.
260
+
261
+ * gem build ruby_git_hooks.gemspec
262
+ * gem install ruby_git_hooks-0.0.34.gem (but use your real file name)
263
+ * rake test
264
+
257
265
  ### It Says It's Not Installed
258
266
 
259
267
  Sometimes you can get an error saying that ruby_git_hooks isn't
data/TODO CHANGED
@@ -64,4 +64,6 @@
64
64
  * In jira_add_comment_hook, rescue DNS errors for VPN setups. Allow
65
65
  the commit, but print a message.
66
66
 
67
+ * In jira_add_comment_hook, allow to specify which branches to process
68
+
67
69
  * In ruby_git_hooks.rb, have "shell!" capture both STDOUT and STDERR.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 OL2, Inc. See LICENSE.txt for details.
1
+ # Copyright (C) 2013-2014 OL2, Inc. See LICENSE.txt for details.
2
2
 
3
3
  require "ruby_git_hooks/version"
4
4
 
@@ -46,19 +46,24 @@ module RubyGitHooks
46
46
  # All filenames in repo
47
47
  attr_accessor :ls_files
48
48
 
49
- # All current commits (sometimes empty)
50
- attr_accessor :commits
51
-
52
49
  # Commit message for current commit
53
50
  attr_accessor :commit_message
54
51
 
55
52
  # Commit message file for current commit
56
53
  attr_accessor :commit_message_file
54
+
55
+ # the following are for hooks which involve multiple commits (pre-receive, post-receive):
56
+ # (may be empty in other hooks)
57
+ # All current commits
58
+ attr_accessor :commits
59
+
60
+ # refs associated with each commit
61
+ attr_accessor :commit_ref_map
57
62
  end
58
63
 
59
64
  # Instances of Hook delegate these methods to the class methods.
60
65
  HOOK_INFO = [ :files_changed, :file_contents, :file_diffs, :ls_files,
61
- :commits, :commit_message, :commit_message_file ]
66
+ :commits, :commit_message, :commit_message_file, :commit_ref_map ]
62
67
  HOOK_INFO.each do |info_method|
63
68
  define_method(info_method) do |*args, &block|
64
69
  Hook.send(info_method, *args, &block)
@@ -69,25 +74,47 @@ module RubyGitHooks
69
74
 
70
75
  # Pre-receive gets no args, but STDIN with a list of changes.
71
76
  "pre-receive" => proc {
77
+ def commit_date(c)
78
+ date = Hook.shell!("git log #{c} --pretty=%ct -1").strip.to_i
79
+ end
80
+
72
81
  changes = []
73
82
  STDIN.each_line do |line|
83
+ # STDERR.puts line # for debugging
74
84
  base, commit, ref = line.strip.split
75
85
  changes.push [base, commit, ref]
76
86
  end
77
- self.commits = []
87
+ self.commit_ref_map = {} #
88
+ # commit_ref_map is a list of which new commits are in this push, and which branches they are associated with
89
+ # as {commit1 => [ref1, ref2], commit2 => [ref1]}
90
+ # For existing branches, this information is sent in directly "base commit ref"
91
+ # BUT for branch new branches, the pre/post-receive hook gets "0 commit ref"
92
+ # ref is of the form refs/heads/branch_name
93
+
94
+ new_branches = changes.select{|base, _, _ | base =~ /\A0+\z/ }.collect{|_,_, ref| ref[/refs\/heads\/(\S+)/,1] }
95
+
96
+ if !new_branches.empty?
97
+ # For new branches, we will calculate which commits are new by specifically not including commits which are
98
+ # present in any other branch (and therefore will have been processed with that branch)
99
+ all_branches = Hook.shell!("git branch").split(/[* \n]+/).select{|b| !b.empty?} # remove spaces and the *
100
+ # ref is like refs/heads/<branch_name>
101
+ existing_branches = all_branches - new_branches
102
+ exclude_branches = existing_branches.inject("") {|str, b| str + " ^" + b} # "^B1 ^B2"
103
+ end
104
+
78
105
 
79
106
  self.files_changed = []
80
107
  self.file_contents = {}
81
108
  self.file_diffs = {}
82
109
 
83
110
  changes.each do |base, commit, ref|
84
- no_base = false
85
- if base =~ /\A0+\z/
86
- # if base is 000... (initial commit), then all files were added, and git diff won't work
87
- no_base = true
88
- files_with_status = Hook.shell!("git ls-tree --name-status -r #{commit}").split("\n")
89
- # put the A at the front
90
- files_with_status.map!{|filename| "A\t" + filename}
111
+ new_branch = base =~ /\A0+\z/
112
+ if new_branch
113
+ # if base is 000 then this is a new branch and we have no easy way know what files were added
114
+ # so for now just don't include files changed in a new branch
115
+ # because really this should be done per commit or at least per branch anyway
116
+ # TODO: we could figure it out based on the branch commit calculations per branch (see below)
117
+ files_with_status = []
91
118
  else
92
119
  files_with_status = Hook.shell!("git diff --name-status #{base}..#{commit}").split("\n")
93
120
  end
@@ -107,19 +134,34 @@ module RubyGitHooks
107
134
  file_contents[file_changed] = ""
108
135
  end
109
136
  end
110
- commit_range = no_base ? commit : "#{base}..#{commit}"
111
- new_commits = Hook.shell!("git log --pretty=format:%H #{commit_range}").split("\n")
112
- self.commits = self.commits | new_commits
137
+
138
+ # now calculate which commits are new
139
+ if new_branch
140
+ # new branch, but we don't want to include all commits from beginning of time
141
+ # so exclude any commits that are on any other branches
142
+ # e.g. git rev-list <commit for B3> ^master ^B2
143
+ # NOTE: have to use commit, not ref, because if this is called in pre-receive the branch name of ref won't
144
+ # actually have been set up yet!
145
+ new_commits = Hook.shell!("git rev-list #{commit} #{exclude_branches}").split("\n")
146
+ else
147
+ # existing branch, base..commit is right
148
+ new_commits = Hook.shell!("git rev-list #{base}..#{commit}").split("\n")
149
+ end
150
+
151
+ new_commits.each do |one_commit|
152
+ self.commit_ref_map[one_commit] ||= [];
153
+ self.commit_ref_map[one_commit] << ref # name of the branch associated with this commit
154
+ end
113
155
  end
114
156
 
157
+ # we want the list of commits sorted by commit date
158
+ self.commits = self.commit_ref_map.keys.sort{|a,b|commit_date(b) <=> commit_date(a)}
159
+
115
160
  if !self.commits.empty?
116
161
  file_list_revision = self.commits.first # can't just use HEAD - remote may be on branch with no HEAD
117
162
  self.ls_files = Hook.shell!("git ls-tree --full-tree --name-only -r #{file_list_revision}").split("\n")
118
- # TODO should store ls_files per commit and ls_files with branch name (in case commits on multiple branches)?
163
+ # TODO should store ls_files per commit (with status)?
119
164
  end
120
-
121
-
122
-
123
165
  },
124
166
 
125
167
  "pre-commit" => proc {
@@ -286,7 +328,6 @@ ERR
286
328
  "any of: #{HOOK_NAMES.inspect}"
287
329
  exit 1
288
330
  end
289
-
290
331
  unless HOOK_TYPE_SETUP[@run_as_hook]
291
332
  STDERR.puts "No setup defined for hook type #{@run_as_hook.inspect}!"
292
333
  exit 1
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 OL2, Inc. See LICENSE.txt for details.
1
+ # Copyright (C) 2013-2014 OL2, Inc. See LICENSE.txt for details.
2
2
 
3
3
  # This is a set of Git operations, run via shell. It permits much
4
4
  # cleaner unit tests. Initially it was written in this way because it
@@ -57,7 +57,6 @@ module RubyGitHooks::GitOps
57
57
 
58
58
  @single_file_counter += 1
59
59
  end
60
- system("git mv child_repo/file_to_rename child_repo/renamed_file")
61
60
 
62
61
  def git_delete(repo_name="child_repo", filename="file_to_delete")
63
62
  # filename is a file that has already been added and commited to the repo
@@ -90,4 +89,24 @@ module RubyGitHooks::GitOps
90
89
  Hook.shell!("cd #{repo_name} && git log -1").chomp
91
90
  end
92
91
 
92
+ def git_tag(repo_name="child_repo", tagname="0.1")
93
+ Hook.shell! "cd #{repo_name} && git tag -a #{tagname} -m 'test'"
94
+ end
95
+
96
+ def git_checkout(repo_name="child_repo", branch_name="master")
97
+ Hook.shell! "cd #{repo_name} && git checkout #{branch_name}"
98
+ end
99
+
100
+ def git_create_and_checkout_branch(repo_name="child_repo", branch_name="B1")
101
+ Hook.shell! "cd #{repo_name} && git checkout -b #{branch_name}"
102
+ end
103
+
104
+ def git_push_all(repo_name = "child_repo")
105
+ Hook.shell! "cd #{repo_name} && git push --all"
106
+ end
107
+
108
+ def git_revlist_all(repo_name = "child_repo")
109
+ Hook.shell!("cd #{repo_name} && git rev-list --all").split("\n")
110
+ end
111
+
93
112
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 OL2, Inc. See LICENSE.txt for details.
1
+ # Copyright (C) 2013-2014 OL2, Inc. See LICENSE.txt for details.
2
2
 
3
3
  require "ruby_git_hooks"
4
4
  require "ruby_git_hooks/jira_ref_check"
@@ -114,21 +114,12 @@ class JiraCommentAddHook < RubyGitHooks::Hook
114
114
  uri = "#{repo_remote_path}/commit/#{commit}"
115
115
  end
116
116
 
117
- def get_change_list(commit)
118
- # we want changes from the previous commit, if any
119
- # ideally this list should be available from the ruby_git_hooks directly
120
- # since they go through this same process.
121
- current, base = Hook.shell!("git log #{commit} -2 --pretty=%H").split
122
- if !base
123
- # This is the initial commit so all files were added, but have to add the A ourselves
124
- files_with_status = Hook.shell!("git ls-tree --name-status -r #{commit}").split("\n")
125
- # put the A at the front
126
- files_with_status.map!{|filename| "A\t" + filename}
127
- else
128
-
129
- files_with_status = Hook.shell!("git diff --name-status #{base}..#{current}")
130
- end
131
- files_with_status
117
+ def get_commit_branch(commit)
118
+ # get the branch (list) for this commit
119
+ # will usually be a single ref ([refs/heads/branch_name]). but could
120
+ # theoretically be multiple if single commit is on several branches processed at the same time.
121
+ refs = self.commit_ref_map[commit]
122
+ refs ? refs.join(" ") : ""
132
123
  end
133
124
 
134
125
  def get_comment_content(commit, commit_message)
@@ -146,12 +137,16 @@ class JiraCommentAddHook < RubyGitHooks::Hook
146
137
  #
147
138
  # M test.txt
148
139
 
149
- github_link = build_commit_uri(commit) # have to do this separately
150
- changes = get_change_list(commit)
151
-
152
- revision_and_date = Hook.shell!("git log #{commit} -1 --pretty='Revision: %h committed by %cn%nCommit date: %cd'") rescue ""
153
-
154
- text = "#{revision_and_date}#{github_link}\n\n#{commit_message}\n{noformat}#{changes}{noformat}"
140
+ github_link = build_commit_uri(commit) # have to do this separately
141
+ branch = "Branch: #{get_commit_branch(commit)}"
142
+ begin
143
+ content = "Revision: %h committed by %cn%nCommit date: %cd%n#{branch}%n#{github_link}%n%n#{commit_message}%n{noformat}"
144
+ text = Hook.shell!("git log #{commit} -1 --name-status --pretty='#{content}'")
145
+ text += "{noformat}" # git log puts changes at the bottom, we need to close the noformat tag for Jira
146
+ rescue
147
+ text = "No commit details available for #{commit}\n#{commit_message}"
148
+ end
149
+ text
155
150
  end
156
151
 
157
152
  def check_one_commit(commit, commit_message)
@@ -262,7 +257,7 @@ class JiraCommentAddHook < RubyGitHooks::Hook
262
257
  # (it looks scary when there's a lot)
263
258
  # when there's only one, just return the commit
264
259
  # when more than one return first_commit..last_commit
265
- # use the shortened SHAH1 for readability
260
+ # use the shortened SHA-1 for readability
266
261
  return "" if !self.commits || self.commits.empty?
267
262
 
268
263
  if self.commits.size == 1
@@ -1,5 +1,5 @@
1
- # Copyright (C) 2013 OL2, Inc. See LICENSE.txt for details.
1
+ # Copyright (C) 2013-2014 OL2, Inc. See LICENSE.txt for details.
2
2
 
3
3
  module RubyGitHooks
4
- VERSION = "0.0.32"
4
+ VERSION = "0.0.40"
5
5
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 OL2, Inc. See LICENSE.txt for details.
1
+ # Copyright (C) 2013-2014 OL2, Inc. See LICENSE.txt for details.
2
2
 
3
3
  require "test_helper"
4
4
 
@@ -40,6 +40,24 @@ class TestHook < RubyGitHooks::Hook
40
40
  end
41
41
  end
42
42
 
43
+ RubyGitHooks.run TestHook.new
44
+ HOOK
45
+
46
+ TEST_HOOK_MULTI = <<HOOK
47
+ #{RubyGitHooks.shebang}
48
+ require "ruby_git_hooks"
49
+
50
+ class TestHook < RubyGitHooks::Hook
51
+ def check
52
+ File.open("#{TEST_PATH}", "w") do |f|
53
+ f.puts commit_ref_map.inspect
54
+ end
55
+
56
+ puts "Test hook runs!"
57
+ true
58
+ end
59
+ end
60
+
43
61
  RubyGitHooks.run TestHook.new
44
62
  HOOK
45
63
 
@@ -91,32 +109,128 @@ HOOK
91
109
  end
92
110
 
93
111
  def test_simple_pre_receive
94
- add_hook("parent_repo.git", "pre-receive", TEST_HOOK_BODY)
112
+ @hook_name ||= "pre-receive"
113
+ add_hook("parent_repo.git", @hook_name, TEST_HOOK_BODY)
95
114
 
96
115
  new_single_file_commit "child_repo"
116
+
97
117
  git_push("child_repo")
98
118
 
119
+ assert File.exist?(TEST_PATH), "Test #{@hook_name} hook didn't run!"
120
+
121
+ # file contents not expected to reach pre-receive hook for first push of a branch
122
+ # assert File.read(TEST_PATH).include?("Single-file commit"), "No file contents reached pre-receive hook!"
123
+ end
124
+
125
+
126
+ def test_multiple_pre_receive
127
+ @hook_name ||= "pre-receive"
128
+ add_hook("parent_repo.git", @hook_name, TEST_HOOK_MULTI)
129
+
130
+ before_commits = git_revlist_all("child_repo") # commits already in the repo
131
+
132
+ new_single_file_commit "child_repo"
133
+
134
+ git_create_and_checkout_branch("child_repo", "B1")
135
+ new_single_file_commit "child_repo"
136
+ git_push_all("child_repo") # pushes multiple branches
137
+
99
138
  assert File.exist?(TEST_PATH), "Test pre-receive hook didn't run!"
100
- assert File.read(TEST_PATH).include?("Single-file commit"),
101
- "No file contents reached pre-receive hook!"
139
+
140
+ commits = git_revlist_all("child_repo") - before_commits # will give us all the commits we just made
141
+ contents = File.read(TEST_PATH)
142
+ commits.each do |c|
143
+ assert contents.include?(c), "Missing commit info for #{c} in #{@hook_name} hook!"
144
+ end
145
+ assert contents.include?("B1")
146
+ assert contents.include?("master")
147
+ end
148
+
149
+ def test_simple_post_receive
150
+ @hook_name = "post-receive" # pre and post are the same, but want to test both
151
+ # default to pre but this lets us use the exact same tests.
152
+ test_simple_pre_receive
153
+ end
154
+
155
+ def test_multiple_post_receive
156
+ @hook_name = "post-receive" # pre and post are the same, but want to test both
157
+ # default to pre but this lets us use the exact same tests.
158
+ test_multiple_branch_pre_receive
159
+ end
160
+
161
+ def test_delete_post_receive
162
+ @hook_name = "post-receive" # pre and post are the same, but want to test both
163
+ # default to pre but this lets us use the exact same tests.
164
+ test_pre_receive_with_delete
165
+ end
166
+
167
+
168
+
169
+ def test_multiple_branch_pre_receive
170
+ @hook_name ||= "pre-receive"
171
+
172
+ add_hook("parent_repo.git", @hook_name, TEST_HOOK_MULTI)
173
+
174
+ before_commits = git_revlist_all("child_repo") # commits already in the repo
175
+
176
+ new_single_file_commit "child_repo" # commit to master
177
+ git_create_and_checkout_branch("child_repo", "B1")
178
+ new_single_file_commit "child_repo"
179
+ git_create_and_checkout_branch("child_repo", "B2")
180
+ new_single_file_commit "child_repo"
181
+ git_checkout("child_repo", "master")
182
+ new_single_file_commit "child_repo"
183
+
184
+ git_push_all("child_repo") # pushes multiple branches
185
+
186
+ commits = before_commits - git_revlist_all("child_repo") # will give us all the commits we just made
187
+ contents = File.read(TEST_PATH)
188
+ commits.each do |c|
189
+ assert contents.include?(c), "Missing commit info for #{c} in #{@hook_name} hook!"
190
+ end
191
+ assert contents.include?("B1")
192
+ assert contents.include?("B2")
193
+ assert contents.include?("master")
194
+
195
+ # now push a commit to a single existing branch and a new branch
196
+ before_commits = git_revlist_all("child_repo") # commits already in the repo
197
+
198
+ git_create_and_checkout_branch("child_repo", "B4") # no commits
199
+ git_checkout("child_repo", "B1")
200
+ new_single_file_commit "child_repo"
201
+ git_create_and_checkout_branch("child_repo", "B3")
202
+ new_single_file_commit "child_repo"
203
+
204
+ git_push_all("child_repo") # pushes multiple branches
205
+
206
+ commits = git_revlist_all("child_repo") - before_commits # will give us all the commits we just made
207
+ contents = File.read(TEST_PATH)
208
+ commits.each do |c|
209
+ assert contents.include?(c), "Missing commit info for #{c} in pre-receive hook!"
210
+ end
211
+ assert contents.include?("B1")
212
+ assert contents.include?("B3")
213
+
214
+ refute contents.include?("B2")
215
+ refute contents.include?("master")
216
+
102
217
  end
103
218
 
104
219
 
105
220
  def test_pre_receive_with_delete
106
- add_hook("parent_repo.git", "pre-receive", TEST_HOOK_BODY)
221
+ @hook_name ||= "pre-receive"
222
+ add_hook("parent_repo.git", @hook_name, TEST_HOOK_BODY)
107
223
 
108
224
  new_commit "child_repo", "file_to_delete"
109
225
  git_push "child_repo"
110
226
 
111
-
112
227
  git_delete "child_repo", "file_to_delete"
113
228
  git_commit "child_repo", "Deleted file_to_delete"
114
229
  git_push "child_repo"
115
230
 
116
-
117
- assert File.exist?(TEST_PATH), "Test pre-receive hook didn't run!"
231
+ assert File.exist?(TEST_PATH), "Test #{@hook_name} hook didn't run!"
118
232
  assert File.read(TEST_PATH).include?('"file_to_delete"=>""'),
119
- "File deletion did not reach pre-receive hook!"
233
+ "File deletion did not reach #{@hook_name} hook!"
120
234
  end
121
235
 
122
236
  def test_commit_msg
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 OL2, Inc. See LICENSE.txt for details.
1
+ # Copyright (C) 2013-2014 OL2, Inc. See LICENSE.txt for details.
2
2
 
3
3
  require "test_helper"
4
4
 
@@ -9,6 +9,7 @@ class RealCopyrightCheckHookTest < HookTestCase
9
9
  REPOS_DIR = File.expand_path File.join(File.dirname(__FILE__), "repos")
10
10
  FAKE_MAILER = File.join(File.dirname(__FILE__), "fake_mailer")
11
11
  MAILER_FILE = File.join(File.dirname(__FILE__), "mail_params")
12
+ CURRENT_YEAR = Time.now.strftime("%Y")
12
13
  TEST_HOOK_BASIC = <<TEST
13
14
  #{RubyGitHooks.shebang}
14
15
  require "ruby_git_hooks/copyright_check"
@@ -115,7 +116,7 @@ FILE_CONTENTS
115
116
  add_hook("child_repo", "post-commit", TEST_HOOK_BASIC)
116
117
 
117
118
  new_commit("child_repo", "correct_file.rb", <<FILE_CONTENTS)
118
- # Copyright (C) 1941-2013 YoyoDyne, Inc. All Rights Reserved.
119
+ # Copyright (C) 1941-#{CURRENT_YEAR} YoyoDyne, Inc. All Rights Reserved.
119
120
  FILE_CONTENTS
120
121
 
121
122
  assert !File.exist?(MAILER_FILE), "Copyright test must not send email!"
@@ -125,7 +126,7 @@ FILE_CONTENTS
125
126
  add_hook("child_repo", "post-commit", TEST_HOOK_COMPANY)
126
127
 
127
128
  new_commit("child_repo", "correct_file.rb", <<FILE_CONTENTS)
128
- # Copyright (C) 1941-2013 YoyoDyne Industries All Rights Reserved.
129
+ # Copyright (C) 1941-#{CURRENT_YEAR} YoyoDyne Industries All Rights Reserved.
129
130
  FILE_CONTENTS
130
131
 
131
132
  assert !File.exist?(MAILER_FILE), "Copyright test must not send email!"
@@ -135,7 +136,7 @@ FILE_CONTENTS
135
136
  add_hook("child_repo", "post-commit", TEST_HOOK_COMPANY)
136
137
 
137
138
  new_commit("child_repo", "correct_file.rb", <<FILE_CONTENTS)
138
- # Copyright (C) 1941-2013 YoyoWrong All Rights Reserved.
139
+ # Copyright (C) 1941-#{CURRENT_YEAR} YoyoWrong All Rights Reserved.
139
140
  FILE_CONTENTS
140
141
 
141
142
  assert File.exist?(MAILER_FILE), "Must email about wrong company name!"
@@ -145,12 +146,22 @@ FILE_CONTENTS
145
146
  add_hook("child_repo", "post-commit", TEST_HOOK_BASIC)
146
147
 
147
148
  new_commit("child_repo", "correct_file_single_year.rb", <<FILE_CONTENTS)
148
- # Copyright (C) 2013 YoyoDyne, Inc. All Rights Reserved.
149
+ # Copyright (C) #{CURRENT_YEAR} YoyoDyne, Inc. All Rights Reserved.
149
150
  FILE_CONTENTS
150
151
 
151
152
  assert !File.exist?(MAILER_FILE), "Copyright test must not send email!"
152
153
  end
153
154
 
155
+ def test_copyright_wrong_year
156
+ add_hook("child_repo", "post-commit", TEST_HOOK_COMPANY)
157
+
158
+ new_commit("child_repo", "correct_file.rb", <<FILE_CONTENTS)
159
+ # Copyright (C) 2012 YoyoDyne, Inc. All Rights Reserved.
160
+ FILE_CONTENTS
161
+
162
+ assert File.exist?(MAILER_FILE), "Must email about wrong date!"
163
+ end
164
+
154
165
  def test_copyright_exclude_files
155
166
  add_hook("child_repo", "post-commit", TEST_HOOK_EXCLUDE)
156
167
  new_commit("child_repo", "schema.rb", <<FILE_CONTENTS)
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 OL2, Inc. See LICENSE.txt for details.
1
+ # Copyright (C) 2013-2014 OL2, Inc. See LICENSE.txt for details.
2
2
 
3
3
  require "test_helper"
4
4
  require "ruby_git_hooks/jira_add_comment"
@@ -37,6 +37,7 @@ class JiraCommentAddHookTest < HookTestCase
37
37
  stub(@hook).commit_message { msg }
38
38
  sha = last_commit_sha("child_repo")
39
39
  stub(@hook).commits{[sha]}
40
+ stub(@hook).commit_ref_map{ {sha => ["refs/heads/master"]} } # it's always the master branch
40
41
  Dir.chdir("child_repo") do
41
42
  @hook.check
42
43
  end
@@ -60,7 +61,7 @@ class JiraCommentAddHookTest < HookTestCase
60
61
 
61
62
  def test_bad_reference
62
63
  dont_allow(JiraCommentAddHook).add_comment # check that no comments are added
63
- # because there are no valid tickets
64
+ # because there are no valid tickets
64
65
  mock(RestClient).get("https://user:password@jira.example.com/rest/api/latest/issue/BAD-234") do
65
66
  exc = RestClient::Exception.new
66
67
  mock(exc).http_code.at_least(1) { 404 }
@@ -82,10 +83,28 @@ JSON
82
83
  mock(RestClient).post.with_any_args {<<JSON } # more complicated to check the args, just be sure it's called.
83
84
  { "fields": { "status": { "name": "Open" } } }
84
85
  JSON
85
-
86
+ git_tag("child_repo", "0.1")
86
87
  fake_hook_check("Message with GOOD-234 reference to Jira" )
87
88
 
88
89
  # as long as the mocked RestClient calls happen, we succeeded
90
+ # would be better if we had a way to check if the tag is in the message
91
+ # but at least we'll make sure it doesn't fail.
92
+ end
93
+
94
+ def test_good_reference_with_description
95
+
96
+ mock(RestClient).get("https://user:password@jira.example.com/rest/api/latest/issue/GOOD-234") { <<JSON }
97
+ { "fields": { "status": { "name": "Open" } } }
98
+ JSON
99
+
100
+ mock(RestClient).post.with_any_args {<<JSON } # more complicated to check the args, just be sure it's called.
101
+ { "fields": { "status": { "name": "Open" } } }
102
+ JSON
103
+ # add a tag so describe works
104
+
105
+ fake_hook_check("Message with GOOD-234 reference to Jira" )
106
+
107
+
89
108
  end
90
109
 
91
110
 
@@ -148,4 +167,6 @@ JSON
148
167
  end
149
168
 
150
169
 
170
+
171
+
151
172
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 OL2, Inc. See LICENSE.txt for details.
1
+ # Copyright (C) 2013-2014 OL2, Inc. See LICENSE.txt for details.
2
2
 
3
3
  require "test_helper"
4
4
 
@@ -11,7 +11,7 @@ class MaxFileSizeHookTest < HookTestCase
11
11
  #{RubyGitHooks.shebang}
12
12
  require "ruby_git_hooks/max_file_size"
13
13
 
14
- RubyGitHooks.run MaxFileSizeHook.new(MAX_SIZE)
14
+ RubyGitHooks.run MaxFileSizeHook.new(#{MAX_SIZE})
15
15
  TEST
16
16
 
17
17
  def setup
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 OL2, Inc. See LICENSE.txt for details.
1
+ # Copyright (C) 2013-2014 OL2, Inc. See LICENSE.txt for details.
2
2
 
3
3
  require "test_helper"
4
4
 
@@ -6,6 +6,7 @@ require "minitest/autorun"
6
6
 
7
7
  class CopyrightCheckHookTest < HookTestCase
8
8
  REPOS_DIR = File.expand_path File.join(File.dirname(__FILE__), "repos")
9
+ CURRENT_YEAR = Time.now.strftime("%Y")
9
10
  TEST_HOOK_MULTI_REG = <<TEST
10
11
  #{RubyGitHooks.shebang}
11
12
  require "ruby_git_hooks/ruby_debug"
@@ -45,7 +46,7 @@ TEST
45
46
  last_sha = last_commit_sha
46
47
 
47
48
  new_commit("child_repo", "myfile.rb", <<FILE_CONTENTS)
48
- # Copyright (C) 2013 YoyoDyne, Inc. All Rights Reserved.
49
+ # Copyright (C) #{CURRENT_YEAR} YoyoDyne, Inc. All Rights Reserved.
49
50
  # No copyright notice, no ruby-debug. Should be fine.
50
51
  FILE_CONTENTS
51
52
 
@@ -65,7 +66,7 @@ FILE_CONTENTS
65
66
  assert_raises RuntimeError do
66
67
  new_commit("child_repo", "myfile.rb", <<FILE_CONTENTS)
67
68
  # Includes a copyright notice, but has ruby-debug
68
- # Copyright (C) 2013 YoyoDyne, Inc. All Rights Reserved.
69
+ # Copyright (C) #{CURRENT_YEAR} YoyoDyne, Inc. All Rights Reserved.
69
70
  require 'ruby-debug'
70
71
  FILE_CONTENTS
71
72
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 OL2, Inc. See LICENSE.txt for details.
1
+ # Copyright (C) 2013-2014 OL2, Inc. See LICENSE.txt for details.
2
2
 
3
3
  # Test local copy first
4
4
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
@@ -9,7 +9,7 @@ require "rr"
9
9
  require "ruby_git_hooks"
10
10
  require "ruby_git_hooks/git_ops"
11
11
 
12
- class HookTestCase < MiniTest::Unit::TestCase
12
+ class HookTestCase < MiniTest::Test
13
13
  Hook = RubyGitHooks::Hook
14
14
  include RubyGitHooks::GitOps
15
15
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_git_hooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.32
4
+ version: 0.0.40
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-10-28 00:00:00.000000000 Z
14
+ date: 2014-04-14 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: pony
@@ -205,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
205
  version: '0'
206
206
  requirements: []
207
207
  rubyforge_project:
208
- rubygems_version: 1.8.25
208
+ rubygems_version: 1.8.23
209
209
  signing_key:
210
210
  specification_version: 3
211
211
  summary: DSL and manager for git hooks in Ruby.
@@ -223,4 +223,3 @@ test_files:
223
223
  - test/repos/.keep
224
224
  - test/test_helper.rb
225
225
  - test/watermark_test.rb
226
- has_rdoc: