Skip to content

Commit

Permalink
retry push commits in execute func
Browse files Browse the repository at this point in the history
Signed-off-by: nnnkkk7 <[email protected]>
  • Loading branch information
nnnkkk7 committed Jun 26, 2023
1 parent d53c906 commit 21cb14b
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions pkg/app/piped/eventwatcher/eventwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,23 @@ func (w *watcher) execute(ctx context.Context, repo git.Repo, repoID string, eve
})
continue
}
if handler.Config.MakePullRequest {
retry := backoff.NewRetry(retryPushNum, backoff.NewConstant(retryPushInterval))
_, err = retry.Do(ctx, func() (interface{}, error) {
err := tmpRepo.Push(ctx, tmpRepo.GetClonedBranch())
return nil, err
})
if err != nil {
w.logger.Error("failed to push commits", zap.Error(err))
handledEvents = append(handledEvents, &pipedservice.ReportEventStatusesRequest_Event{
Id: latestEvent.Id,
Status: model.EventStatus_EVENT_FAILURE,
StatusDescription: fmt.Sprintf("Failed to push commits: %v", err),
})
continue
}

}
handledEvents = append(handledEvents, &pipedservice.ReportEventStatusesRequest_Event{
Id: latestEvent.Id,
Status: model.EventStatus_EVENT_SUCCESS,
Expand Down Expand Up @@ -644,11 +661,6 @@ func (w *watcher) commitFiles(ctx context.Context, latestData, eventName, commit
if err := repo.CommitChanges(ctx, branch, commitMsg, newBranch, changes); err != nil {
return fmt.Errorf("failed to perform git commit: %w", err)
}
if newBranch {
if err := repo.Push(ctx, branch); err != nil {
return fmt.Errorf("failed to perform git push: %w", err)
}
}
w.logger.Info(fmt.Sprintf("event watcher will update values of Event %q", eventName))
return nil
}
Expand Down

0 comments on commit 21cb14b

Please sign in to comment.