mirror of
https://github.com/adulau/gitlog2timesheet.git
synced 2024-12-22 08:36:02 +00:00
Merge pull request #1 from nseinlet/master
improvement from nseinlet to ensure that the last commit message is not already processed to avoid duplicate counting when you commit more often than the commit factor (default 4 hours).
This commit is contained in:
commit
46f023fb56
2 changed files with 37 additions and 12 deletions
|
@ -22,6 +22,8 @@ Usage
|
||||||
-f FORMAT, --outputformat=FORMAT
|
-f FORMAT, --outputformat=FORMAT
|
||||||
output format text, csv (default is text)
|
output format text, csv (default is text)
|
||||||
-u USER, --user=USER limit timesheet to the user specified
|
-u USER, --user=USER limit timesheet to the user specified
|
||||||
|
-p, --previouslog user previous date, or work time factor if less,
|
||||||
|
for commit duration
|
||||||
|
|
||||||
|
|
||||||
Sample output
|
Sample output
|
||||||
|
|
|
@ -38,21 +38,40 @@ def gitlog(location = None):
|
||||||
def logmessage(name = None, email = None, when = None, message = None, repo = None, commitfactor = 4, format="text"):
|
def logmessage(name = None, email = None, when = None, message = None, repo = None, commitfactor = 4, format="text"):
|
||||||
logmessage = ""
|
logmessage = ""
|
||||||
t=datetime.datetime.fromtimestamp(when)
|
t=datetime.datetime.fromtimestamp(when)
|
||||||
d=t-datetime.timedelta(hours=commitfactor)
|
nonecalculated = True
|
||||||
|
if options.previouslog:
|
||||||
|
prevlogkey = name
|
||||||
|
if prevlogkey in prevlogs:
|
||||||
|
nonecalculated = False
|
||||||
|
d=max(prevlogs[prevlogkey],t-datetime.timedelta(hours=commitfactor))
|
||||||
|
#print unicode(prevlogs[prevlogkey])+"|"+unicode(t-datetime.timedelta(hours=commitfactor))+"|"+unicode(d)
|
||||||
|
|
||||||
|
if nonecalculated:
|
||||||
|
d=t-datetime.timedelta(hours=commitfactor)
|
||||||
|
|
||||||
if options.total:
|
if options.total:
|
||||||
projectkey= repo+":"+name
|
if options.previouslog:
|
||||||
if projectkey in projecttime:
|
timetoadd=((t-d).seconds/3600.0)
|
||||||
projecttime[projectkey] += commitfactor
|
|
||||||
else:
|
else:
|
||||||
projecttime[projectkey] = commitfactor
|
timetoadd=commitfactor
|
||||||
|
|
||||||
|
projectkey= repo+":"+name
|
||||||
|
|
||||||
|
if projectkey in projecttime:
|
||||||
|
projecttime[projectkey] += timetoadd
|
||||||
|
else:
|
||||||
|
projecttime[projectkey] = timetoadd
|
||||||
|
|
||||||
|
if options.previouslog:
|
||||||
|
prevlogkey= name
|
||||||
|
prevlogs[prevlogkey]=t
|
||||||
|
|
||||||
if format == "text":
|
if format == "text":
|
||||||
logmessage = "From "+d.ctime()+" to "+t.ctime() + "\n"
|
logmessage = "From "+d.ctime()+" to "+t.ctime() + "\n"
|
||||||
logmessage += " "+name+" ("+email+") worked on "+ repo +"\n"
|
logmessage += " "+name+" ("+email+") worked on "+ repo +"\n"
|
||||||
logmessage += " and did the following: "+ message
|
logmessage += " and did the following: "+ message
|
||||||
elif format == "csv":
|
elif format == "csv":
|
||||||
logmessage = d.ctime()+"|"+t.ctime()+"|"+unicode(commitfactor)+"|"+name+"|"+message
|
logmessage = d.ctime()+"|"+t.ctime()+"|"+unicode(round(timetoadd,2))+"|"+name+"|"+message
|
||||||
return logmessage
|
return logmessage
|
||||||
|
|
||||||
usage = "usage: %s path_to_git_repos" % sys.argv[0]
|
usage = "usage: %s path_to_git_repos" % sys.argv[0]
|
||||||
|
@ -62,19 +81,23 @@ parser.add_option("-w", "--commitfactor", dest="commitfactor", help="work time f
|
||||||
parser.add_option("-t", "--total", action="store_true", dest="total", help="total hours worked for each user per repository/project", default=False)
|
parser.add_option("-t", "--total", action="store_true", dest="total", help="total hours worked for each user per repository/project", default=False)
|
||||||
parser.add_option("-f", "--outputformat", dest="format", help="output format text, csv (default is text)", default="text", type="string")
|
parser.add_option("-f", "--outputformat", dest="format", help="output format text, csv (default is text)", default="text", type="string")
|
||||||
parser.add_option("-u", "--user", dest="user", help="limit timesheet to the user specified", default=None, type="string")
|
parser.add_option("-u", "--user", dest="user", help="limit timesheet to the user specified", default=None, type="string")
|
||||||
|
parser.add_option("-p", "--previouslog", action="store_true", dest="previouslog", help="user previous date, or work time factor if less, for commit duration", default=False)
|
||||||
|
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
if options.total:
|
if options.total:
|
||||||
projecttime = {}
|
projecttime = {}
|
||||||
|
|
||||||
|
if options.previouslog:
|
||||||
|
prevlogs={}
|
||||||
|
|
||||||
for repo in args:
|
for repo in args:
|
||||||
if not os.path.exists(repo):
|
if not os.path.exists(repo):
|
||||||
continue
|
continue
|
||||||
val = gitlog(location = repo)
|
val = gitlog(location = repo)
|
||||||
if options.debug:
|
if options.debug:
|
||||||
print val
|
print val
|
||||||
for line in val:
|
for line in reversed(val):
|
||||||
try:
|
try:
|
||||||
(name, email, when, message) = line.split("|")
|
(name, email, when, message) = line.split("|")
|
||||||
except:
|
except:
|
||||||
|
@ -87,6 +110,6 @@ for repo in args:
|
||||||
if options.total:
|
if options.total:
|
||||||
for x in projecttime:
|
for x in projecttime:
|
||||||
if options.format == "text":
|
if options.format == "text":
|
||||||
print x + "->" + unicode(projecttime[x])+" hours."
|
print x + "->" + unicode(int(round(projecttime[x],0)))+" hours."
|
||||||
elif options.format == "csv":
|
elif options.format == "csv":
|
||||||
print x.split(":")[0]+"|"+x.split(":")[1]+"|"+unicode(projecttime[x])
|
print x.split(":")[0]+"|"+x.split(":")[1]+"|"+unicode(int(round(projecttime[x],0)))
|
||||||
|
|
Loading…
Reference in a new issue