Skip to content

Commit bd6ae40

Browse files
committed
use tag version
fix linting
1 parent 22739f1 commit bd6ae40

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,4 +348,4 @@ exclude github.com/goccy/go-json v0.4.11
348348

349349
exclude github.com/satori/go.uuid v1.2.0
350350

351-
replace github.com/zricethezav/gitleaks/v8 => github.com/TheFox0x7/gitleaks/v8 v8.0.0-20250416161107-ce27b3ebd696
351+
replace github.com/zricethezav/gitleaks/v8 => github.com/TheFox0x7/gitleaks/v8 v8.24.4-patch-gitea

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ github.com/RoaringBitmap/roaring v1.9.4 h1:yhEIoH4YezLYT04s1nHehNO64EKFTop/wBhxv
8383
github.com/RoaringBitmap/roaring v1.9.4/go.mod h1:6AXUsoIEzDTFFQCe1RbGA6uFONMhvejWj5rqITANK90=
8484
github.com/SaveTheRbtz/zstd-seekable-format-go/pkg v0.7.3 h1:BP0HiyNT3AQEYi+if3wkRcIdQFHtsw6xX3Kx0glckgA=
8585
github.com/SaveTheRbtz/zstd-seekable-format-go/pkg v0.7.3/go.mod h1:hMNtySovKkn2gdDuLqnqveP+mfhUSaBdoBcr2I7Zt0E=
86-
github.com/TheFox0x7/gitleaks/v8 v8.0.0-20250416161107-ce27b3ebd696 h1:HLdcIxXpEGZ1IrqAiQ+ExvAiUBSVPn1xCcmAmR0zaeI=
87-
github.com/TheFox0x7/gitleaks/v8 v8.0.0-20250416161107-ce27b3ebd696/go.mod h1:D3AhHRLVp0DigFQNxAgHcQks8EbF7wCZanT/UbGd0Jo=
86+
github.com/TheFox0x7/gitleaks/v8 v8.24.4-patch-gitea h1:VMXSHOeB5t4e3Hqet9GSTx5oULskEp7dV2i0/cgEhd4=
87+
github.com/TheFox0x7/gitleaks/v8 v8.24.4-patch-gitea/go.mod h1:D3AhHRLVp0DigFQNxAgHcQks8EbF7wCZanT/UbGd0Jo=
8888
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
8989
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
9090
github.com/alecthomas/chroma/v2 v2.2.0/go.mod h1:vf4zrexSH54oEjJ7EdB65tGNHmH3pGZmVkgTP5RHvAs=

routers/private/hook_pre_receive.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"code.gitea.io/gitea/modules/web"
2626
gitea_context "code.gitea.io/gitea/services/context"
2727
pull_service "code.gitea.io/gitea/services/pull"
28+
2829
"github.com/gitleaks/go-gitdiff/gitdiff"
2930
"github.com/zricethezav/gitleaks/v8/cmd/scm"
3031
gitleaks "github.com/zricethezav/gitleaks/v8/detect"
@@ -121,7 +122,7 @@ func HookPreReceive(ctx *gitea_context.PrivateContext) {
121122
newCommitID := opts.NewCommitIDs[i]
122123
refFullName := opts.RefFullNames[i]
123124

124-
preReceiveSecrets(ourCtx, oldCommitID, newCommitID, refFullName)
125+
preReceiveSecrets(ourCtx, oldCommitID, newCommitID)
125126
switch {
126127
case refFullName.IsBranch():
127128
preReceiveBranch(ourCtx, oldCommitID, newCommitID, refFullName)
@@ -542,7 +543,7 @@ func (ctx *preReceiveContext) loadPusherAndPermission() bool {
542543
}
543544

544545
// checks commits for secrets
545-
func preReceiveSecrets(ctx *preReceiveContext, oldCommitID, newCommitID string, refFullName git.RefName) {
546+
func preReceiveSecrets(ctx *preReceiveContext, oldCommitID, newCommitID string) {
546547
detector, err := gitleaks.NewDetectorDefaultConfig()
547548
if err != nil {
548549
ctx.Status(http.StatusTeapot)
@@ -551,22 +552,20 @@ func preReceiveSecrets(ctx *preReceiveContext, oldCommitID, newCommitID string,
551552

552553
repo := ctx.Repo.Repository
553554
out, _, err := git.NewCommand("diff", "-U0").AddDynamicArguments(oldCommitID, newCommitID).RunStdBytes(ctx, &git.RunOpts{Dir: repo.RepoPath(), Env: ctx.env})
554-
// r, w, err := os.Pipe()
555555
if err != nil {
556556
ctx.Status(http.StatusTeapot)
557557
return
558558
}
559-
log.Info("done with diff")
560-
giteaCmd, err := newPreRecieveDiff(bytes.NewReader(out))
561-
log.Info("crerated cmd!")
559+
giteaCmd, err := newPreReceiveDiff(bytes.NewReader(out))
562560
if err != nil {
563-
log.Info("look! a wild error! %v", err)
564561
ctx.Status(http.StatusTeapot)
565562
return
566563
}
567-
log.Info("running the detector!")
568564
findings, err := detector.DetectGit(giteaCmd, gitleaks.NewRemoteInfo(scm.GitHubPlatform, repo.Website))
569-
log.Info("done!")
565+
if err != nil {
566+
ctx.Status(http.StatusTeapot)
567+
return
568+
}
570569
if len(findings) != 0 {
571570
msg := strings.Builder{}
572571
msg.WriteString("This repository has secret detection enabled! Following secrets were detected:\n\n")
@@ -578,26 +577,21 @@ func preReceiveSecrets(ctx *preReceiveContext, oldCommitID, newCommitID string,
578577
}
579578

580579
ctx.JSON(http.StatusForbidden, private.Response{UserMsg: msg.String()})
581-
582580
}
583-
return
584-
585581
}
586582

587583
type giteacmd struct {
588584
diffCh <-chan *gitdiff.File
589-
errCh <-chan error
590585
}
591586

592-
func newPreRecieveDiff(r io.Reader) (*giteacmd, error) {
587+
func newPreReceiveDiff(r io.Reader) (*giteacmd, error) {
593588
diffCh, err := gitdiff.Parse(r)
594589
if err != nil {
595590
return nil, err
596591
}
597592
return &giteacmd{
598593
diffCh: diffCh,
599594
}, nil
600-
601595
}
602596

603597
// DiffFilesCh implements sources.Git.

0 commit comments

Comments
 (0)