@@ -248,7 +248,7 @@ func CheckFileProtection(oldCommitID, newCommitID string, patterns []glob.Glob,
248
248
if len (patterns ) == 0 {
249
249
return nil , nil
250
250
}
251
- affectedFiles , err := getAffectedFiles (oldCommitID , newCommitID , env , repo )
251
+ affectedFiles , err := git . GetAffectedFiles (oldCommitID , newCommitID , env , repo )
252
252
if err != nil {
253
253
return nil , err
254
254
}
@@ -278,7 +278,7 @@ func CheckUnprotectedFiles(oldCommitID, newCommitID string, patterns []glob.Glob
278
278
if len (patterns ) == 0 {
279
279
return false , nil
280
280
}
281
- affectedFiles , err := getAffectedFiles (oldCommitID , newCommitID , env , repo )
281
+ affectedFiles , err := git . GetAffectedFiles (oldCommitID , newCommitID , env , repo )
282
282
if err != nil {
283
283
return false , err
284
284
}
@@ -298,48 +298,6 @@ func CheckUnprotectedFiles(oldCommitID, newCommitID string, patterns []glob.Glob
298
298
return true , nil
299
299
}
300
300
301
- func getAffectedFiles (oldCommitID , newCommitID string , env []string , repo * git.Repository ) ([]string , error ) {
302
- stdoutReader , stdoutWriter , err := os .Pipe ()
303
- if err != nil {
304
- log .Error ("Unable to create os.Pipe for %s" , repo .Path )
305
- return nil , err
306
- }
307
- defer func () {
308
- _ = stdoutReader .Close ()
309
- _ = stdoutWriter .Close ()
310
- }()
311
-
312
- affectedFiles := make ([]string , 0 , 32 )
313
-
314
- // Run `git diff --name-only` to get the names of the changed files
315
- err = git .NewCommand ("diff" , "--name-only" , oldCommitID , newCommitID ).
316
- RunInDirTimeoutEnvFullPipelineFunc (env , - 1 , repo .Path ,
317
- stdoutWriter , nil , nil ,
318
- func (ctx context.Context , cancel context.CancelFunc ) error {
319
- // Close the writer end of the pipe to begin processing
320
- _ = stdoutWriter .Close ()
321
- defer func () {
322
- // Close the reader on return to terminate the git command if necessary
323
- _ = stdoutReader .Close ()
324
- }()
325
- // Now scan the output from the command
326
- scanner := bufio .NewScanner (stdoutReader )
327
- for scanner .Scan () {
328
- path := strings .TrimSpace (scanner .Text ())
329
- if len (path ) == 0 {
330
- continue
331
- }
332
- affectedFiles = append (affectedFiles , path )
333
- }
334
- return scanner .Err ()
335
- })
336
- if err != nil {
337
- log .Error ("Unable to get affected files for commits from %s to %s in %s: %v" , oldCommitID , newCommitID , repo .Path , err )
338
- }
339
-
340
- return affectedFiles , err
341
- }
342
-
343
301
// checkPullFilesProtection check if pr changed protected files and save results
344
302
func checkPullFilesProtection (pr * models.PullRequest , gitRepo * git.Repository ) error {
345
303
if err := pr .LoadProtectedBranch (); err != nil {
0 commit comments