Skip to content
Draft
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
102 changes: 56 additions & 46 deletions src/regolith/helpers/u_milestonehelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from regolith.dates import get_due_date
from regolith.fsclient import _id_key
from regolith.helpers.basehelper import DbHelperBase
from regolith.schemas import alloweds
from regolith.schemas import SCHEMAS, alloweds
from regolith.tools import all_docs_from_collection, fragment_retrieval, get_uuid

TARGET_COLL = "projecta"
Expand All @@ -25,7 +25,8 @@ def subparser(subpi):
if isinstance(subpi, GooeyParser):
date_kwargs["widget"] = "DateChooser"

subpi.add_argument("-i", "--milestone_uuid", help="The uuid of a milestone. " "Takes a full or partial uuid.")
# subpi.add_argument("-i", "--uuid", help="The universally unique id for the task so it
# can be referenced elsewhere. " "Takes a full or partial uuid.")
subpi.add_argument(
"-p",
"--projectum_id",
Expand All @@ -34,37 +35,48 @@ def subparser(subpi):
"you are adding a new milestone "
"to the specified projectum.",
)
subpi.add_argument(
"-u", "--due-date", help="New due date of the milestone. " "Required for a new milestone.", **date_kwargs
)
# subpi.add_argument(
# "-u", "--due-date", help="New due date of the milestone. " "Required for a new milestone.", **date_kwargs
# )
# Do not delete --database arg
subpi.add_argument(
"--database",
help="The database that will be updated. Defaults to " "first database in the regolithrc.json file.",
)
subpi.add_argument("-f", "--finish", action="store_true", help="Finish milestone. ")
subpi.add_argument("-n", "--name", help="Name of the milestone. " "Required for a new milestone.")
subpi.add_argument("-o", "--objective", help="Objective of the milestone. " "Required for a new milestone.")
subpi.add_argument(
"-s",
"--status",
help="Status of the milestone/deliverable: "
f"{*PROJECTUM_STATI, }. "
"Defaults to proposed for a new milestone.",
)
subpi.add_argument(
"-t",
"--type",
help="Type of the milestone: " f"{*MILESTONE_TYPES, } " "Defaults to meeting for a new milestone.",
)
subpi.add_argument(
"-a",
"--audience",
nargs="+",
help="Audience of the milestone. " "Defaults to ['lead', 'pi', 'group_members'] for a new milestone.",
)
subpi.add_argument("--notes", nargs="+", help="Any notes you want to add to the milestone.")
# subpi.add_argument("-n", "--name", help="Name of the milestone. " "Required for a new milestone.")
# subpi.add_argument("-o", "--objective", help="Objective of the milestone. " "Required for a new milestone.")
# # subpi.add_argument(
# # "-s",
# # "--status",
# # help="Status of the milestone/deliverable: "
# # f"{*PROJECTUM_STATI, }. "
# # "Defaults to proposed for a new milestone.",
# # )
# subpi.add_argument(
# "-t",
# "--type",
# help="Type of the milestone: " f"{*MILESTONE_TYPES, } " "Defaults to meeting for a new milestone.",
# )
# subpi.add_argument(
# "-a",
# "--audience",
# nargs="+",
# help="Audience of the milestone. " "Defaults to ['lead', 'pi', 'group_members'] for a new milestone.",
# )
# subpi.add_argument("--notes", nargs="+", help="Any notes you want to add to the milestone.")
subpi.add_argument("--date", help="The date that will be used for testing.", **date_kwargs)

milestone_keys = [key for key in SCHEMAS.get("projecta").get("milestones").get("schema").get("schema")]
milestone_helps = milestone_keys
milestone_helps = [
help[1].get("description")
for help in SCHEMAS.get("projecta").get("milestones").get("schema").get("schema").items()
]

for key, help in zip(milestone_keys, milestone_helps):
subpi.add_argument(f"--{key}", help=f"{help}")

return subpi


Expand Down Expand Up @@ -96,14 +108,14 @@ def db_updater(self):
now = dt.date.today()
new_mil = []
pdoc = {}
if rc.projectum_id and rc.milestone_uuid:
if rc.projectum_id and rc.uuid:
raise RuntimeError(
"Detected both a uuid fragment and projectum id.\n"
"You may enter either a milestone uuid or a projectum id but not both.\n"
"Enter a milestone uuid to update an existing milestone, "
"or a projectum id to add a new milestone to that projectum.\n"
)
if not rc.projectum_id and not rc.milestone_uuid:
if not rc.projectum_id and not rc.uuid:
raise RuntimeError(
"No milestone uuid or projectum id was entered.\n"
"Enter a milestone uuid to update an existing milestone, "
Expand Down Expand Up @@ -176,14 +188,14 @@ def db_updater(self):
updated.append(f"{rc.projectum_id} has been updated in projecta")
else:
pdoc, upd_mil, all_miles, id = {}, [], [], []
target_mil = fragment_retrieval(self.gtx["projecta"], ["milestones"], rc.milestone_uuid)
target_del = fragment_retrieval(self.gtx["projecta"], ["_id"], rc.milestone_uuid)
target_ko = fragment_retrieval(self.gtx["projecta"], ["_id"], rc.milestone_uuid[2:])
target_mil = fragment_retrieval(self.gtx["projecta"], ["milestones"], rc.uuid)
target_del = fragment_retrieval(self.gtx["projecta"], ["_id"], rc.uuid)
target_ko = fragment_retrieval(self.gtx["projecta"], ["_id"], rc.uuid[2:])
if target_mil and not target_del and not target_ko:
for prum in target_mil:
milestones = prum["milestones"]
for milestone in milestones:
if milestone.get("uuid")[0 : len(rc.milestone_uuid)] == rc.milestone_uuid:
if milestone.get("uuid")[0 : len(rc.uuid)] == rc.uuid:
upd_mil.append(milestone)
else:
all_miles.append(milestone)
Expand All @@ -192,28 +204,28 @@ def db_updater(self):
id.append(pid)
if target_del:
for prum in target_del:
if prum.get("_id")[0 : len(rc.milestone_uuid)] == rc.milestone_uuid:
if prum.get("_id")[0 : len(rc.uuid)] == rc.uuid:
deliverable = prum["deliverable"]
upd_mil.append(deliverable)
if upd_mil:
pid = prum.get("_id")
id.append(pid)
if target_ko and rc.milestone_uuid[:2] == "ko":
if target_ko and rc.uuid[:2] == "ko":
for prum in target_ko:
if prum.get("_id")[0 : len(rc.milestone_uuid) - 2] == rc.milestone_uuid[2:]:
if prum.get("_id")[0 : len(rc.uuid) - 2] == rc.uuid[2:]:
kickoff = prum["kickoff"]
upd_mil.append(kickoff)
if upd_mil:
pid = prum.get("_id")
id.append(pid)
if len(upd_mil) == 0:
zero.append(rc.milestone_uuid)
zero.append(rc.uuid)
elif len(upd_mil) == 1:
for dict in upd_mil:
pdoc.update(dict)
if not pdoc.get("type") and not rc.type and not target_del and not target_ko:
raise ValueError(
f"Milestone ({rc.milestone_uuid}) does not have a type set and this is required.\n"
f"Milestone ({rc.uuid}) does not have a type set and this is required.\n"
"Specify '--type' and rerun the helper to update this milestone.\n"
)
if rc.type:
Expand Down Expand Up @@ -248,11 +260,11 @@ def db_updater(self):
if rc.name and pdoc.get("name"):
pdoc.update({"name": rc.name})
elif rc.name and not pdoc.get("name"):
print(f"Ignoring 'name' assignment for deliverable uuid ({rc.milestone_uuid})")
print(f"Ignoring 'name' assignment for deliverable uuid ({rc.uuid})")
if rc.objective and pdoc.get("name"):
pdoc.update({"objective": rc.objective})
elif rc.objective and not pdoc.get("name"):
print(f"Ignoring 'objective' assignment for deliverable uuid ({rc.milestone_uuid})")
print(f"Ignoring 'objective' assignment for deliverable uuid ({rc.uuid})")
if rc.status:
pdoc.update({"status": rc.status})
if rc.notes:
Expand All @@ -265,28 +277,26 @@ def db_updater(self):
doc.update({"milestones": all_miles})
if target_del:
doc.update({"deliverable": pdoc})
if target_ko and rc.milestone_uuid[:2] == "ko":
if target_ko and rc.uuid[:2] == "ko":
doc.update({"kickoff": pdoc})
rc.client.update_one(rc.database, rc.coll, {"_id": id[0]}, doc)
if not rc.finish:
updated.append(
f"The milestone uuid {rc.milestone_uuid} in {id[0]} has been updated in projecta."
)
updated.append(f"The milestone uuid {rc.uuid} in {id[0]} has been updated in projecta.")
else:
multiple.append(rc.milestone_uuid)
multiple.append(rc.uuid)
if updated:
for msg in updated:
print(msg)
else:
print("Failed to update projecta.")
if zero:
print(
f"No ids were found that match your milestone_uuid entry ({zero[0]}).\n"
f"No ids were found that match your uuid entry ({zero[0]}).\n"
"Make sure you have entered the correct uuid or uuid fragment and rerun the helper.\n"
)
if multiple:
print(
f"Multiple ids match your milestone_uuid entry ({multiple[0]}).\n"
f"Multiple ids match your uuid entry ({multiple[0]}).\n"
"Try entering more characters of the uuid and rerun the helper.\n"
)
return
2 changes: 1 addition & 1 deletion src/regolith/schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -2150,7 +2150,7 @@
"type": "dict",
"schema": {
"uuid": {
"description": "a universally unique id for the task so it can be referenced elsewhere",
"description": "a universally unique id for the milestone.",
"required": true,
"type": "string"
},
Expand Down
16 changes: 8 additions & 8 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@
[
"helper",
"u_milestone",
"--milestone_uuid",
"--uuid",
"kosb_fir",
"--name",
"Kick off meeting",
Expand All @@ -676,7 +676,7 @@
"The milestone 'Kick off meeting' has been marked as finished in prum sb_firstprojectum.\n",
),
(
["helper", "u_milestone", "--milestone_uuid", "bad_id"],
["helper", "u_milestone", "--uuid", "bad_id"],
"Failed to update projecta.\n"
"No ids were found that match your milestone_uuid entry (bad_id).\n"
"Make sure you have entered the correct uuid or uuid fragment and rerun the helper.\n\n",
Expand All @@ -685,7 +685,7 @@
[
"helper",
"u_milestone",
"--milestone_uuid",
"--uuid",
"pl",
"--status",
"finished",
Expand Down Expand Up @@ -802,7 +802,7 @@
"tag2",
"--date",
"2020-07-10",
"--milestone_uuid",
"--uuid",
"milestone_uuid_sb1_2",
],
"The milestone uuid milestone_uuid_sb1_2 in projectum sb_firstprojectum has been updated in projecta.\n"
Expand Down Expand Up @@ -1228,7 +1228,7 @@

helper_map_bad = [
(
["helper", "u_milestone", "--milestone_uuid", "sb_fir", "--projectum_id", "sb_firstprojectum"],
["helper", "u_milestone", "--uuid", "sb_fir", "--projectum_id", "sb_firstprojectum"],
"Detected both a uuid fragment and projectum id.\n"
"You may enter either a milestone uuid or a projectum id but not both.\n"
"Enter a milestone uuid to update an existing milestone, or a projectum id to add a new milestone to that projectum.\n",
Expand Down Expand Up @@ -1256,13 +1256,13 @@
RuntimeError,
),
(
["helper", "u_milestone", "--milestone_uuid", "milestone_uuid_pl1", "--due_date", "2020-06-01"],
["helper", "u_milestone", "--uuid", "milestone_uuid_pl1", "--due_date", "2020-06-01"],
"Milestone (milestone_uuid_pl1) does not have a type set and this is required.\n"
"Specify '--type' and rerun the helper to update this milestone.\n",
ValueError,
),
(
["helper", "u_milestone", "--milestone_uuid", "kopl_first", "--type", "bad_type"],
["helper", "u_milestone", "--uuid", "kopl_first", "--type", "bad_type"],
"The type you have specified is not recognized. \n"
"Please rerun your command adding '--type' \n"
"and giving a type from this list:\n"
Expand Down Expand Up @@ -1291,7 +1291,7 @@
ValueError,
),
(
["helper", "u_milestone", "--milestone_uuid", "milestone_uuid_sb1_", "--type", "bad_type"],
["helper", "u_milestone", "--uuid", "milestone_uuid_sb1_", "--type", "bad_type"],
"The type you have specified is not recognized. \n"
"Please rerun your command adding '--type' \n"
"and giving a type from this list:\n"
Expand Down
Loading