mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-04 05:18:25 +00:00 
			
		
		
		
	Avoid user does not exist error when detecting schedule actions when the commit author is an external user (#30357)
 When repo is a mirror, and commit author is an external user, then `GetUserByEmail` will return error. reproduce/test: - mirror Gitea to your instance - disable action and enable it again, this will trigger `DetectAndHandleSchedules` ps: also follow #24706, it only fixed normal runs, not scheduled runs.
This commit is contained in:
		@@ -40,6 +40,9 @@ func (schedules ScheduleList) LoadTriggerUser(ctx context.Context) error {
 | 
			
		||||
			schedule.TriggerUser = user_model.NewActionsUser()
 | 
			
		||||
		} else {
 | 
			
		||||
			schedule.TriggerUser = users[schedule.TriggerUserID]
 | 
			
		||||
			if schedule.TriggerUser == nil {
 | 
			
		||||
				schedule.TriggerUser = user_model.NewGhostUser()
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
 
 | 
			
		||||
@@ -525,12 +525,9 @@ func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 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)
 | 
			
		||||
	// if repo is a mirror, commit author maybe an external user,
 | 
			
		||||
	// so we use action user as the Doer of the notifyInput
 | 
			
		||||
	notifyInput := newNotifyInput(repo, user_model.NewActionsUser(), webhook_module.HookEventSchedule)
 | 
			
		||||
 | 
			
		||||
	return handleSchedules(ctx, scheduleWorkflows, commit, notifyInput, repo.DefaultBranch)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user