Project

General

Profile

Actions

Feature #4155

closed

Automatic spent time logging from commit messages

Added by Marek Siller about 15 years ago. Updated over 12 years ago.

Status:
Closed
Priority:
Normal
Category:
Time tracking
Target version:
Start date:
2009-11-02
Due date:
% Done:

100%

Estimated time:
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


Files

LogTime-v1-redmine-0.8.5.patch (27.8 KB) LogTime-v1-redmine-0.8.5.patch Patch for version 0.8.5 Marek Siller, 2009-11-02 16:45
LogTime-v1-redmine-devel.patch (30.2 KB) LogTime-v1-redmine-devel.patch Patch for trunk version Marek Siller, 2009-11-02 16:45
LogTime-v2-redmine-0.8.x.patch (27.8 KB) LogTime-v2-redmine-0.8.x.patch Patch for version 0.8.x (tested on 0.8.5 and 0.8.6) Marek Siller, 2009-11-04 16:46
LogTime-v2-redmine-devel.patch (30.2 KB) LogTime-v2-redmine-devel.patch Patch for trunk version Marek Siller, 2009-11-04 16:46
LogTime-v2.1-redmine-0.8.x.patch (27.8 KB) 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 Marek Siller, 2009-11-06 18:09
LogTime-v2.1-redmine-devel.patch (30.2 KB) LogTime-v2.1-redmine-devel.patch Patch for trunk version - corrected version Marek Siller, 2009-11-06 18:09
LogTime-v2.1-redmine-devel.patch (30.2 KB) LogTime-v2.1-redmine-devel.patch Patch for trunk version - corrected version Marek Siller, 2009-11-06 18:45
logtime_redmine_0.9.2.patch (22.3 KB) logtime_redmine_0.9.2.patch Vladimir Kovacik, 2010-02-18 14:00
logtime_redmine_0.9.2_v2.2.patch (22.3 KB) logtime_redmine_0.9.2_v2.2.patch Vladimir Kovacik, 2010-03-04 10:13
logtime_redmine_0.9.2_v2.3.patch (22.7 KB) logtime_redmine_0.9.2_v2.3.patch Katy A, 2010-05-25 01:45
logtime_redmine_0.9.3_v2.3.patch (22.2 KB) logtime_redmine_0.9.3_v2.3.patch Paul Widden, 2010-09-01 19:33
logtime_redmine_1.0.3-v3.patch (114 KB) logtime_redmine_1.0.3-v3.patch Marek Siller, 2010-11-09 20:13
fix-scmid-all-number.diff (1.8 KB) fix-scmid-all-number.diff Toshi MARUYAMA, 2010-12-11 14:51

Related issues

Related to Redmine - Feature #1518: Log time via commit messagesClosedMischa The Evil2008-06-23

Actions
Related to Redmine - Defect #7630: Spent time in commits not recognizedClosed2011-02-15

Actions
Actions #1

Updated by Marek Siller about 15 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

Actions #2

Updated by Kamil . about 15 years ago

Looks very interesting!

Actions #3

Updated by Marek Siller about 15 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
Actions #4

Updated by Jean-Philippe Lang about 15 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.

Actions #5

Updated by Robert Chady about 15 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.

Actions #6

Updated by Jonas von Andrian about 15 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.

Actions #7

Updated by Marek Siller about 15 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.

Actions #8

Updated by Erik Lindblom about 15 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)"

Actions #9

Updated by Marek Siller about 15 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)?

Actions #10

Updated by Erik Lindblom about 15 years ago

Version: 0.8.6.devel.3009
Patch v22

Actions #11

Updated by Marek Siller about 15 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?

Actions #12

Updated by Erik Lindblom about 15 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'
Actions #13

Updated by Marek Siller about 15 years ago

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

Actions #14

Updated by Erik Lindblom about 15 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 2 and even the older one, refs #112 2 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!

Actions #15

Updated by Leonard Brünings about 15 years ago

Erik Lindblom wrote:

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

Try either @2.0 or @2h

Actions #16

Updated by Erik Lindblom about 15 years ago

Just tried this with no luck:

testing (#362) @2h
Actions #17

Updated by Mischa The Evil about 15 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...

Actions #18

Updated by Erik Lindblom about 15 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.

Actions #19

Updated by Jean-Philippe Lang about 15 years ago

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

Actions #20

Updated by Jonas von Andrian about 15 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.

Actions #21

Updated by Chris Platts about 15 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

Actions #22

Updated by Sachin Khandelwal about 15 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

Actions #23

Updated by Renzo Meister almost 15 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

Actions #24

Updated by Vladimir Kovacik almost 15 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 (111 2342)

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.

Actions #25

Updated by Tomasz Sawicki almost 15 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.

Actions #26

Updated by Tomasz Sawicki almost 15 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)

Actions #27

Updated by Vladimir Kovacik almost 15 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).

Actions #28

Updated by Simon Dyson over 14 years ago

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

Actions #29

Updated by Katy A over 14 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.

Actions #30

Updated by David Parker over 14 years ago

+1. prefer this syntax to #1518

Actions #31

Updated by Dominic Clifton over 14 years ago

+1 for this syntax.

Actions #33

Updated by Dominic Clifton about 14 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?

Actions #34

Updated by Dominic Clifton about 14 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.

Actions #35

Updated by Marek Siller about 14 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?

Actions #36

Updated by Jean-Philippe Lang about 14 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.

Actions #37

Updated by Jean-Philippe Lang about 14 years ago

  • Tracker changed from Patch to Feature
Actions #38

Updated by Ivan Cenov about 14 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

Actions #39

Updated by Marek Siller about 14 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

Actions #40

Updated by Toshi MARUYAMA about 14 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.

Actions #41

Updated by Jean-Philippe Lang about 14 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.

Actions #42

Updated by гиём шарьм almost 14 years ago

Is it posisble to update the patch for redmine 1.1?

Thanks.

Actions #43

Updated by Marek Siller almost 14 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)

Actions #44

Updated by гиём шарьм almost 14 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?

Actions #45

Updated by Marek Siller almost 14 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?

Actions #46

Updated by гиём шарьм almost 14 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?

Actions #47

Updated by Marek Siller almost 14 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

Actions #48

Updated by Terence Mill almost 14 years ago

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

Actions #49

Updated by Szymon Nowak over 13 years ago

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

Actions #50

Updated by Daniel Dehennin about 13 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.

Actions #51

Updated by michele corradin over 12 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

Actions #52

Updated by Jean-Philippe Lang over 12 years ago

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

Actions

Also available in: Atom PDF