@@ -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
587583type 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