@ -6,8 +6,9 @@ package git
import (
"bufio"
"bytes "
"context "
"fmt"
"os"
"sort"
"strconv"
"strings"
@ -49,6 +50,15 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
}
stats . CommitCountInAllBranches = c
stdoutReader , stdoutWriter , err := os . Pipe ( )
if err != nil {
return nil , err
}
defer func ( ) {
_ = stdoutReader . Close ( )
_ = stdoutWriter . Close ( )
} ( )
args := [ ] string { "log" , "--numstat" , "--no-merges" , "--pretty=format:---%n%h%n%an%n%ae%n" , "--date=iso" , fmt . Sprintf ( "--since='%s'" , since ) }
if len ( branch ) == 0 {
args = append ( args , "--branches=*" )
@ -56,12 +66,14 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
args = append ( args , "--first-parent" , branch )
}
stdout , err = NewCommand ( args ... ) . RunInDirBytes ( repo . Path )
if err != nil {
return nil , err
}
stderr := new ( strings . Builder )
err = NewCommand ( args ... ) . RunInDirTimeoutEnvFullPipelineFunc (
nil , - 1 , repo . Path ,
stdoutWriter , stderr , nil ,
func ( ctx context . Context , cancel context . CancelFunc ) error {
_ = stdoutWriter . Close ( )
scanner := bufio . NewScanner ( bytes . NewReader ( stdout ) )
scanner := bufio . NewScanner ( stdoutReader )
scanner . Split ( bufio . ScanLines )
stats . CommitCount = 0
stats . Additions = 0
@ -130,5 +142,12 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
stats . ChangedFiles = int64 ( len ( files ) )
stats . Authors = a
_ = stdoutReader . Close ( )
return nil
} )
if err != nil {
return nil , fmt . Errorf ( "Failed to get GetCodeActivityStats for repository.\nError: %w\nStderr: %s" , err , stderr )
}
return stats , nil
}