def _set_group(tree, group):
    """Set the group for a tree of dependencies."""
    grouped = {
        "dependency": tree["dependency"],
        "level": tree["level"],
        "version": tree["version"],
        "group": group,
        "children": [],
    }

    if tree["children"]:
        for child in tree["children"]:
            grouped["children"].append(_set_group(child, group))

    return grouped