Browse Source

Estimate and spent time

main
R 4 months ago
parent
commit
2d2946cf26
2 changed files with 44 additions and 5 deletions
  1. +3
    -1
      README.md
  2. +41
    -4
      gitlab_todotxt/main.py

+ 3
- 1
README.md View File

@ -56,7 +56,7 @@ form your todo.txt tasks are written to file.
The default is
{delegate} {title} {due} {project} {url}
{delegate} {title} {due} {project} {milestone} {estimate} {spent} {url}
These are also all possible fields:
@ -67,6 +67,8 @@ These are also all possible fields:
- `due`: the due date of the issue or, if there is none, the due date of the
milestone this task belongs to (if any); in form of a `due:` tag.
- `project`: the project this task belongs to.
- `spent`: the time spent on the task.
- `estimate`: the estimated time for the task.
- `milestone`: the milestone of the issue.
- `url`: the URL to the actual issue at the GitLab website

+ 41
- 4
gitlab_todotxt/main.py View File

@ -34,7 +34,7 @@ if BaseDirectory is not None:
CACHEFILE = CACHEDIR / (PROGRAMNAME + ".cache")
DATE_FMT = '%Y-%m-%d'
DEFAULT_FORMAT = '{delegate} {title} {due} {project} {milestone} {url}'
DEFAULT_FORMAT = '{delegate} {title} {due} {project} {milestone} {estimate} {spent} {url}'
def get_config(args):
@ -47,6 +47,25 @@ def get_config(args):
return conf
def duration_as_str(seconds):
hours = seconds // 3600
minutes = (seconds % 3600) // 60
result = ''
if hours > 0:
result += f'{hours}h'
if minutes > 0:
result += f'{minutes}m'
return result
def unspacify(text):
for char in "\t\n":
text = text.replace(char, '_')
return text
class GitlabSource:
def __init__(self, name, config):
self.displayname = name
@ -127,13 +146,15 @@ class GitlabSource:
'uid': item['id'],
'url': item['web_url'],
'state': item['state'],
'labels': {label.replace(' ', '_') for label in item.get('labels', [])},
'labels': {unspacify(label) for label in item.get('labels', [])},
'assignees': set([user['username'] for user in item['assignees']]),
'projectid': item['project_id'],
'due': None,
'estimate': None,
'spent': None,
'milestone': None,
'estimate': None,
'spent': None,
}
if item['closed_at'] is not None:
@ -148,7 +169,13 @@ class GitlabSource:
issue['due'] = datetime.datetime.strptime(item['milestone']['due_date'], DATE_FMT).date()
if item['milestone'] is not None:
issue['milestone'] = item['milestone']['title'].replace(' ', '_')
issue['milestone'] = unspacify(item['milestone']['title'])
if item['time_stats']['time_estimate'] > 0:
issue['estimate'] = duration_as_str(item['time_stats']['time_estimate'])
if item['time_stats']['total_time_spent'] > 0:
issue['spent'] = duration_as_str(item['time_stats']['total_time_spent'])
issues.append(issue)
@ -196,7 +223,7 @@ class GitlabSource:
# Format for open issues
text = issue['created'].strftime(DATE_FMT)
project = '+' + project
project = '+' + unspacify(project)
title = issue['title']
delegation = ' '.join(['to:' + user
@ -221,11 +248,21 @@ class GitlabSource:
if issue['due'] is not None:
due = 'due:' + issue['due'].strftime(DATE_FMT)
spent = ''
if issue['spent'] is not None:
spent = 'spent:' + issue['spent']
estimate = ''
if issue['estimate'] is not None:
estimate = 'estimate:' + issue['estimate']
text = text + ' ' + self.format.format(title=issue['title'],
delegate=delegation,
project=project,
url=url,
due=due,
estimate=estimate,
spent=spent,
milestone=milestone)
# TODO: upon synchronisation this must be added to tasks to reconnect after parsing


Loading…
Cancel
Save