def git_change_audit(event: KubernetesAnyChangeEvent, action_params: GitAuditParams):
    """
    Audit Kubernetes resources from the cluster to Git as yaml files (cluster/namespace/resources hierarchy).
    Monitor resource changes and save it to a dedicated Git repository.

    Using this audit repository, you can easily detect unplanned changes on your clusters.
    """
    try:
        if event.obj.kind in skipped_kinds:
            return

        if len(event.obj.metadata.ownerReferences) != 0:
            return  # not handling runtime objects

        git_repo = GitRepoManager.get_git_repo(
            action_params.git_url,
            action_params.git_key.get_secret_value(),
        )
        name = f"{git_safe_name(event.obj.metadata.name)}.yaml"
        namespace = event.obj.metadata.namespace or "None"
        path = f"{git_safe_name(action_params.cluster_name)}/{git_safe_name(namespace)}"

        if event.operation == K8sOperationType.DELETE:
            git_repo.delete_push(path, name, f"Delete {path}/{name}", action_params.cluster_name)
        elif event.operation == K8sOperationType.CREATE:
            obj_yaml = hikaru.get_yaml(event.obj.spec)
            git_repo.commit_push(
                obj_yaml,
                path,
                name,
                f"Create {event.obj.kind} named {event.obj.metadata.name} on namespace {namespace}",
                action_params.cluster_name,
            )
        else:  # update
            old_spec = event.old_obj.spec if event.old_obj else None
            if obj_diff(event.obj.spec, old_spec, action_params.ignored_changes):  # we have a change in the spec
                git_repo.commit_push(
                    hikaru.get_yaml(event.obj.spec),
                    path,
                    name,
                    f"Update {event.obj.kind} named {event.obj.metadata.name} on namespace {namespace}",
                    action_params.cluster_name,
                )
    except Exception as e:
        logging.error("git audit error", exc_info=True)

    Audit Kubernetes resources from the cluster to Git as yaml files (cluster/namespace/resources hierarchy).
    Monitor resource changes and save it to a dedicated Git repository.

    Using this audit repository, you can easily detect unplanned changes on your clusters.
    
playbooks/robusta_playbooks/git_change_audit.py