/
object_config.go
74 lines (64 loc) · 1.48 KB
/
object_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package gptest
import (
"net/url"
"github.com/opensibyl/sibyl-go-client"
)
type SharedConfig struct {
Token string `json:"token"`
SrcDir string `json:"srcDir"`
OutputDir string `json:"outputDir"`
RepoInfo *RepoInfo `json:"repoInfo"`
SibylUrl string `json:"sibylUrl"`
Before string `json:"before"`
After string `json:"after"`
FileInclude string `json:"fileInclude"`
PromptFile string `json:"promptFile"`
}
func DefaultConfig() SharedConfig {
return SharedConfig{
"",
".",
".",
nil,
"http://127.0.0.1:9875",
"HEAD~1",
"HEAD",
"",
"",
}
}
func (conf *SharedConfig) NewSibylClient() (*openapi.APIClient, error) {
parsed, err := conf.parseSibylUrl()
if err != nil {
return nil, err
}
configuration := openapi.NewConfiguration()
configuration.Scheme = parsed.Scheme
configuration.Host = parsed.Host
return openapi.NewAPIClient(configuration), nil
}
func (conf *SharedConfig) LocalSibyl() bool {
parsed, err := conf.parseSibylUrl()
if err != nil {
return false
}
hostName := parsed.Hostname()
if hostName == "127.0.0.1" || hostName == "localhost" {
return true
}
return false
}
func (conf *SharedConfig) GetSibylPort() string {
parsed, err := conf.parseSibylUrl()
if err != nil {
return ""
}
return parsed.Port()
}
func (conf *SharedConfig) parseSibylUrl() (*url.URL, error) {
return url.Parse(conf.SibylUrl)
}
type RepoInfo struct {
RepoId string `json:"repoId"`
RevHash string `json:"revHash"`
}