Open source AI coding agent. Designed for large projects and real world tasks.
Go aiai-agentsai-developer-toolsai-toolsclicommand-linedeveloper-toolsgitgolanggpt-4llmopenaipolyglot-programmingterminalterminal-basedterminal-ui
make handlers lockRepo helper available outside package, remove extraneous list branches when locking, add helper to get single PlanFileResult object
Dane Schneiderd934bbf3bdab
diff --git a/app/server/db/locks.go b/app/server/db/locks.goindex cdea4343..1059fa59 100644--- a/app/server/db/locks.go+++ b/app/server/db/locks.go@@ -229,12 +229,12 @@ func lockRepo(params LockRepoParams, numRetry int) (string, error) {return "", fmt.Errorf("error removing lock file: %v", err)}- branches, err := GitListBranches(orgId, planId)- if err != nil {- return "", fmt.Errorf("error getting branches: %v", err)- }+ // branches, err := GitListBranches(orgId, planId)+ // if err != nil {+ // return "", fmt.Errorf("error getting branches: %v", err)+ // }- log.Println("branches:", branches)+ // log.Println("branches:", branches)if branch != "" {// checkout the branchdiff --git a/app/server/db/result_helpers.go b/app/server/db/result_helpers.goindex 0e33dfdc..0f9d50cd 100644--- a/app/server/db/result_helpers.go+++ b/app/server/db/result_helpers.go@@ -301,6 +301,25 @@ func GetPlanFileResults(orgId, planId string) ([]*PlanFileResult, error) {return results, nil}+func GetPlanFileResultById(orgId, planId, resultId string) (*PlanFileResult, error) {+ resultsDir := getPlanResultsDir(orgId, planId)++ bytes, err := os.ReadFile(filepath.Join(resultsDir, resultId+".json"))++ if err != nil {+ return nil, fmt.Errorf("error reading result file: %v", err)+ }++ var result PlanFileResult+ err = json.Unmarshal(bytes, &result)++ if err != nil {+ return nil, fmt.Errorf("error unmarshalling result file: %v", err)+ }++ return &result, nil+}+func GetPlanResult(planFileResults []*shared.PlanFileResult) *shared.PlanResult {resByPath := make(shared.PlanFileResultsByPath)replacementsByPath := make(map[string][]*shared.Replacement)diff --git a/app/server/handlers/branches.go b/app/server/handlers/branches.goindex 0dce378f..40c8d804 100644--- a/app/server/handlers/branches.go+++ b/app/server/handlers/branches.go@@ -32,7 +32,7 @@ func ListBranchesHandler(w http.ResponseWriter, r *http.Request) {var err errorctx, cancel := context.WithCancel(context.Background())- unlockFn := lockRepo(w, r, auth, db.LockScopeRead, ctx, cancel, false)+ unlockFn := LockRepo(w, r, auth, db.LockScopeRead, ctx, cancel, false)if unlockFn == nil {return} else {@@ -108,7 +108,7 @@ func CreateBranchHandler(w http.ResponseWriter, r *http.Request) {}ctx, cancel := context.WithCancel(context.Background())- unlockFn := lockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)+ unlockFn := LockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)if unlockFn == nil {return} else {diff --git a/app/server/handlers/context_helper.go b/app/server/handlers/context_helper.goindex fff6d9a6..8c59aa43 100644--- a/app/server/handlers/context_helper.go+++ b/app/server/handlers/context_helper.go@@ -120,7 +120,7 @@ func loadContexts(w http.ResponseWriter, r *http.Request, auth *types.ServerAuth}ctx, cancel := context.WithCancel(context.Background())- unlockFn := lockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)+ unlockFn := LockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)if unlockFn == nil {return nil, nil} else {diff --git a/app/server/handlers/fs_helper.go b/app/server/handlers/fs_helper.goindex 5702a61a..4ccc603f 100644--- a/app/server/handlers/fs_helper.go+++ b/app/server/handlers/fs_helper.go@@ -12,7 +12,7 @@ import ("github.com/gorilla/mux")-func lockRepo(w http.ResponseWriter, r *http.Request, auth *types.ServerAuth, scope db.LockScope, ctx context.Context, cancelFn context.CancelFunc, requireBranch bool) *func(err error) {+func LockRepo(w http.ResponseWriter, r *http.Request, auth *types.ServerAuth, scope db.LockScope, ctx context.Context, cancelFn context.CancelFunc, requireBranch bool) *func(err error) {vars := mux.Vars(r)planId := vars["planId"]branch := vars["branch"]diff --git a/app/server/handlers/plans_changes.go b/app/server/handlers/plans_changes.goindex 851d0bc3..ce04869f 100644--- a/app/server/handlers/plans_changes.go+++ b/app/server/handlers/plans_changes.go@@ -35,7 +35,7 @@ func CurrentPlanHandler(w http.ResponseWriter, r *http.Request) {var err errorctx, cancel := context.WithCancel(context.Background())- unlockFn := lockRepo(w, r, auth, db.LockScopeRead, ctx, cancel, true)+ unlockFn := LockRepo(w, r, auth, db.LockScopeRead, ctx, cancel, true)if unlockFn == nil {return} else {@@ -105,7 +105,7 @@ func ApplyPlanHandler(w http.ResponseWriter, r *http.Request) {}ctx, cancel := context.WithCancel(context.Background())- unlockFn := lockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)+ unlockFn := LockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)if unlockFn == nil {return} else {@@ -175,7 +175,7 @@ func RejectAllChangesHandler(w http.ResponseWriter, r *http.Request) {var err errorctx, cancel := context.WithCancel(context.Background())- unlockFn := lockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)+ unlockFn := LockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)if unlockFn == nil {return} else {@@ -230,7 +230,7 @@ func RejectFileHandler(w http.ResponseWriter, r *http.Request) {}ctx, cancel := context.WithCancel(context.Background())- unlockFn := lockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)+ unlockFn := LockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)if unlockFn == nil {return} else {@@ -285,7 +285,7 @@ func RejectFilesHandler(w http.ResponseWriter, r *http.Request) {}ctx, cancel := context.WithCancel(context.Background())- unlockFn := lockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)+ unlockFn := LockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)if unlockFn == nil {return} else {@@ -439,7 +439,7 @@ func GetPlanDiffsHandler(w http.ResponseWriter, r *http.Request) {var err errorctx, cancel := context.WithCancel(context.Background())- unlockFn := lockRepo(w, r, auth, db.LockScopeRead, ctx, cancel, true)+ unlockFn := LockRepo(w, r, auth, db.LockScopeRead, ctx, cancel, true)if unlockFn == nil {return} else {diff --git a/app/server/handlers/plans_context.go b/app/server/handlers/plans_context.goindex 8c081b0f..11868457 100644--- a/app/server/handlers/plans_context.go+++ b/app/server/handlers/plans_context.go@@ -30,7 +30,7 @@ func ListContextHandler(w http.ResponseWriter, r *http.Request) {var err errorctx, cancel := context.WithCancel(context.Background())- unlockFn := lockRepo(w, r, auth, db.LockScopeRead, ctx, cancel, true)+ unlockFn := LockRepo(w, r, auth, db.LockScopeRead, ctx, cancel, true)if unlockFn == nil {return} else {@@ -152,7 +152,7 @@ func UpdateContextHandler(w http.ResponseWriter, r *http.Request) {}ctx, cancel := context.WithCancel(context.Background())- unlockFn := lockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)+ unlockFn := LockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)if unlockFn == nil {return} else {@@ -253,7 +253,7 @@ func DeleteContextHandler(w http.ResponseWriter, r *http.Request) {}ctx, cancel := context.WithCancel(context.Background())- unlockFn := lockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)+ unlockFn := LockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)if unlockFn == nil {return} else {diff --git a/app/server/handlers/plans_convo.go b/app/server/handlers/plans_convo.goindex 30b4282c..6f0905bc 100644--- a/app/server/handlers/plans_convo.go+++ b/app/server/handlers/plans_convo.go@@ -28,7 +28,7 @@ func ListConvoHandler(w http.ResponseWriter, r *http.Request) {var err errorctx, cancel := context.WithCancel(context.Background())- unlockFn := lockRepo(w, r, auth, db.LockScopeRead, ctx, cancel, true)+ unlockFn := LockRepo(w, r, auth, db.LockScopeRead, ctx, cancel, true)if unlockFn == nil {return} else {@@ -79,7 +79,7 @@ func GetPlanStatusHandler(w http.ResponseWriter, r *http.Request) {var err errorctx, cancel := context.WithCancel(context.Background())- unlockFn := lockRepo(w, r, auth, db.LockScopeRead, ctx, cancel, true)+ unlockFn := LockRepo(w, r, auth, db.LockScopeRead, ctx, cancel, true)if unlockFn == nil {return} else {diff --git a/app/server/handlers/plans_exec.go b/app/server/handlers/plans_exec.goindex 74284302..e1c26d84 100644--- a/app/server/handlers/plans_exec.go+++ b/app/server/handlers/plans_exec.go@@ -243,7 +243,7 @@ func StopPlanHandler(w http.ResponseWriter, r *http.Request) {var err errorctx, cancel := context.WithCancel(context.Background())- unlockFn := lockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)+ unlockFn := LockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)if unlockFn == nil {return} else {diff --git a/app/server/handlers/plans_versions.go b/app/server/handlers/plans_versions.goindex 0aae3af0..4fd71baf 100644--- a/app/server/handlers/plans_versions.go+++ b/app/server/handlers/plans_versions.go@@ -32,7 +32,7 @@ func ListLogsHandler(w http.ResponseWriter, r *http.Request) {var err errorctx, cancel := context.WithCancel(context.Background())- unlockFn := lockRepo(w, r, auth, db.LockScopeRead, ctx, cancel, true)+ unlockFn := LockRepo(w, r, auth, db.LockScopeRead, ctx, cancel, true)if unlockFn == nil {return} else {@@ -102,7 +102,7 @@ func RewindPlanHandler(w http.ResponseWriter, r *http.Request) {}ctx, cancel := context.WithCancel(context.Background())- unlockFn := lockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)+ unlockFn := LockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)if unlockFn == nil {return} else {diff --git a/app/server/handlers/settings.go b/app/server/handlers/settings.goindex a8928799..b69e061d 100644--- a/app/server/handlers/settings.go+++ b/app/server/handlers/settings.go@@ -34,7 +34,7 @@ func GetSettingsHandler(w http.ResponseWriter, r *http.Request) {var err errorctx, cancel := context.WithCancel(context.Background())- unlockFn := lockRepo(w, r, auth, db.LockScopeRead, ctx, cancel, true)+ unlockFn := LockRepo(w, r, auth, db.LockScopeRead, ctx, cancel, true)if unlockFn == nil {return} else {@@ -94,7 +94,7 @@ func UpdateSettingsHandler(w http.ResponseWriter, r *http.Request) {}ctx, cancel := context.WithCancel(context.Background())- unlockFn := lockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)+ unlockFn := LockRepo(w, r, auth, db.LockScopeWrite, ctx, cancel, true)if unlockFn == nil {return} else {