Module: Murmurs::Git
- Included in:
- Murmurs
- Defined in:
- lib/murmurs/git.rb
Instance Method Summary collapse
-
#git_commits(input, branch) ⇒ Object
input: git post receive stdin string branch: git branch.
- #git_hooks_dir(git_repo_dir) ⇒ Object
- #install_git_hook(git_dir, script) ⇒ Object
Instance Method Details
#git_commits(input, branch) ⇒ Object
input: git post receive stdin string branch: git branch
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/murmurs/git.rb', line 43 def git_commits(input, branch) data = input.split("\n").map do |l| l.split end.find do |l| l[2] =~ /\Arefs\/heads\/#{branch}\z/ end return if data.nil? null_rev = '0' * 40 from_rev, to_rev, _ = data if to_rev == null_rev # delete branch "Someone deleted branch #{branch}." else repo_name = File.basename(Dir.getwd) revs = if from_rev == null_rev # new branch to_rev else "#{from_rev}..#{to_rev}" end `git rev-list #{revs}`.split("\n").map do |rev| `git log -n 1 #{rev}` end.reverse.map do |msg| lines = msg.split("\n") commit = lines[0][8..20] = lines[1] time = lines[2] msg = lines[3..-1] <<-MURMUR #{} #{msg.join("\n").strip} commit #rev-#{commit} (#{repo_name}) #{time} MURMUR end end end |
#git_hooks_dir(git_repo_dir) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/murmurs/git.rb', line 5 def git_hooks_dir(git_repo_dir) hooks = File.join(git_repo_dir, 'hooks') if File.exists?(hooks) hooks else hooks = File.join(git_repo_dir, '.git', 'hooks') if File.exists?(hooks) hooks else raise "Could not find \"hooks\" dir or \".git/hooks\" dir in #{git_repo_dir}" end end end |
#install_git_hook(git_dir, script) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/murmurs/git.rb', line 19 def install_git_hook(git_dir, script) hooks = git_hooks_dir(git_dir) hook = File.join(hooks, 'post-receive') if File.exists?(hook) raise HookExistsError, "There is #{hook} file existing, please backup / remove it." end File.open(hook, 'w') do |f| f.write <<-BASH #!/usr/bin/env bash mingle_murmurs_url=$(git config hooks.minglemurmursurl) mingle_access_key_id=$(git config hooks.mingleaccesskeyid) mingle_access_secret_key=$(git config hooks.mingleaccesssecretkey) echo "$(cat)" | #{script.inspect} -g -b master -m "$mingle_murmurs_url" -k "$mingle_access_key_id" -s "$mingle_access_secret_key" BASH end FileUtils.chmod('+x', hook) hook end |