Skip to content

Commit

Permalink
If the config option projects is empty, do not omit any entries. (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
icemac authored Dec 11, 2023
1 parent 08c1c83 commit dc7ec46
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 38 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Change log

- Fetch all projects, not just the first 100.

- If the config option ``projects`` is empty, upload all possible entries.

- Improve formatting to have always a precision of 2 for floats.

- No longer ignore entries with negative time.
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ should be okay.
`ticklog`: this file is used to write a line for each action which is done via
the Tick API. When using `--dry-run`, this file is also filled.

`projects` option should list all project prefixes. These prefixes will be used
to identify tick projects. If the script does not find anything that looks like
a tick project, it will skip that entry.

`projects` option should list all project prefixes for upload. These prefixes
will be used to identify tick projects. If the script for an entry does not
find a matching tick project, it will skip that entry. **Caution:** This option
can be empty or omitted to upload all projects.

TODO
====
Expand Down
17 changes: 6 additions & 11 deletions gtimelog2tick.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,6 @@ def read_config(config_file: pathlib.Path) -> dict:
"Your email address is not specified, set it via the"
" gtimelog2tick.email setting.")

if not requested_projects:
raise ConfigurationError(
"The list of projects is not specified, set them via the"
" gtimelog2tick.projects setting. Use the first letters of the"
" projects relevant for you from the projects page on"
" tickspot.com.")

requested_projects = set(requested_projects.split())

if not timelog:
Expand Down Expand Up @@ -262,10 +255,12 @@ def parse_timelog(
# Skip all non-work related entries.
if entry.message.endswith('**'):
continue
# Skip all lines which do not match the requested projects.
if not any(entry.message.startswith(x)
for x in config['requested_projects']):
continue
# Skip all lines which do not match the requested projects if requested
# projects are specified
if config['requested_projects']:
if not any(entry.message.startswith(x)
for x in config['requested_projects']):
continue

task, text, task_id = parse_entry_message(config, entry.message)
worklog = WorkLog(entry, text, task, task_id)
Expand Down
56 changes: 33 additions & 23 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import gtimelog2tick


def test_parse_timelog():
def test_gtimelog2tick__parse_timelog__1():
"""It omits entries which do not match the requested projects."""
entries = [
gtimelog2tick.Entry(datetime.datetime(2014, 3, 31, 14, 48),
datetime.datetime(2014, 3, 31, 17, 10),
Expand Down Expand Up @@ -46,6 +47,33 @@ def test_parse_timelog():
]


def test_gtimelog2tick__parse_timelog__2():
"""It omits no entries if requested projects is empty."""
entries = [
gtimelog2tick.Entry(datetime.datetime(2014, 3, 31, 14, 48),
datetime.datetime(2014, 3, 31, 17, 10),
'proj2: maint: work'),
gtimelog2tick.Entry(datetime.datetime(2014, 3, 31, 17, 48),
datetime.datetime(2014, 3, 31, 18, 10),
'proj3: dev: other'),
]
config = {
'requested_projects': [],
'tick_projects': [
gtimelog2tick.Project('proj2', 42, [
gtimelog2tick.Task('maintenance', 1),
]),
gtimelog2tick.Project('proj3', 43, [
gtimelog2tick.Task('development', 5),
])
]
}
assert list(gtimelog2tick.parse_timelog(config, entries)) == [
gtimelog2tick.WorkLog(entries[0], 'work', 'proj2: maintenance', 1),
gtimelog2tick.WorkLog(entries[-1], 'other', 'proj3: development', 5),
]


class Route:

def __init__(self, handler, params=None):
Expand Down Expand Up @@ -413,7 +441,7 @@ def test_no_args(env, mocker):
]


def test_gtimelog2tick__parse_timelog__1(env, mocker):
def test_gtimelog2tick__parse_timelog__3(env, mocker):
"""It raises a DataError for an entry with negative time."""
mocker.patch('gtimelog2tick.get_now',
return_value=datetime.datetime(2023, 12, 7).astimezone())
Expand All @@ -430,7 +458,7 @@ def test_gtimelog2tick__parse_timelog__1(env, mocker):
err.match(r'Negative hours: WorkLog\(.*')


def test_gtimelog2tick__parse_timelog__2(env, mocker):
def test_gtimelog2tick__parse_timelog__4(env, mocker):
"""It it ignores entries with zero minutes duration."""
mocker.patch('gtimelog2tick.get_now',
return_value=datetime.datetime(2023, 12, 7).astimezone())
Expand Down Expand Up @@ -734,22 +762,6 @@ def test_gtimelog2tick__read_config__7(tmpdir):
' gtimelog2tick.email setting.')


def test_gtimelog2tick__read_config__8(tmpdir):
"""It renders an exception if projects is missing."""
path = pathlib.Path(tmpdir) / 'config.ini'
path.write_text(textwrap.dedent("""\
[gtimelog]
[gtimelog2tick]
subscription_id = 123
token = <TOKEN>
user_id = 456
email = [email protected]"""))
with pytest.raises(gtimelog2tick.ConfigurationError) as err:
gtimelog2tick.read_config(path)
assert err.match('The list of projects is not specified, set them via the'
' gtimelog2tick.projects setting.')


def test_gtimelog2tick__read_config__9(tmpdir):
"""It renders an exception if timelog file does not exist."""
path = pathlib.Path(tmpdir) / 'config.ini'
Expand All @@ -758,8 +770,7 @@ def test_gtimelog2tick__read_config__9(tmpdir):
subscription_id = 123
token = <TOKEN>
user_id = 456
email = [email protected]
projects = FOO BAR"""))
email = [email protected]"""))
with pytest.raises(gtimelog2tick.ConfigurationError) as err:
gtimelog2tick.read_config(path)
assert err.match('Timelog file .*/timelog.txt does not exist.')
Expand All @@ -773,8 +784,7 @@ def test_gtimelog2tick__read_config__10(tmpdir):
subscription_id = 123
token = <TOKEN>
user_id = 456
email = [email protected]
projects = FOO BAR"""))
email = [email protected]"""))
(pathlib.Path(tmpdir) / 'timelog.txt').touch()
ticklog = pathlib.Path(tmpdir) / 'ticklog.txt'
ticklog.touch()
Expand Down

0 comments on commit dc7ec46

Please sign in to comment.