feat(backend): Implement discussion branching and take promotion
This commit is contained in:
@@ -424,3 +424,36 @@ def calculate_track_progress(tickets: list) -> dict:
|
||||
"todo": todo
|
||||
}
|
||||
|
||||
|
||||
def branch_discussion(project_dict: dict, source_id: str, new_id: str, message_index: int) -> None:
|
||||
"""
|
||||
Creates a new discussion in project_dict['discussion']['discussions'] by copying
|
||||
the history from source_id up to (and including) message_index, and sets active to new_id.
|
||||
"""
|
||||
if "discussion" not in project_dict or "discussions" not in project_dict["discussion"]:
|
||||
return
|
||||
if source_id not in project_dict["discussion"]["discussions"]:
|
||||
return
|
||||
|
||||
source_disc = project_dict["discussion"]["discussions"][source_id]
|
||||
new_disc = default_discussion()
|
||||
new_disc["git_commit"] = source_disc.get("git_commit", "")
|
||||
# Copy history up to and including message_index
|
||||
new_disc["history"] = source_disc["history"][:message_index + 1]
|
||||
|
||||
project_dict["discussion"]["discussions"][new_id] = new_disc
|
||||
project_dict["discussion"]["active"] = new_id
|
||||
|
||||
def promote_take(project_dict: dict, take_id: str, new_id: str) -> None:
|
||||
"""Renames a take_id to new_id in the discussions dict."""
|
||||
if "discussion" not in project_dict or "discussions" not in project_dict["discussion"]:
|
||||
return
|
||||
if take_id not in project_dict["discussion"]["discussions"]:
|
||||
return
|
||||
|
||||
disc = project_dict["discussion"]["discussions"].pop(take_id)
|
||||
project_dict["discussion"]["discussions"][new_id] = disc
|
||||
|
||||
# If the take was active, update the active pointer
|
||||
if project_dict["discussion"].get("active") == take_id:
|
||||
project_dict["discussion"]["active"] = new_id
|
||||
|
||||
Reference in New Issue
Block a user