mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-10-30 22:11:07 +00:00 
			
		
		
		
	This enables all action run state changes (from a not done to a done
state) to also send a notification.
Moved these:
- models/actions/task.go|423 col 6| func StopTask(ctx context.Context, taskID int64, status Status) error {
- models/actions/run.go|190 col 6| func CancelPreviousJobs(ctx context.Context, repoID int64, ref, workflowID string, event webhook_module.HookEventType) error {
- models/actions/schedule.go|122 col 6| func CleanRepoScheduleTasks(ctx context.Context, repo *repo_model.Repository, cancelPreviousJobs bool) error {
		
	
			
		
			
				
	
	
		
			56 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2023 The Gitea Authors. All rights reserved.
 | |
| // SPDX-License-Identifier: MIT
 | |
| 
 | |
| package repository
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"slices"
 | |
| 
 | |
| 	"forgejo.org/models/db"
 | |
| 	repo_model "forgejo.org/models/repo"
 | |
| 	"forgejo.org/models/unit"
 | |
| 	"forgejo.org/modules/log"
 | |
| 	actions_service "forgejo.org/services/actions"
 | |
| )
 | |
| 
 | |
| // UpdateRepositoryUnits updates a repository's units
 | |
| func UpdateRepositoryUnits(ctx context.Context, repo *repo_model.Repository, units []repo_model.RepoUnit, deleteUnitTypes []unit.Type) (err error) {
 | |
| 	ctx, committer, err := db.TxContext(ctx)
 | |
| 	if err != nil {
 | |
| 		return err
 | |
| 	}
 | |
| 	defer committer.Close()
 | |
| 
 | |
| 	// Delete existing settings of units before adding again
 | |
| 	for _, u := range units {
 | |
| 		deleteUnitTypes = append(deleteUnitTypes, u.Type)
 | |
| 	}
 | |
| 
 | |
| 	if slices.Contains(deleteUnitTypes, unit.TypeActions) {
 | |
| 		if err := actions_service.CleanRepoScheduleTasks(ctx, repo, true); err != nil {
 | |
| 			log.Error("CleanRepoScheduleTasks: %v", err)
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	for _, u := range units {
 | |
| 		if u.Type == unit.TypeActions {
 | |
| 			if err := actions_service.DetectAndHandleSchedules(ctx, repo); err != nil {
 | |
| 				log.Error("DetectAndHandleSchedules: %v", err)
 | |
| 			}
 | |
| 			break
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	if _, err = db.GetEngine(ctx).Where("repo_id = ?", repo.ID).In("type", deleteUnitTypes).Delete(new(repo_model.RepoUnit)); err != nil {
 | |
| 		return err
 | |
| 	}
 | |
| 
 | |
| 	if len(units) > 0 {
 | |
| 		if err = db.Insert(ctx, units); err != nil {
 | |
| 			return err
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	return committer.Commit()
 | |
| }
 |