package deployment import ( "os/exec" "github.com/thepeterstone/claudomator/internal/task" "github.com/thepeterstone/claudomator/internal/version" ) // Status describes whether the currently-deployed server includes a set of fix commits. type Status struct { DeployedCommit string `json:"deployed_commit"` FixCommits []task.GitCommit `json:"fix_commits"` IncludesFix bool `json:"includes_fix"` } // Check returns the deployment status for a set of fix commits given the project directory. // It uses `git merge-base --is-ancestor` to check whether each fix commit is an ancestor // of the deployed server's commit. Returns a non-nil Status in all cases; IncludesFix is // false when the check cannot be performed (missing git, "dev" version, no commits, etc.). func Check(fixCommits []task.GitCommit, projectDir string) *Status { deployedCommit := version.Version() status := &Status{ DeployedCommit: deployedCommit, FixCommits: fixCommits, } if deployedCommit == "dev" || projectDir == "" || len(fixCommits) == 0 { return status } // All fix commits must be ancestors of (or equal to) the deployed commit. for _, commit := range fixCommits { if commit.Hash == "" { continue } cmd := exec.Command("git", "-C", projectDir, "merge-base", "--is-ancestor", commit.Hash, deployedCommit) if err := cmd.Run(); err != nil { return status } } status.IncludesFix = true return status }