Vote #65960
完了Automatic spent time logging from commit messages
100%
説明
We have created a small patch for redmine that enables automatic logging of spent time via commit messages of a versioning system.
h1. 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.
h1. 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.
h1. Patch
Tested with Redmine 0.8.5 and the latest development version (both patches included). Tested SCM include Subversion and git.
h2. 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
journals
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
<pre>
Completed implementation of two new features: refs #1518 @3h 40m #4155 @6h
</pre>
--------------------------------------------------------------------------------
Looks very interesting!
--------------------------------------------------------------------------------
New set of patches for this feature.
h3. 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
--------------------------------------------------------------------------------
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:
<pre>
refs #1
ratio 50
time 1,0
timelogcomment comment for this timelog
</pre>
I have to admit that I prefer the shorter syntax:
<pre>
refs #1234 @2.5
references #1234 @2h30m
fixes #1234 @2h 30m
</pre>
What do you think? Any suggestion is welcome.
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
Marek,
I applied the patch, but I'm having issues with it.
Here is the top of the error log:
<pre>
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'
</pre>
Any ideas?
I have my "Referencing keywords" set to "*" because I just commit with "(#idnumber)"
--------------------------------------------------------------------------------
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)?
--------------------------------------------------------------------------------
Version: 0.8.6.devel.3009
Patch v22
--------------------------------------------------------------------------------
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?
--------------------------------------------------------------------------------
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:
<pre>
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'
</pre>
--------------------------------------------------------------------------------
Sorry, I made a mistake while creating the patch for the devel version. Corrected version in attachement.
--------------------------------------------------------------------------------
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!
--------------------------------------------------------------------------------
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
--------------------------------------------------------------------------------
Just tried this with no luck:
<pre>
testing (#362) @2h
</pre>
--------------------------------------------------------------------------------
Erik Lindblom wrote:
> Just tried this with no luck:
>
> <pre>testing (#362) @2h</pre>
I think this is due to the used parentheses in you syntax. Probably <pre>testing #362 @2h</pre> works...
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
Adding a few tests in this patch would lower the noise.
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
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
--------------------------------------------------------------------------------
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
--------------------------------------------------------------------------------
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
--------------------------------------------------------------------------------
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:
<pre>
+ if activity == nil
+ activity = TimeEntryActivity.values[0]
+ end
</pre>
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.
--------------------------------------------------------------------------------
Very nice feature, thank you for contributing.
Another nice thing would be possibility to log the time without referencing particular issue, like:
<pre>
- doing some cleanups
@2h30m
</pre>
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.
--------------------------------------------------------------------------------
After applying the patch you *must* include the "spent time" part, otherwise reference to issue will be ignored. Following won't work anymore:
<pre>
refs #4155
</pre>
To fix that following line:
<pre>
<code class="ruby">
target_issues_with_log = match[1].scan(/([\s,;&]*([^@]|#?)\d+)([\s]*@(\d+[.]\d+|(\d+[hm]\s?){1,2}))/)
</code>
</pre>
should be changed to:
<pre>
<code class="ruby">
target_issues_with_log = match[1].scan(/([\s,;&]*([^@]|#?)\d+)([\s]*@(\d+[.]\d+|(\d+[hm]\s?){1,2}))?/)
</code>
</pre>
(additional question mark near the end of line)
--------------------------------------------------------------------------------
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).
--------------------------------------------------------------------------------
Is there a version of this patch compatible with Redmine 0.9.3?
--------------------------------------------------------------------------------
> 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.
--------------------------------------------------------------------------------
+1. prefer this syntax to #1518
--------------------------------------------------------------------------------
+1 for this syntax.
--------------------------------------------------------------------------------
Patch for 0.9.3
--------------------------------------------------------------------------------
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?
--------------------------------------------------------------------------------
Current patch applies with:
<pre>
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
</pre>
My other questions above still stand.
--------------------------------------------------------------------------------
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?
--------------------------------------------------------------------------------
I'll review your patch as soon as possible.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
I am translating this to Bulgarian and have a question:
<pre>
text_time_logged_by_changeset: Applied in changeset {{value}}.
</pre>
What kind is the value of *value* ? What information does it comprises of?
Ivan
--------------------------------------------------------------------------------
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
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
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#Accepted-time-formats]]), except that spaces are not allowed to keep parsing simple.
Thanks.
--------------------------------------------------------------------------------
Is it posisble to update the patch for redmine 1.1?
Thanks.
--------------------------------------------------------------------------------
гиём шарьм 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)
--------------------------------------------------------------------------------
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?
--------------------------------------------------------------------------------
гиём шарьм 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
<pre>Here is my change refs #1234 @1h30m</pre>
should work without any problems.
What expression do you use in the commit message?
--------------------------------------------------------------------------------
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?
--------------------------------------------------------------------------------
гиём шарьм 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 marek.siller@k-tc.de)
Sincerely,
Marek Siller
KTC - Karlsruhe Technology Consulting GmbH
--------------------------------------------------------------------------------
For this new feature documentation is still missing in wiki redmine user guide
See [[RedmineTimeTracking]] or [[RedmineIssues]]
--------------------------------------------------------------------------------
I there any way to apply this patch to Redmine 1.2.1? Is it working with 1.2.1?
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
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
--------------------------------------------------------------------------------
The syntax "#issue @Xh" should work fine. Make sure that "Enable time logging" option is enabled in Application settings -> Repositories.
--------------------------------------------------------------------------------
related_issues
relates,Closed,1518,Log time via commit messages
relates,Closed,7630,Spent time in commits not recognized