Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions regolith/helpers/f_todohelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import dateutil.parser as date_parser
import math
import re

from regolith.helpers.basehelper import DbHelperBase
from regolith.fsclient import _id_key
Expand All @@ -30,7 +31,7 @@ def subparser(subpi):
int_kwargs['widget'] = 'IntegerField'

subpi.add_argument("-i", "--index",
help="Enter the index of a certain task in the enumerated list to mark as finished.",
help="Enter the index or the first 6 characters of a certain task in the enumerated list to mark as finished.",
type=int)
subpi.add_argument("--end-date",
help="Add the end date of the task. Default is today.",
Expand Down Expand Up @@ -72,11 +73,15 @@ def construct_global_ctx(self):

def db_updater(self):
rc = self.rc
if rc.index:
if rc.index >= 9900:
print("WARNING: indices >= 9900 are used for milestones which "
"should be finished using u_milestone and not f_todo")
return
# Check if rc.index is an integer and >= 9900
if isinstance(rc.index, int) and rc.index >= 9900:
print("WARNING: indices >= 9900 are used for milestones which "
"should be finished using u_milestone and not f_todo")
return
# Check if rc.index is a string, less than 6 characters, and contains both letters and numbers
elif isinstance(rc.index, str) and len(rc.index) < 6 and re.search("[A-Za-z].*\d|\d.*[A-Za-z]", rc.index):
print("WARNING: String indices less than 6 characters containing both letters and numbers are not allowed")
return
if not rc.assigned_to:
try:
rc.assigned_to = rc.default_user_id
Expand Down Expand Up @@ -113,7 +118,10 @@ def db_updater(self):
print("-" * 80)
print_task(todolist, stati=['started'])
else:
match_todo = [i for i in todolist if i.get("running_index") == rc.index]
if isinstance(rc.index, int):
match_todo = [i for i in todolist if i.get("running_index") == rc.index]
else:
match_todo = [i for i in todolist if i.get("uuid") == rc.index]
if len(match_todo) == 0:
raise RuntimeError("Please enter a valid index.")
else:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,12 @@
(["helper", "f_todo", "--index", "99100"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the index and uuid should be handled in the same way as each other as we discussed, so we probably either need to change how index is handled (remove optional argument --index and take is a required argument) or have the uuid taken in --index. I am not sure there is a way to test this unless we run the tests again from scratch. Maybe it is time to set that up.

Given that choice I would be inclined to pass the uuid as index. Maybe we change that variable name to --index_uuid or something like that? We will have to comment out the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be inclined to change variable name to index_uuid or adding a variable name uuid. Because it would be clearer to the user what to enter. If we change it to index_uuid it is not as clear because one can think it means entering the index and uuid. If we leave it as just index, I will change the definition of described in index to add that it is interchangeable with the first 6 characters of a todo's uuid.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea is that the user can enter either an index or a uuid. Either would work in exactly the same way. If I enter regolith helper f_todo --index 123 or regolith helper f_todo --index 8yt4q will work the same way if todo with index 123 has uuid 8yt4q.

Let's just keep the arg name as index for now. Late we can easily change it if we find a better name.

"WARNING: indices >= 9900 are used for milestones which should be finished using u_milestone and not f_todo\n"
),
(["helper", "f_todo", "--index", "1saefa"],
"The task \"(1saefa) test a_todo\" in test for sbillinge has been marked as finished.\n"
),
(["helper", "f_todo", "--index", "1saef"],
"Please enter either an index of todo or the first 6 characters of a todo\'s uuid..\n"
),
(["helper", "u_todo", "--index", "3", "--assigned-to", "sbillinge",
"--description", "update the description", "--due-date", "2020-07-06",
"--estimated-duration", "35", "--importance", "2", "--status", "finished",
Expand Down