@ -474,3 +474,35 @@ func handleSchedules(
return actions_model . CreateScheduleTask ( ctx , crons )
}
// DetectAndHandleSchedules detects the schedule workflows on the default branch and create schedule tasks
func DetectAndHandleSchedules ( ctx context . Context , repo * repo_model . Repository ) error {
gitRepo , err := gitrepo . OpenRepository ( context . Background ( ) , repo )
if err != nil {
return fmt . Errorf ( "git.OpenRepository: %w" , err )
}
defer gitRepo . Close ( )
// Only detect schedule workflows on the default branch
commit , err := gitRepo . GetCommit ( repo . DefaultBranch )
if err != nil {
return fmt . Errorf ( "gitRepo.GetCommit: %w" , err )
}
scheduleWorkflows , err := actions_module . DetectScheduledWorkflows ( gitRepo , commit )
if err != nil {
return fmt . Errorf ( "detect schedule workflows: %w" , err )
}
if len ( scheduleWorkflows ) == 0 {
return nil
}
// We need a notifyInput to call handleSchedules
// Here we use the commit author as the Doer of the notifyInput
commitUser , err := user_model . GetUserByEmail ( ctx , commit . Author . Email )
if err != nil {
return fmt . Errorf ( "get user by email: %w" , err )
}
notifyInput := newNotifyInput ( repo , commitUser , webhook_module . HookEventSchedule )
return handleSchedules ( ctx , scheduleWorkflows , commit , notifyInput , repo . DefaultBranch )
}