diff options
Diffstat (limited to 'internal/deployment')
| -rw-r--r-- | internal/deployment/deployment.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/internal/deployment/deployment.go b/internal/deployment/deployment.go new file mode 100644 index 0000000..0ba436d --- /dev/null +++ b/internal/deployment/deployment.go @@ -0,0 +1,43 @@ +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 +} |
