fix: execute hook check only on --one-time

Execute hook check only if --one-time  is true and corrected log spelling of webhook and exechook
This commit is contained in:
ChrisERo 2022-01-10 18:42:34 -05:00 committed by chrrodri
parent a362b4a5f4
commit d2a4320e6c
1 changed files with 27 additions and 19 deletions

View File

@ -364,8 +364,11 @@ func main() {
if *flExechookBackoff < time.Second { if *flExechookBackoff < time.Second {
handleError(log, true, "ERROR: --exechook-backoff must be at least 1s") handleError(log, true, "ERROR: --exechook-backoff must be at least 1s")
} }
if *flOneTime {
exechookChannel = make(chan bool, 1) exechookChannel = make(chan bool, 1)
} }
}
if *flWebhookURL != "" { if *flWebhookURL != "" {
if *flWebhookStatusSuccess < -1 { if *flWebhookStatusSuccess < -1 {
@ -377,8 +380,11 @@ func main() {
if *flWebhookBackoff < time.Second { if *flWebhookBackoff < time.Second {
handleError(log, true, "ERROR: --webhook-backoff must be at least 1s") handleError(log, true, "ERROR: --webhook-backoff must be at least 1s")
} }
if *flOneTime {
webhookChannel = make(chan bool, 1) webhookChannel = make(chan bool, 1)
} }
}
if *flPassword != "" && *flPasswordFile != "" { if *flPassword != "" && *flPasswordFile != "" {
handleError(log, false, "ERROR: only one of --password and --password-file may be specified") handleError(log, false, "ERROR: only one of --password and --password-file may be specified")
@ -630,25 +636,27 @@ func main() {
} }
if initialSync { if initialSync {
// Determine if git-sync should terminate for one of several reasons
if *flOneTime {
// Wait for hooks to complete at least once, if not nil, before checking whether to stop program // Wait for hooks to complete at least once, if not nil, before checking whether to stop program
// Assumes that if hook channels are not nil, they will have at least one value before getting closed // Assumes that if hook channels are not nil, they will have at least one value before getting closed
exitCode := 0 // if all hooks succeeded, exit code is 0, else set to 1
if exechookChannel != nil { if exechookChannel != nil {
exechookChannelFinishedSuccessfully := <-exechookChannel exechookChannelFinishedSuccessfully := <-exechookChannel
if !exechookChannelFinishedSuccessfully { if !exechookChannelFinishedSuccessfully {
log.Error(nil, "exec hook completed with error") log.Error(nil, "exechook completed with error")
exitCode = 1
} }
} }
if webhookChannel != nil { if webhookChannel != nil {
webhookChannelFinishedSuccessfully := <-webhookChannel webhookChannelFinishedSuccessfully := <-webhookChannel
if !webhookChannelFinishedSuccessfully { if !webhookChannelFinishedSuccessfully {
log.Error(nil, "web hook completed with error") log.Error(nil, "webhook completed with error")
} }
exitCode = 1
} }
// Determine if git-sync should terminate
if *flOneTime {
log.DeleteErrorFile() log.DeleteErrorFile()
os.Exit(0) os.Exit(exitCode)
} }
if isHash, err := git.RevIsHash(ctx); err != nil { if isHash, err := git.RevIsHash(ctx); err != nil {
log.Error(err, "can't tell if rev is a git hash, exiting", "rev", git.rev) log.Error(err, "can't tell if rev is a git hash, exiting", "rev", git.rev)