Skip to content

Commit

Permalink
- F Add auto approver reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclerc-cio committed Dec 5, 2024
1 parent 13115a7 commit ff769f6
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions reporters/reporter_that_automatically_approves.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package reporters

import (
"fmt"
"os"
"path/filepath"
)

type reporterThatAutomaticallyApproves struct{}

// NewQuietReporter creates a new reporter that does nothing.
func NewReporterThatAutomaticallyApproves() Reporter {
return &reporterThatAutomaticallyApproves{}
}

func (s *reporterThatAutomaticallyApproves) Report(approved, received string) bool {

approvedFull, _ := filepath.Abs(approved)
receivedFull, _ := filepath.Abs(received)

// move the pending file to the approved location
fmt.Printf("Automatically approving the received file\napproved: %v\nreceived: %v\n", approvedFull, receivedFull)

// If the approved file exists, delete it, then rename it
if _, err := os.Stat(approved); err == nil {
err = os.Remove(approved)
if err != nil {
fmt.Printf("Error removing file: %v\n", err)
return false
}
}

err := os.Rename(received, approved)

if err != nil {
fmt.Printf("Error moving file: %v\n", err)
return false
}

return true
}

0 comments on commit ff769f6

Please sign in to comment.