steyep / alfred-jira

Alfred 3 (or Alfred 2) workflow for interacting with JIRA.
270 stars 60 forks source link

Time tracking improvements #52

Open otherguy opened 7 years ago

otherguy commented 7 years ago

I would love a checkbox in the settings to disable the automatic time tracking.

It would also be cool to have a menu item to manually log time to an issue.

steyep commented 7 years ago

Hey, @darkwinternight, thanks for the suggestions! Could you elaborate on what you mean by "disable automatic time tracking?"

Are you saying that you want the "start progress" menu item to move the issue to the main menu but not track your time? If so, it's worth mentioning that just because the workflow is tracking the time that you leave an issue "in progress" you are able to stop progress on an issue without logging time. You can do that by using the keyword jiraclear. If you're using Alfred 3, cmd + return on the in-progress issue (on the main menu) and the "stop progress" item in the issue's sub-menu will allow you to stop progress without logging your time. Since that feature exists, I'm not sure I see a benefit of disabling time tracking (haha especially considering the "start/stop progress" item was added specifically for time tracking – #5). Please, let me know if I'm misinterpreting your comment, though.

In regards to your second comment, I completely agree and have been trying to come up with a good way to implement that.

otherguy commented 7 years ago

Got it... I misinterpreted the Start Progress feature I think. I was under the impression that it would also actually move the issue to In Progress in Jira! It doesn't and that's OK. Just Disregard my initial comment.

In regards to my second comment, I think the default Jira implementation would be enough. 2h to log 2 hours without a comment, 2h Meeting with client to log time with a comment.

steyep commented 7 years ago

I was under the impression that it would also actually move the issue to In Progress in Jira!

I've actually been testing something locally that will do that. It will allow you to configure certain options for your transitions in the settings so that transitioning an issue to In Dev (for example) will start progress or transitioning an issue to Ready for testing will log your time, assign the issue to the reporter, add a comment, etc. That feature will allow you to specify whether or not your time is actually logged to an issue.

Thanks for the suggestion. I think adding a comment in addition to the time adds another level of complexity. Separating the time-spent and the comment with a space probably isn't ideal since a user could technically log 2h 5m. But I will dig in to it and see what's possible.

otherguy commented 7 years ago

Separating the time-spent and the comment with a space probably isn't ideal since a user could technically log 2h 5m. But I will dig in to it and see what's possible.

True, but a simple regular expression should make that possible. According to this, there are only a few possible values:

You can specify additional time units after a time value 'X', such as Xw, Xd, Xh, or Xm, to represent weeks (w), days (d), hours (h), and minutes (m), respectively. If you type a number without specifying a time unit (e.g. if you type '2' instead of '2h'), the default time unit that your JIRA administrator specified will apply. Default conversion rates are 1w = 5d and 1d = 8h.

This quickly hacked (JS) RegEx should work:

^((\d+[wdhm]\ +?)+|\d+)\ *(.*)$

This would give you 3 capturing groups. The first one is the time string (needs to be trimmed), the third one is the comment.

What would add another level of complexity though is if you disable all time tracking features in the workflow, if JIRA has time tracking disabled completely ;)

steyep commented 7 years ago

Thanks. I'm not sure that regex will lead to a very good UX after some brief testing:

console.log([
  '5h 2m Meeting with client',
  '2h',
  '2h Meeting with client',
  '5w 2d 4m ',
  '5w 2d 4m meeting'
].map(str =>
  str.replace(/^((\d+[wdhm]\ +?)+|\d+)\ *(.*)$/,
    (s,a,b,c) => `time: ${a}, comment: ${c}`)));

Output:

[ 'time: 5h 2m , comment: Meeting with client',
  'time: 2h , comment: 2',
  'time: 2h , comment: Meeting with client',
  'time: 5w 2d 4m , comment: ',
  'time: 5w 2d 4m , comment: meeting' ]
otherguy commented 7 years ago

Why not? Can you elaborate? I've updated the regex a bit to make it nicer. Here is your test case with a few more examples:

console.log([
  '3w 4d 8h 12m Test string',
  '15m Test string',
  '123 Test',
  '50 Test',
  '123',
  '1h Test',
  '2h Test',
  '3d 4h Test',
  '7m, Meeting',
  '3h 15m, Meeting'
].map(str =>
  str.replace(/^(\d+|(?:(?:(?:\d+w)?\ ?(?:\d+d)?\ ?(?:\d+h)?\ ?(?:\d+m)?)))(?:[,\ ]+(.*))?$/gim,
    (s,a,b) => `time: "${a}", comment: "${b||""}"`)));

Output:

[ 'time: "3w 4d 8h 12m", comment: "Test string"',
  'time: "15m", comment: "Test string"',
  'time: "123", comment: "Test"',
  'time: "50", comment: "Test"',
  'time: "123", comment: ""',
  'time: "1h", comment: "Test"',
  'time: "2h", comment: "Test"',
  'time: "3d 4h", comment: "Test"',
  'time: "7m", comment: "Meeting"',
  'time: "3h 15m", comment: "Meeting"' ]

It's totally fine to have empty comments (${b} will be undefined) as I mostly log uncommented time.

steyep commented 7 years ago

Why not? Can you elaborate?

Oh, sorry, I thought that it was obvious from the test I posted. I meant that it wouldn't be a good user-experience using the previous regex because if they tried to log 2h (for example) it would log 2 [default units] to the issue and add a comment of 2 when they intended to log 2 hours and no comment.

Your revised expression looks promising though! By the way, PR's are always welcomed 😄

On a side note: I didn't realize that markdown supported syntax highlighting. I will definitely have to take advantage of that in the future.

otherguy commented 7 years ago

Oh, apparently I missed it or didn't look at the output closely 😉

On a side note: I didn't realize that markdown supported syntax highlighting. I will definitely have to take advantage of that in the future.

It's just GitHub flavored markdown that supports Syntax highlighting.

I did submit a tiny PR already by the way but building the whole feature would take too much time for me at the moment. I hope that my regular expression can help you a bit though!

oxeron commented 7 years ago

Would love to add work log to a ticket from Alfred directly, could be a nice feature.

alexsanjoseph commented 5 years ago

👍