git-log-time 0.0.1
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.
- checksums.yaml +7 -0
- data/bin/git-log-time +9 -0
- data/lib/git-log-time.rb +2 -0
- data/lib/git-log-time/cli.rb +57 -0
- data/lib/git-log-time/installer.rb +72 -0
- data/templates/hooks/post-commit +54 -0
- data/templates/hooks/pre-push +37 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d964187d34c769eb2aa72705e51cb19fbd24326c
|
4
|
+
data.tar.gz: c4d9abf90f3869c4dbe96fcd01291f64b288f9c8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: afe7cb11aa6da8fb63cd276dc131c1a5a911a2e8f630d93ac21854f14dc72a3606198e47d1e3f3eec81cd9889a3d0adfc2f04ddf8835f4396955fe347f97c28f
|
7
|
+
data.tar.gz: 97dd2dc943628dfb1c969a6088cb78ce4a05425aff492714a3b431b7ece76d56ec1455e8c6554302892a3f2990ea175c21bf2f108661c885072210589cf11bbc
|
data/bin/git-log-time
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'git-log-time'
|
4
|
+
require 'git-log-time/cli'
|
5
|
+
|
6
|
+
repo_root = `git rev-parse --show-toplevel`.strip
|
7
|
+
abort "No .git directory found." unless File.directory?(repo_root)
|
8
|
+
Dir.chdir repo_root
|
9
|
+
GitLogTime::Cli.new(*ARGV).execute or exit 1
|
data/lib/git-log-time.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'git-log-time/installer'
|
3
|
+
|
4
|
+
module GitLogTime
|
5
|
+
|
6
|
+
TemplateNotFound = Class.new(StandardError)
|
7
|
+
|
8
|
+
class Cli
|
9
|
+
|
10
|
+
def initialize(*args)
|
11
|
+
@args = args
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute()
|
15
|
+
action_name = @args.shift or 'help'
|
16
|
+
action = :"execute_#{action_name}"
|
17
|
+
if respond_to?(action)
|
18
|
+
then send(action, *@args)
|
19
|
+
else execute_help(action_name, *@args)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def execute_help(*args)
|
24
|
+
warn "Usage: git-log-time install"
|
25
|
+
warn "Usage: git-log-time uninstall"
|
26
|
+
args.empty? # return status, it's ok if user requested help
|
27
|
+
end
|
28
|
+
|
29
|
+
def execute_install(key = nil, *args)
|
30
|
+
['post-commit', 'pre-push' ].each do |key|
|
31
|
+
GitLogTime::Installer.new(key).install
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def execute_uninstall(key = nil, *args)
|
36
|
+
['post-commit', 'pre-push' ].each do |key|
|
37
|
+
GitLogTime::Installer.new(key).uninstall
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def execute_new(*args)
|
42
|
+
GitLogTime::Template.new(*args).save
|
43
|
+
rescue ArgumentError => e
|
44
|
+
warn e
|
45
|
+
warn "Usage: git-log-time new plugin-name 'Author Name' author@email 'description of the plugin'"
|
46
|
+
end
|
47
|
+
|
48
|
+
def config
|
49
|
+
@config ||= GitLogTime::Configuration.new(GitLogTime.pluginator)
|
50
|
+
end
|
51
|
+
|
52
|
+
def list_evaluator
|
53
|
+
@list_evaluator ||= GitLogTime::ListEvaluator.new(config)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module GitLogTime
|
4
|
+
|
5
|
+
class Installer
|
6
|
+
|
7
|
+
TARGET_GIT_PATH = '.git'
|
8
|
+
TARGET_HOOKS_PATH = 'hooks/'
|
9
|
+
TEMPLATE_DIR = File.expand_path("../../../templates/hooks/", __FILE__)
|
10
|
+
|
11
|
+
attr_reader :key
|
12
|
+
|
13
|
+
def initialize(key = nil)
|
14
|
+
@key = key || "default"
|
15
|
+
end
|
16
|
+
|
17
|
+
def hook
|
18
|
+
templates[key.sub(/^--/, "")]
|
19
|
+
end
|
20
|
+
|
21
|
+
def target
|
22
|
+
target_git_path =
|
23
|
+
if File.directory?(TARGET_GIT_PATH)
|
24
|
+
then TARGET_GIT_PATH
|
25
|
+
else File.readlines('.git').first.match(/gitdir: (.*)$/)[1]
|
26
|
+
end
|
27
|
+
File.join(target_git_path, (TARGET_HOOKS_PATH + key))
|
28
|
+
end
|
29
|
+
|
30
|
+
def install
|
31
|
+
if
|
32
|
+
hook
|
33
|
+
then
|
34
|
+
FileUtils.cp(target, target+ ".backup") if File.exist?(target)
|
35
|
+
FileUtils.mkdir_p(File.dirname(target))
|
36
|
+
FileUtils.cp(hook, target)
|
37
|
+
FileUtils.chmod(0755, target)
|
38
|
+
puts "Installed #{hook} to #{target}"
|
39
|
+
true
|
40
|
+
else
|
41
|
+
warn "Could not find template #{key}"
|
42
|
+
false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def uninstall
|
47
|
+
back_up_path = target+ ".backup"
|
48
|
+
if File.exist?(back_up_path)
|
49
|
+
FileUtils.mv(back_up_path, target)
|
50
|
+
puts "Installed #{back_up_path} to #{target}"
|
51
|
+
else
|
52
|
+
puts "Git-log-time not Installed"
|
53
|
+
end
|
54
|
+
true
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def templates
|
60
|
+
return @templates if @templates
|
61
|
+
pattern = File.join(TEMPLATE_DIR, "*")
|
62
|
+
|
63
|
+
@templates =
|
64
|
+
Dir.glob(pattern).inject({}) do |hash, file|
|
65
|
+
key = file.match(/\/([^\/]+?)$/)[1]
|
66
|
+
hash[key] = file
|
67
|
+
hash
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
STDIN.reopen('/dev/tty')
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class String
|
6
|
+
def red; "\e[31m#{self}\e[0m" end
|
7
|
+
def green; "\e[32m#{self}\e[0m" end
|
8
|
+
end
|
9
|
+
|
10
|
+
begin
|
11
|
+
puts "Please enter the time spent for this commit:"
|
12
|
+
time = Integer(gets) rescue false
|
13
|
+
puts "Please enter Integer".red unless time
|
14
|
+
end until time
|
15
|
+
|
16
|
+
puts "Thanks for logging the time -> #{time}".green
|
17
|
+
outputfile="#{Dir.pwd}/.git/hooks/outputfile.json"
|
18
|
+
origin_url = `git config --get remote.origin.url`
|
19
|
+
unless (origin_url.include?('https://') || origin_url.include?('http://'))
|
20
|
+
origin_url = origin_url.gsub("git@", "http://").gsub(".git","").gsub(".com:", ".com/")
|
21
|
+
else
|
22
|
+
origin_url = origin_url.gsub(".git","")
|
23
|
+
end
|
24
|
+
commit_id = `git log --format='%H' -n 1`.chomp.strip
|
25
|
+
commit_url = origin_url+"/commit/#{commit_id}"
|
26
|
+
commit_info={
|
27
|
+
"id"=> commit_id,
|
28
|
+
"tree_id"=> `git log --format='%T' -n 1`.chomp.strip,
|
29
|
+
"message"=> `git log --format='%s' -n 1`.chomp.strip,
|
30
|
+
"timestamp"=> `git log --format='%ad' -n 1`.chomp.strip,
|
31
|
+
"url"=> commit_url,
|
32
|
+
"author"=> {
|
33
|
+
"name"=> `git log --format='%an' -n 1`.chomp.strip,
|
34
|
+
"email"=> `git log --format='%ae' -n 1`.chomp.strip,
|
35
|
+
},
|
36
|
+
"committer"=> {
|
37
|
+
"name"=> `git log --format='%cn' -n 1`.chomp.strip,
|
38
|
+
"email"=> `git log --format='%ce' -n 1`.chomp.strip,
|
39
|
+
},
|
40
|
+
"commit_time"=> time,
|
41
|
+
"origin_url"=> origin_url,
|
42
|
+
"modified"=> [`git diff-tree --no-commit-id --name-only -r "#{commit_id}"`.chomp.strip.split("\n")]
|
43
|
+
}
|
44
|
+
if File.exist?(outputfile)
|
45
|
+
commit_infos = JSON.parse(IO.read(outputfile)).map{|cm| cm.to_json }
|
46
|
+
commit_infos << commit_info.to_json
|
47
|
+
File.open(outputfile, 'w') {
|
48
|
+
| f| f.write("#{commit_infos}")
|
49
|
+
}
|
50
|
+
else
|
51
|
+
File.open(outputfile, 'a') {
|
52
|
+
| f| f.write("[#{commit_info.to_json}]")
|
53
|
+
}
|
54
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
require 'uri'
|
5
|
+
require 'dotenv'
|
6
|
+
Dotenv.load
|
7
|
+
|
8
|
+
class String
|
9
|
+
def red; "\e[31m#{self}\e[0m" end
|
10
|
+
def green; "\e[32m#{self}\e[0m" end
|
11
|
+
end
|
12
|
+
|
13
|
+
outputfile="#{Dir.pwd}/.git/hooks/outputfile.json"
|
14
|
+
begin
|
15
|
+
if File.exist?(outputfile)
|
16
|
+
puts "Sending commits to spritle dashboard .......".green
|
17
|
+
origin_url = `git config --get remote.origin.url`
|
18
|
+
unless (origin_url.include?('https://') || origin_url.include?('http://'))
|
19
|
+
origin_url = origin_url.gsub("git@", "http://").gsub(".git","").gsub(".com:", ".com/")
|
20
|
+
else
|
21
|
+
origin_url = origin_url.gsub(".git","")
|
22
|
+
end
|
23
|
+
log_time_values = {"commits" => [], "origin_url" => origin_url }
|
24
|
+
log_time_values["commits"] = File.read(outputfile)
|
25
|
+
url = ENV["GIT_LOG_TIME_CALLBACK_URL"]
|
26
|
+
uri = URI.parse(url)
|
27
|
+
data = {"name" => "tbone"}
|
28
|
+
headers = {"Content-Type" => "application/json"}
|
29
|
+
http = Net::HTTP.new(uri.host,uri.port)
|
30
|
+
response = http.post(uri.path,log_time_values.to_json,headers)
|
31
|
+
if response.body["success"]
|
32
|
+
File.delete(outputfile)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
rescue => e
|
36
|
+
puts "#{e}".red
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-log-time
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Siva
|
8
|
+
- Suren
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-06-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: dotenv-rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.0'
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.2
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - "~>"
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '1.0'
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.2
|
34
|
+
description: git log time is used get time from user for each commit
|
35
|
+
email:
|
36
|
+
- siva.kb@spritle.com
|
37
|
+
- surendrans@spritle.com
|
38
|
+
executables:
|
39
|
+
- git-log-time
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- bin/git-log-time
|
44
|
+
- lib/git-log-time.rb
|
45
|
+
- lib/git-log-time/cli.rb
|
46
|
+
- lib/git-log-time/installer.rb
|
47
|
+
- templates/hooks/post-commit
|
48
|
+
- templates/hooks/pre-push
|
49
|
+
homepage: https://github.com/sivakb/git-log-time
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata: {}
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 2.4.5
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: git log time
|
73
|
+
test_files: []
|