Skip to content

Commit d204d8d

Browse files
authored
Merge pull request #60 from gitopia/fix-git-hook
Configure grpc host during build time for git hooks
2 parents c6a940f + ff3e920 commit d204d8d

9 files changed

Lines changed: 26 additions & 23 deletions

File tree

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
GITOPIA_ENV ?= prod
2+
BUILD_FLAGS := -tags "$(GITOPIA_ENV)"
3+
14
all: install
25

36
.PHONY: build
@@ -11,7 +14,7 @@ build:
1114
install: go.sum
1215
@echo "--> Installing gitopia services"
1316
@go install -mod=readonly .
14-
@go install ./hooks/gitopia-pre-receive
17+
@go install $(BUILD_FLAGS) ./hooks/gitopia-pre-receive
1518
@go install ./hooks/gitopia-post-receive
1619

1720
go.sum: go.mod

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## [v2.2.0] - 2023-09-22
4+
- Configure grpc host during build
5+
36
## [v2.1.0] - 2023-07-27
47

58
- fix pr diff api to return git triple dot diff

hooks/gitopia-post-receive/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/gitopia/git-server/hooks/utils"
1010
"github.com/pkg/errors"
11-
"github.com/spf13/viper"
1211
)
1312

1413
func receive(reader io.Reader) error {
@@ -23,7 +22,7 @@ func receive(reader io.Reader) error {
2322
}
2423

2524
// create dangling ref
26-
if force || input.Action == utils.DeleteAction{
25+
if force || input.Action == utils.DeleteAction {
2726
cmd := exec.Command("git", "update-ref", "refs/dangling/"+input.OldRev, input.OldRev)
2827
errPipe, err := cmd.StderrPipe()
2928
if err != nil {
@@ -51,7 +50,6 @@ func receive(reader io.Reader) error {
5150
}
5251

5352
func main() {
54-
viper.AutomaticEnv()
5553
// Git hook data is provided via STDIN
5654
if err := receive(os.Stdin); err != nil {
5755
log.Println(err)
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
# gitopia pre-receive events
1+
# gitopia post-receive events
22

33
gitopia post receive hook for git server
4-
5-
6-
## configuration
7-
set below environment variables
8-
```
9-
export GITOPIA_ADDR="localhost:9090"
10-
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build prod
2+
3+
package config
4+
5+
const (
6+
GRPCHost = "grpc.gitopia.com:9090"
7+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build testing
2+
3+
package config
4+
5+
const (
6+
GRPCHost = "localhost:9090"
7+
)

hooks/gitopia-pre-receive/gitopia.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import (
44
"context"
55

66
"cosmossdk.io/errors"
7+
"github.com/gitopia/git-server/hooks/gitopia-pre-receive/config"
78
"github.com/gitopia/gitopia-go"
89
"github.com/gitopia/gitopia/v2/x/gitopia/types"
9-
"github.com/spf13/viper"
1010
)
1111

1212
func IsForcePushAllowedForBranch(repo uint64, branch string) (bool, error) {
13-
qc, err := gitopia.GetQueryClient(viper.GetString("GITOPIA_ADDR"))
13+
qc, err := gitopia.GetQueryClient(config.GRPCHost)
1414
if err != nil {
1515
return false, errors.Wrap(err, "error connecting to gitopia")
1616
}
@@ -31,4 +31,4 @@ func IsForcePushAllowedForBranch(repo uint64, branch string) (bool, error) {
3131
return false, errors.Wrap(err, "error querying repo branch")
3232
}
3333
return branchRes.Branch.AllowForcePush, nil
34-
}
34+
}

hooks/gitopia-pre-receive/main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/gitopia/git-server/hooks/utils"
1010
"github.com/pkg/errors"
11-
"github.com/spf13/viper"
1211
)
1312

1413
var NonFFErr = errors.New("non fast-forward pushes are not allowed")
@@ -47,7 +46,6 @@ func receive(reader io.Reader) error {
4746
}
4847

4948
func main() {
50-
viper.AutomaticEnv()
5149
// Git hook data is provided via STDIN
5250
if err := receive(os.Stdin); err != nil {
5351
log.Println(err)
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
# gitopia pre-receive events
22

33
gitopia pre receive hook for git server
4-
5-
6-
## configuration
7-
set below environment variables
8-
```
9-
export GITOPIA_ADDR="localhost:9090"
104
```

0 commit comments

Comments
 (0)