Skip to content

Commit 0cc8914

Browse files
committed
CV Read gitconfig variables
1 parent 8d8d32c commit 0cc8914

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

cmd/git-remote-gitopia/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ import (
77
"os"
88

99
sdk "github.com/cosmos/cosmos-sdk/types"
10+
"github.com/gitopia/git-remote-gitopia/config"
1011
core "github.com/gitopia/git-remote-gitopia/core"
1112
)
1213

1314
func Main(args []string, reader io.Reader, writer io.Writer, logger *log.Logger) error {
15+
config.LoadGitConfig()
16+
1417
conf := sdk.GetConfig()
1518
conf.SetBech32PrefixForAccount(AccountAddressPrefix, AccountPubKeyPrefix)
1619
// cannot seal the config

config/config.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package config
2+
3+
import (
4+
"cosmossdk.io/errors"
5+
goGitConfig "github.com/go-git/go-git/v5/config"
6+
)
7+
8+
const (
9+
AppName = "git-remote-gitopia"
10+
gitopiaConfigSection = "gitopia"
11+
12+
gitopiaConfigChainid = "chainid"
13+
gitopiaConfigGrpchost = "grpchost"
14+
gitopiaConfigGitserverhost = "gitserverhost"
15+
gitopiaConfigTmaddr = "tmaddr"
16+
gitopiaConfigGasprices = "gasprices"
17+
gitopiaConfigFeegranter = "feegranter"
18+
gitopiaConfigDenom = "denom"
19+
)
20+
21+
func LoadGitConfig() error {
22+
conf, err := goGitConfig.LoadConfig(goGitConfig.GlobalScope)
23+
if err != nil {
24+
return errors.Wrap(err, "error loading git config")
25+
}
26+
if conf.Raw.HasSection(gitopiaConfigSection) &&
27+
conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigChainid) {
28+
ChainId = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigChainid)
29+
}
30+
if conf.Raw.HasSection(gitopiaConfigSection) &&
31+
conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigGrpchost) {
32+
GRPCHost = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigGrpchost)
33+
}
34+
if conf.Raw.HasSection(gitopiaConfigSection) &&
35+
conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigGitserverhost) {
36+
GitServerHost = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigGitserverhost)
37+
}
38+
if conf.Raw.HasSection(gitopiaConfigSection) &&
39+
conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigTmaddr) {
40+
TmAddr = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigTmaddr)
41+
}
42+
if conf.Raw.HasSection(gitopiaConfigSection) &&
43+
conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigGasprices) {
44+
GasPrices = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigGasprices)
45+
}
46+
if conf.Raw.HasSection(gitopiaConfigSection) &&
47+
conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigFeegranter) {
48+
FeeGranterAddr = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigFeegranter)
49+
}
50+
if conf.Raw.HasSection(gitopiaConfigSection) &&
51+
conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigDenom) {
52+
Denom = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigDenom)
53+
}
54+
return nil
55+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/gitopia/git-remote-gitopia
33
go 1.19
44

55
require (
6+
cosmossdk.io/errors v1.0.0-beta.7
67
github.com/cosmos/cosmos-sdk v0.46.12
78
github.com/gitopia/gitopia-go v0.5.0
89
github.com/gitopia/gitopia/v2 v2.0.1
@@ -20,7 +21,6 @@ require (
2021
cloud.google.com/go/compute/metadata v0.2.3 // indirect
2122
cloud.google.com/go/iam v0.11.0 // indirect
2223
cloud.google.com/go/storage v1.27.0 // indirect
23-
cosmossdk.io/errors v1.0.0-beta.7 // indirect
2424
cosmossdk.io/math v1.0.0-beta.3 // indirect
2525
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
2626
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect

0 commit comments

Comments
 (0)