@@ -56,6 +56,8 @@ const (
56
56
numToMakeOutdated = 10
57
57
)
58
58
59
+ var errNoChanges = errors .New ("nothing to commit" )
60
+
59
61
type Watcher interface {
60
62
Run (context.Context ) error
61
63
}
@@ -336,6 +338,7 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve
336
338
outDatedDuration = time .Hour
337
339
gitUpdateEvent = false
338
340
branchHandledEvents = make (map [string ][]* pipedservice.ReportEventStatusesRequest_Event , len (eventCfgs ))
341
+ gitNoChangeEvents = make ([]* pipedservice.ReportEventStatusesRequest_Event , 0 )
339
342
)
340
343
for _ , e := range eventCfgs {
341
344
for _ , cfg := range e .Configs {
@@ -388,7 +391,8 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve
388
391
switch handler .Type {
389
392
case config .EventWatcherHandlerTypeGitUpdate :
390
393
branchName , err := w .commitFiles (ctx , latestEvent , matcher .Name , handler .Config .CommitMessage , e .GitPath , handler .Config .Replacements , tmpRepo , handler .Config .MakePullRequest )
391
- if err != nil {
394
+ noChange := errors .Is (err , errNoChanges )
395
+ if err != nil && ! noChange {
392
396
w .logger .Error ("failed to commit outdated files" , zap .Error (err ))
393
397
handledEvent := & pipedservice.ReportEventStatusesRequest_Event {
394
398
Id : latestEvent .Id ,
@@ -398,12 +402,18 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve
398
402
branchHandledEvents [branchName ] = append (branchHandledEvents [branchName ], handledEvent )
399
403
continue
400
404
}
405
+
401
406
handledEvent := & pipedservice.ReportEventStatusesRequest_Event {
402
- Id : latestEvent .Id ,
403
- Status : model .EventStatus_EVENT_SUCCESS ,
404
- StatusDescription : fmt .Sprintf ("Successfully updated %d files in the %q repository" , len (handler .Config .Replacements ), repoID ),
407
+ Id : latestEvent .Id ,
408
+ Status : model .EventStatus_EVENT_SUCCESS ,
409
+ }
410
+ if noChange {
411
+ handledEvent .StatusDescription = "Nothing to commit"
412
+ gitNoChangeEvents = append (gitNoChangeEvents , handledEvent )
413
+ } else {
414
+ handledEvent .StatusDescription = fmt .Sprintf ("Successfully updated %d files in the %q repository" , len (handler .Config .Replacements ), repoID )
415
+ branchHandledEvents [branchName ] = append (branchHandledEvents [branchName ], handledEvent )
405
416
}
406
- branchHandledEvents [branchName ] = append (branchHandledEvents [branchName ], handledEvent )
407
417
if latestEvent .CreatedAt > maxTimestamp {
408
418
maxTimestamp = latestEvent .CreatedAt
409
419
}
@@ -428,6 +438,13 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve
428
438
return nil
429
439
}
430
440
441
+ if len (gitNoChangeEvents ) > 0 {
442
+ if _ , err := w .apiClient .ReportEventStatuses (ctx , & pipedservice.ReportEventStatusesRequest {Events : gitNoChangeEvents }); err != nil {
443
+ w .logger .Error ("failed to report event statuses" , zap .Error (err ))
444
+ }
445
+ w .executionMilestoneMap .Store (repoID , maxTimestamp )
446
+ }
447
+
431
448
var responseError error
432
449
retry := backoff .NewRetry (retryPushNum , backoff .NewConstant (retryPushInterval ))
433
450
for branch , events := range branchHandledEvents {
@@ -603,6 +620,7 @@ func (w *watcher) updateValues(ctx context.Context, repo git.Repo, repoID string
603
620
}
604
621
605
622
// commitFiles commits changes if the data in Git is different from the latest event.
623
+ // If there are no changes to commit, it returns errNoChanges.
606
624
func (w * watcher ) commitFiles (ctx context.Context , latestEvent * model.Event , eventName , commitMsg , gitPath string , replacements []config.EventWatcherReplacement , repo git.Repo , newBranch bool ) (string , error ) {
607
625
// Determine files to be changed by comparing with the latest event.
608
626
changes := make (map [string ][]byte , len (replacements ))
@@ -641,7 +659,7 @@ func (w *watcher) commitFiles(ctx context.Context, latestEvent *model.Event, eve
641
659
changes [filePath ] = newContent
642
660
}
643
661
if len (changes ) == 0 {
644
- return "" , nil
662
+ return "" , errNoChanges
645
663
}
646
664
647
665
args := argsTemplate {
0 commit comments