package engine import ( "fmt" "net/http" "github.com/deranjer/gvc/common" serverconfig "github.com/deranjer/gvc/server/serverconfig" "github.com/labstack/echo" ) // GetInfo return the relevant repo specific info to the client func (Server *GVCServer) GetInfo(context echo.Context) error { repo := context.Param("repo") fmt.Println("Asking about repo: ", repo) config := Server.Config var repoInfo RepoInfoRequest // Create an engine struct that contains basic server info as well as all repo info for _, knownRepo := range config.Repos { if knownRepo.RepoName == repo { repoInfo.BindIP = config.BindIP repoInfo.Port = config.Port repoInfo.RawPort = config.RawPort repoInfo.Version = config.Version repoInfo.Repo = knownRepo for i := range repoInfo.Repo.KnownClients { // Blank out the client keys repoInfo.Repo.KnownClients[i].Key = "REDACTED" } } } return context.JSONPretty(http.StatusAccepted, repoInfo, " ") } // LockFile just locks the file/folder/wildcard func (Server *GVCServer) LockFile(context echo.Context) error { fileType := context.Param("type") fileName := context.Param("name") repoName := context.Param("repo") var repo serverconfig.RepoConfig for i, knownRepo := range Server.Config.Repos { if knownRepo.RepoName == repoName { repo = Server.Config.Repos[i] } } switch fileType { case "file": err := common.CheckFileTypes(fileName, fileType, repo.Locked) if err != nil { return fmt.Errorf("failed checking file lock: %s", err) } fmt.Println("Filename: ", fileName) } return nil } // Refresh sends all updated information to client (like git fetch) func (Server *GVCServer) Refresh(context echo.Context) error { repoName := context.Param("repo") var serverRepo serverconfig.RepoConfig for i, repo := range Server.Config.Repos { if repo.RepoName == repoName { serverRepo = Server.Config.Repos[i] } } // pull the locks and ignores to send back to client branches := serverRepo.LocalBranches serverLocks := serverRepo.Locked serverIgnores := serverRepo.DefaultIgnores refreshResult := common.RepoRefreshRequest{ Branches: branches, Locked: serverLocks, Ignores: serverIgnores, } return context.JSON(http.StatusOK, refreshResult) } // Revert fetches the supplied file (or entire repo) at version X and pushes it to the client // TODO: This should perhaps just be part of PULL? func (Server *GVCServer) Revert(context echo.Context) error { repoName := context.Param("repo") return context.JSON(http.StatusOK, repoName) } // Pull fetches the latest changes from the server to the client. func (Server *GVCServer) Pull(context echo.Context) error { helloMsg := "server alive" return context.JSON(http.StatusOK, helloMsg) } // Hello just verifies the server is running //TODO remove this, just extra shit we are sending func (Server *GVCServer) Hello(context echo.Context) error { helloMsg := "server alive" return context.JSON(http.StatusOK, helloMsg) }