// SPDX-FileCopyrightText: 2025 Romain Maneschi // // SPDX-License-Identifier: MIT package model import "github.com/tidwall/gjson" type FileActionType string const ( FileActionTypeAdd FileActionType = "add" FileActionTypeMod FileActionType = "mod" FileActionTypeDel FileActionType = "del" ) type File struct { Path string `json:"path"` FileHash string `json:"fileHash"` OldPath string `json:"oldPath"` //only if action == FileActionTypeMod OldFileHash string `json:"oldFileHash"` //only if action == FileActionTypeMod Action FileActionType `json:"action"` } func FileFromString(file string) File { j := gjson.Parse(file) action := FileActionTypeAdd switch j.Get("action").String() { case "add": action = FileActionTypeAdd case "mod": action = FileActionTypeMod case "del": action = FileActionTypeDel } return File{ Path: j.Get("path").String(), FileHash: j.Get("fileHash").String(), OldPath: j.Get("oldPath").String(), OldFileHash: j.Get("oldFileHash").String(), Action: action, } }