Darkyenus / DarkyenusTimeTracker

Lightweight time tracker for IntelliJ platform IDEs
The Unlicense
49 stars 13 forks source link

Get total time spend in git commit message #41

Closed baptistebisson closed 3 years ago

baptistebisson commented 3 years ago

Hi !

First thanks for this great plugin.

I would like to know if there is any included way to add the total time spent in the project in the commit message. I've looked in the helper but it doesn't seem to have this possibility.

Darkyenus commented 3 years ago

There is currently no such functionality. What is your use-case for this?

baptistebisson commented 3 years ago

There is currently no such functionality. What is your use-case for this?

I charge by the time spent. So it's easier to see at each commit the time spent since the beginning rather than having to add up all the commits.

I guess that if this is not the most common case, there is no chance to add this feature ?

Maybe I could try to create a git hook that parse the file .idea/workspace.xml and then add it to the commit message.

Darkyenus commented 3 years ago

Parsing xml from POSIX shell is not an easy task. Since you are charging by the time spent, why don't you use the IDE timer, which serves this exact use case? That is what I do.

baptistebisson commented 3 years ago

Well, it's pretty easy:

➜  Project git:(master) ✗ cat .idea/workspace.xml | grep totalTimeSeconds | grep -Pio 'value="\K\d+'
96192

You're talking about the time tracking functionnality ? https://www.jetbrains.com/help/phpstorm/managing-tasks-and-context.html#time_tracking

It's really linked to Tasks and I'm not using the task system.

EDIT - Found a solution

Like I was saying previously, we can parse the workspace.xml file and retrieve the total in seconds. I just needed to add a commit-msg hook in my git repository:

#!/bin/sh
secs=$(cat .idea/workspace.xml | grep totalTimeSeconds | grep -Pio 'value="\K\d+')

TOTAL=$(printf '%02dh:%02dm:%02ds\n' $((secs/3600)) $((secs%3600/60)) $((secs%60)))

printf "

Time spent: $TOTAL" >> $1

Found the time converter here: https://stackoverflow.com/a/39452629/5003342 (thanks to Cascabel). The time spent was correctly added to my commit message:

My commit message

Time spent: 27h:01m:58s
Darkyenus commented 3 years ago

I am not using any built-in time tracking. I was talking about the time shown on the plugins widget in the status bar.

Yes, it is easy to parse the XML as long as the exact format does not change and the exact string does not appear multiple times in the document, or there are no XML entities and so on. So it is very fragile.

But since you have found your workaround, I am closing this.