Feature #4155

Automatic spent time logging from commit messages

Added by Marek Siller about 8 years ago. Updated over 5 years ago.

Status:ClosedStart date:2009-11-02
Priority:NormalDue date:
Assignee:Jean-Philippe Lang% Done:

100%

Category:Time tracking
Target version:1.1.0
Resolution:

Description

We have created a small patch for redmine that enables automatic logging of spent time via commit messages of a versioning system.

Use case

This patch allows users to log the spent time automatically along with commiting their work to the SCM. It works in a similar way like referencing or closing issues via commit messages. For example:

Fixed some issue with menu. 

refs #1234 @2h30m

The user does not have to visit the redmine site just to log the spent time any more.

Features

  • Support for both ways of referencing issues - with keywords (refs, fixes, ...) and with wildcard.
  • Possibility to turn the feature on or off (default is the original behavior of redmine).
  • Support for two time formats: as a floating point number (i. e. 2.5) or as a string (i. e. 2h30m or 2h 30m). Time specification must follow the issue reference (blanks allowed). Examples
    refs #1234 @2.5
    references #1234 @2h30m
    fixes #1234 @2h 30m
    
  • Date of logged spent time - date of commit.
  • Owner of logged spent time - user mapped to the SCM account the commit belongs to.
  • Uses default (or the first found if no default set) activity for spent time logging.
  • Comment for logged spent time includes the revision number.

Patch

Tested with Redmine 0.8.5 and the latest development version (both patches included). Tested SCM include Subversion and git.

Patched files

  • app/models/changeset.rb
  • app/views/settings/_repositories.rhtml
  • config/settings.yml (new configuration option: Enable spent time logging)
  • + language files (two new messages - setting_commit_logtime_enabled and text_commit_logtime) - already translated to German and Czech

Any feedback or question is welcome!

Sincerelly Yours,

Marek Siller
Karlsruhe Technology Consulting

LogTime-v1-redmine-0.8.5.patch Magnifier - Patch for version 0.8.5 (27.8 KB) Marek Siller, 2009-11-02 16:45

LogTime-v1-redmine-devel.patch Magnifier - Patch for trunk version (30.2 KB) Marek Siller, 2009-11-02 16:45

LogTime-v2-redmine-0.8.x.patch Magnifier - Patch for version 0.8.x (tested on 0.8.5 and 0.8.6) (27.8 KB) Marek Siller, 2009-11-04 16:46

LogTime-v2-redmine-devel.patch Magnifier - Patch for trunk version (30.2 KB) Marek Siller, 2009-11-04 16:46

LogTime-v2.1-redmine-0.8.x.patch Magnifier - Patch for version 0.8.x (tested on 0.8.5 and 0.8.6) - corrected version (27.8 KB) Marek Siller, 2009-11-06 18:09

LogTime-v2.1-redmine-devel.patch Magnifier - Patch for trunk version - corrected version (30.2 KB) Marek Siller, 2009-11-06 18:09

LogTime-v2.1-redmine-devel.patch Magnifier - Patch for trunk version - corrected version (30.2 KB) Marek Siller, 2009-11-06 18:45

logtime_redmine_0.9.2.patch Magnifier (22.3 KB) Vladimir Kovacik, 2010-02-18 14:00

logtime_redmine_0.9.2_v2.2.patch Magnifier (22.3 KB) Vladimir Kovacik, 2010-03-04 10:13

logtime_redmine_0.9.2_v2.3.patch Magnifier (22.7 KB) Katy A, 2010-05-25 01:45

logtime_redmine_0.9.3_v2.3.patch Magnifier (22.2 KB) Paul Widden, 2010-09-01 19:33

logtime_redmine_1.0.3-v3.patch Magnifier (114 KB) Marek Siller, 2010-11-09 20:13

fix-scmid-all-number.diff Magnifier (1.8 KB) Toshi MARUYAMA, 2010-12-11 14:51


Related issues

Related to Redmine - Feature #1518: Log time via commit messages Closed 2008-06-23
Related to Redmine - Defect #7630: Spent time in commits not recognized Closed 2011-02-15

Associated revisions

Revision 4470
Added by Jean-Philippe Lang almost 7 years ago

Automatic spent time logging from commit messages (#4155).

History

#1 Updated by Marek Siller about 8 years ago

The biggest difference between this patch / feature and the related feature #1518 is that the syntax in commit message is (in my opinion) a little bit simpler (no new keywords, just an at-sign) and it allows the developer explicit specification of the spent time for each referenced issue - for instance

Completed implementation of two new features: refs #1518 @3h 40m #4155 @6h

#2 Updated by Kamil . about 8 years ago

Looks very interesting!

#3 Updated by Marek Siller about 8 years ago

New set of patches for this feature.

Changelog:

  • Tested with new Redmine release 0.8.6
  • Bug fix - crash when only minutes were logged as spent time, for example: Fixed bug #123 @30m

#4 Updated by Jean-Philippe Lang about 8 years ago

I think this feature should be added in 0.9.

Another patch for this feature was already submitted in #1518.
Please have a look at its description: http://www.redmine.org/issues/1518#note-14

Here is an exemple:

refs #1
ratio 50
time 1,0
timelogcomment comment for this timelog

I have to admit that I prefer the shorter syntax:

refs #1234 @2.5
references #1234 @2h30m
fixes #1234 @2h 30m

What do you think? Any suggestion is welcome.

#5 Updated by Robert Chady about 8 years ago

Personally, I prefer the the shorter syntax, not only for its use, but simplicity of the patch. For those that want something other than the '@' token, it should be possible to make this a settable option (which token or string to use).

The only other option I see that would be nice is to be able to make the comment get updated in the journal AND the comment if possible -- or something similar. I would not want to see a bunch of things getting inserted via comments and not show up in the journal as well from this.

#6 Updated by Jonas von Andrian about 8 years ago

Hi,
I started the other patch.

I like the shorter syntax, but this patch lacks another feature, which might be nice to have: Assigning ratios via commit messages.
Plus it has no tests.

Apart from that I would prefer this patch, since it's up to date.

#7 Updated by Marek Siller about 8 years ago

Thanks for the feedback!

Robert Chady wrote:

Personally, I prefer the the shorter syntax, not only for its use, but simplicity of the patch. For those that want something other than the '@' token, it should be possible to make this a settable option (which token or string to use).

I will add the new setting in next version of this patch. You're right, it'd be nice if redmine users could define their own token / keyword for spent time logging.

The only other option I see that would be nice is to be able to make the comment get updated in the journal AND the comment if possible -- or something similar. I would not want to see a bunch of things getting inserted via comments and not show up in the journal as well from this.

I will investigate how this can be done.

Jonas von Andrian wrote:

Hi,
I started the other patch.

I like the shorter syntax, but this patch lacks another feature, which might be nice to have: Assigning ratios via commit messages.

Unfortunately, I have no idea, what you mean with assigning ratios via commit messages - could you ellaborate on this subject, please.

Plus it has no tests.

You're right, there are no tests right now, I'm planning on including them in the next version of the patch.

Apart from that I would prefer this patch, since it's up to date.

#8 Updated by Erik Lindblom about 8 years ago

Marek,

I applied the patch, but I'm having issues with it.

Here is the top of the error log:

NoMethodError (undefined method `match' for 0:Fixnum):
  app/models/changeset.rb:144:in `scan_comment_for_issue_ids'
  app/models/changeset.rb:138:in `each'
  app/models/changeset.rb:138:in `scan_comment_for_issue_ids'
  app/models/changeset.rb:70:in `after_create'
  app/models/repository/subversion.rb:59:in `fetch_changesets'
  app/models/repository/subversion.rb:58:in `fetch_changesets'
  app/models/repository/subversion.rb:57:in `reverse_each'
  app/models/repository/subversion.rb:57:in `fetch_changesets'
  app/controllers/repositories_controller.rb:70:in `show'

Any ideas?

I have my "Referencing keywords" set to "*" because I just commit with "(#idnumber)"

#9 Updated by Marek Siller about 8 years ago

Erik Lindblom wrote:

Marek,

I applied the patch, but I'm having issues with it.

Here is the top of the error log:

[...]

Any ideas?

I have my "Referencing keywords" set to "*" because I just commit with "(#idnumber)"

Thanks for letting me know about the bug.

I'll investigate the source of the problem and let you know. Which redmine version do you use and which patch have you applied (version 1 or the updated version 2)?

#10 Updated by Erik Lindblom about 8 years ago

Version: 0.8.6.devel.3009
Patch v22

#11 Updated by Marek Siller about 8 years ago

Erik Lindblom wrote:

Version: 0.8.6.devel.3009
Patch v22

I've found the problem and fixed it. New set of patches included. Could you test it and let me know whether it solves your problem, please?

#12 Updated by Erik Lindblom about 8 years ago

Marek Siller wrote:

Erik Lindblom wrote:

Version: 0.8.6.devel.3009
Patch v22

I've found the problem and fixed it. New set of patches included. Could you test it and let me know whether it solves your problem, please?

Tested it and still get an error, here is the log:

ArgumentError (wrong number of arguments (1 for 0)):
  app/models/changeset.rb:164:in `default'
  app/models/changeset.rb:164:in `scan_comment_for_issue_ids'
  app/models/changeset.rb:138:in `each'
  app/models/changeset.rb:138:in `scan_comment_for_issue_ids'
  app/models/changeset.rb:70:in `after_create'
  app/models/repository/subversion.rb:59:in `fetch_changesets'
  app/models/repository/subversion.rb:58:in `fetch_changesets'
  app/models/repository/subversion.rb:57:in `reverse_each'
  app/models/repository/subversion.rb:57:in `fetch_changesets'
  app/controllers/repositories_controller.rb:70:in `show'

#13 Updated by Marek Siller about 8 years ago

Sorry, I made a mistake while creating the patch for the devel version. Corrected version in attachement.

#14 Updated by Erik Lindblom about 8 years ago

Great. Thanks! It applies now with no errors, however, none of the time shows up on the tickets.

I've tried (#112) @2 and even the older one, refs #112 @2 and neither of them log time against the ticket.

Is there any more configuration I need besides the option on the administration screen?

Thanks for your time on this!

#15 Updated by Leonard Brünings about 8 years ago

Erik Lindblom wrote:

I've tried (#112) @2 and even the older one, refs #112 @2 and neither of them log time against the ticket.

Try either @2.0 or @2h

#16 Updated by Erik Lindblom about 8 years ago

Just tried this with no luck:

testing (#362) @2h

#17 Updated by Mischa The Evil about 8 years ago

Erik Lindblom wrote:

Just tried this with no luck:

testing (#362) @2h

I think this is due to the used parentheses in you syntax. Probably

testing #362 @2h
works...

#18 Updated by Erik Lindblom about 8 years ago

Mischa The Evil wrote:

Erik Lindblom wrote:

Just tried this with no luck:

[...]

I think this is due to the used parentheses in you syntax. Probably [...] works...

Very odd, I've tried it with that syntax and still nothing. I've also tried on a clean checkout and still doesn't work. There is nothing in the logs as well :/

If anyone has any suggestions, I would love to hear them.

#19 Updated by Jean-Philippe Lang about 8 years ago

Adding a few tests in this patch would lower the noise.

#20 Updated by Jonas von Andrian about 8 years ago

Marek Siller wrote:

Jonas von Andrian wrote:

I like the shorter syntax, but this patch lacks another feature, which might be nice to have: Assigning ratios via commit messages.

Unfortunately, I have no idea, what you mean with assigning ratios via commit messages - could you ellaborate on this subject, please.

It's possible to set a percentage (ratio to 1) how far the ticket has progressed (% Done). I think it would be nice to be able to set that too via the commit message.

#21 Updated by Chris Platts almost 8 years ago

Erik Lindblom wrote:

Mischa The Evil wrote:

Erik Lindblom wrote:

Just tried this with no luck:

[...]

I think this is due to the used parentheses in you syntax. Probably [...] works...

Very odd, I've tried it with that syntax and still nothing. I've also tried on a clean checkout and still doesn't work. There is nothing in the logs as well :/

If anyone has any suggestions, I would love to hear them.

Hi,

Just for info, I'm seeing this problem behaviour too - patch apparently applies OK, but time entries are not logged. I'm running the latest SVN version as of today (0.8.7.devel.3111)

Cheers,
Chris

#22 Updated by Sachin Khandelwal almost 8 years ago

Chris Platts wrote:

Erik Lindblom wrote:

Mischa The Evil wrote:

Erik Lindblom wrote:

Just tried this with no luck:

[...]

I think this is due to the used parentheses in you syntax. Probably [...] works...

Very odd, I've tried it with that syntax and still nothing. I've also tried on a clean checkout and still doesn't work. There is nothing in the logs as well :/

If anyone has any suggestions, I would love to hear them.

Hi,

Just for info, I'm seeing this problem behaviour too - patch apparently applies OK, but time entries are not logged. I'm running the latest SVN version as of today (0.8.7.devel.3111)

Cheers,
Chris

Hi,

I'm trying to apply the below mentioned patch to redmine source checkout from "http://redmine.rubyforge.org/svn/tags/0.8.6" using TortoiseSVN.

"LogTime-v2.1-redmine-0.8.x.patch - Patch for version 0.8.x (tested on 0.8.5 and 0.8.6) - corrected version (27.8 KB) Marek Siller, 2009-11-06 22:39"

Its giving error "The line indicating the new file is expected in line 3". The format of your patch file seems little different from normal. Please help me to track where I'm going wrong.

Regards,
Sachin

#23 Updated by Renzo Meister almost 8 years ago

Hi,
I've installed it and after some trial and errors it works fine.
But for my use there is one "bug" or better a feature wish.
I'm working with subprojects so it must be possible to log time for a ticket which is in another project.

I think the problem is in changeset.rb:
...
timeentry = TimeEntry.create(:project => repository.project,
:issue => issue,
...
Here it uses the project of current repository but for me it's better to use the project of the issue.
Does anybody know how I get the project of my issue and use it?

Regards
Renzo

#24 Updated by Vladimir Kovacik almost 8 years ago

Since last released patch (LogTime-v2.1-redmine-devel.patch) does not apply correctly on the latest Redmine trunk I have updated the patch and tested on Redmine 0.9.2 (@3412)

The main issue was related to the following part:

+         if activity == nil
+           activity = TimeEntryActivity.values[0]
+         end

There was also an issue with time getting logged twice when [Referencing keywords] is set to "*". This happens because log_time variable got first time filled when handling "ref_keywords=*" and second time when handling ref+fix keywords. This is fixed in the attached patch.

#25 Updated by Tomasz Sawicki over 7 years ago

Very nice feature, thank you for contributing.

Another nice thing would be possibility to log the time without referencing particular issue, like:

- doing some cleanups 
@2h30m

so I can log the time spent on something that is not in any issue.
It's just like filling Spent time form without providing issue Id.

#26 Updated by Tomasz Sawicki over 7 years ago

After applying the patch you must include the "spent time" part, otherwise reference to issue will be ignored. Following won't work anymore:

refs #4155

To fix that following line:

target_issues_with_log = match[1].scan(/([\s,;&]*([^@]|#?)\d+)([\s]*@(\d+[.]\d+|(\d+[hm]\s?){1,2}))/)


should be changed to:
target_issues_with_log = match[1].scan(/([\s,;&]*([^@]|#?)\d+)([\s]*@(\d+[.]\d+|(\d+[hm]\s?){1,2}))?/)


(additional question mark near the end of line)

#27 Updated by Vladimir Kovacik over 7 years ago

Thanks for pointing this issue out. The updated patch is included. Now issue reference is handled correctly even when "Time Spent" is not included and Referencing keywords are defined (different than *, e.g. refs).

#28 Updated by Simon Dyson over 7 years ago

Is there a version of this patch compatible with Redmine 0.9.3?

#29 Updated by Katy A over 7 years ago

Here it uses the project of current repository but for me it's better to use the project of the issue.
Does anybody know how I get the project of my issue and use it?

The updated patch is considering the project of the issue and work with subprojects too.

#30 Updated by David Parker over 7 years ago

+1. prefer this syntax to #1518

#31 Updated by Dominic Clifton over 7 years ago

+1 for this syntax.

#32 Updated by Paul Widden about 7 years ago

Patch for 0.9.3

#33 Updated by Dominic Clifton about 7 years ago

Does the current patch apply on 1.0.3 or is a new one required?

When will this be integrated into trunk or is there other similar functionality that should be used instead?

#34 Updated by Dominic Clifton about 7 years ago

Current patch applies with:

cd /path/to/redmine
wget http://www.redmine.org/attachments/download/4410/logtime_redmine_0.9.3_v2.3.patch
patch -p 0 -F 3 < logtime_redmine_0.9.3_v2.3.patch

My other questions above still stand.

#35 Updated by Marek Siller about 7 years ago

I have created new version of the log spent time patch. The new features are:
  • corrected regular expressions for spent time logging
  • function scan_comment_for_issue_ids split into several functions for easier reading and to make it testable
  • set of tests that check the functionality
  • logging of spent time creates a new journal entry (activity) associated with the referenced issue (can be switched off in settings)
  • the activity type (e.g. Development, Design) the spent time is logged on, can be configured in the settings

The patch has been tested both with experimental subversion setup as well as with the test suite, all tests were successful. Tested with stable version of Redmine (1.0.3) and development version from trunk.

Every feedback regarding the patch and / or feature requests would be greatly appreciated.

Is there any chance, this patch makes it to the main repository of Redmine? What needs to be done in order to get it in the main repository?

#36 Updated by Jean-Philippe Lang about 7 years ago

  • Category changed from SCM to Time tracking
  • Assignee set to Jean-Philippe Lang
  • Target version set to 1.1.0

I'll review your patch as soon as possible.

#37 Updated by Jean-Philippe Lang about 7 years ago

  • Tracker changed from Patch to Feature

#38 Updated by Ivan Cenov almost 7 years ago

I am translating this to Bulgarian and have a question:

text_time_logged_by_changeset: Applied in changeset {{value}}.

What kind is the value of value ? What information does it comprises of?

Ivan

#39 Updated by Marek Siller almost 7 years ago

The value includes the revision number from the commit / changeset - for example r123 for revision 123.

Marek

Ivan Cenov wrote:

I am translating this to Bulgarian and have a question:
[...]

What kind is the value of value ? What information does it comprises of?

Ivan

#40 Updated by Toshi MARUYAMA almost 7 years ago

r4470 have implemented #6681 feature.
But, if commit id is all numeric (e.g. "0123456789"), auto close text become "Applied in changeset r0123456789".

I attach the patch to fix this problem.
This patch include unit test.

#41 Updated by Jean-Philippe Lang almost 7 years ago

  • Status changed from New to Closed
  • % Done changed from 90 to 100

Implementation was rewritten based on the provided patch.
A few things were changed/removed for consistency (like notes in the issue history, as they are not added when logging time through the UI).

Basically, it works as expected. The syntax is the same as the one you can use to log time through the UI (see RedmineTimeTracking), except that spaces are not allowed to keep parsing simple.

Thanks.

#42 Updated by гиём шарьм almost 7 years ago

Is it posisble to update the patch for redmine 1.1?

Thanks.

#43 Updated by Marek Siller almost 7 years ago

гиём шарьм wrote:

Is it posisble to update the patch for redmine 1.1?

Thanks.

The patch is already included in redmine version 1.1, as far as I know.

Sincerely,

Marek Siller
KTC - Karlsruhe Technology Consulting GmbH (www.k-tc.de)

#44 Updated by гиём шарьм almost 7 years ago

I saw indeed something in administration/settings/repositories : Enable time logging. I tried it but without any result. Do the syntax has changed? Or does it simply does not work with mercurial?

#45 Updated by Marek Siller almost 7 years ago

гиём шарьм wrote:

I saw indeed something in administration/settings/repositories : Enable time logging. I tried it but without any result. Do the syntax has changed? Or does it simply does not work with mercurial?

It should work with Mercurial as well. Which syntax do you use - as far as I know, Jean-Philippe Lang changed the syntax a little bit - no spaces are allowed in the spent time entry ... but something like

Here is my change refs #1234 @1h30m

should work without any problems.

What expression do you use in the commit message?

#46 Updated by гиём шарьм almost 7 years ago

I indeed didn't try this syntax.

But I tried
ref #1234 @2h
and it does not work.

By the way, ref #1234 @XhYYm Apply only Xh and 0 min. Is it normal?
Is there any ratio or timelogcomment command still?

#47 Updated by Marek Siller almost 7 years ago

гиём шарьм wrote:

I indeed didn't try this syntax.

But I tried
ref #1234 @2h
and it does not work.

By the way, ref #1234 @XhYYm Apply only Xh and 0 min. Is it normal?
Is there any ratio or timelogcomment command still?

I have to go through the code to answer you question - I'm not completely familiar with the way the time-logging in redmine 1.1 - we still use 1.0.3 with the patch I wrote ... but I will try it tommorow and get back to you, how the syntax should exactly work ... and if it does not work work for you in connection with Mercurial, you should create a new issue / ticket here, so that the developers can track the bug. Even if you create new ticket, I'll be glad to help you to get it working (just add me to the watch list or send me an email with the link at )

Sincerely,
Marek Siller
KTC - Karlsruhe Technology Consulting GmbH

#48 Updated by Terence Mill over 6 years ago

For this new feature documentation is still missing in wiki redmine user guide
See RedmineTimeTracking or RedmineIssues

#49 Updated by Szymon Nowak about 6 years ago

I there any way to apply this patch to Redmine 1.2.1? Is it working with 1.2.1?

#50 Updated by Daniel Dehennin almost 6 years ago

Is there a way to specify the activity in the commit messages?

It is defaulted to Developpment but sometimes it could be usefull to change it.

Regards.

#51 Updated by michele corradin over 5 years ago

Hi,
we have moved to version 1.3.2 from an old version patched but it's no more working the syntax "#issue @Xh" in the SVN logging.

I didn't understand from the last post if time tracking is working or not in new versions, can you give me a feedback?

We are really using it a lot
Thanks
michele

#52 Updated by Jean-Philippe Lang over 5 years ago

The syntax "#issue @Xh" should work fine. Make sure that "Enable time logging" option is enabled in Application settings -> Repositories.

Also available in: Atom PDF