38 lines
1.3 KiB
Go
38 lines
1.3 KiB
Go
package clientcmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
clientconfig "github.com/deranjer/gvc/client/clientconfig"
|
|
"github.com/deranjer/gvc/common"
|
|
"github.com/go-resty/resty/v2"
|
|
)
|
|
|
|
// RefreshContent gets all the new file locks and updated pulls from the server (like git fetch)
|
|
func RefreshContent(conf *clientconfig.Gvcconfig, repoName string) error { //TODO: need to change command to be able to target user specified servers
|
|
connectionString, err := FindServer("", conf.CurrentBranch, conf)
|
|
var refreshResult common.RepoRefreshRequest
|
|
if err != nil {
|
|
return err
|
|
}
|
|
client := resty.New()
|
|
resp, err := client.R().
|
|
SetPathParams(map[string]string{
|
|
"repoName": repoName,
|
|
}).
|
|
SetResult(&refreshResult). // Automatically unmarshal the JSON response to our struct
|
|
Get(connectionString + "/refresh/" + "{repoName}") //creating the full string to get info
|
|
if err != nil {
|
|
return fmt.Errorf("error connecting to server at: %s: error was: %s", connectionString, err)
|
|
}
|
|
if resp.IsError() {
|
|
if resp.StatusCode() == 404 {
|
|
return fmt.Errorf("error: repo %s was not found on server, 404: %s", repoName, resp.Request.URL)
|
|
}
|
|
return fmt.Errorf("response not a success: %d: connection URL: %s", resp.StatusCode(), resp.Request.URL)
|
|
}
|
|
fmt.Println(resp)
|
|
fmt.Printf("%+v\n", refreshResult)
|
|
return nil
|
|
}
|