@@ -16,6 +16,7 @@ import (
1616	user_model "code.gitea.io/gitea/models/user" 
1717	"code.gitea.io/gitea/modules/git" 
1818	"code.gitea.io/gitea/modules/json" 
19+ 	"code.gitea.io/gitea/modules/setting" 
1920	api "code.gitea.io/gitea/modules/structs" 
2021	"code.gitea.io/gitea/modules/timeutil" 
2122	"code.gitea.io/gitea/modules/util" 
@@ -171,6 +172,7 @@ func (run *ActionRun) IsSchedule() bool {
171172
172173func  updateRepoRunsNumbers (ctx  context.Context , repo  * repo_model.Repository ) error  {
173174	_ , err  :=  db .GetEngine (ctx ).ID (repo .ID ).
175+ 		NoAutoTime ().
174176		SetExpr ("num_action_runs" ,
175177			builder .Select ("count(*)" ).From ("action_run" ).
176178				Where (builder.Eq {"repo_id" : repo .ID }),
@@ -342,13 +344,13 @@ func InsertRun(ctx context.Context, run *ActionRun, jobs []*jobparser.SingleWork
342344	return  committer .Commit ()
343345}
344346
345- func  GetRunByID (ctx  context.Context , id  int64 ) (* ActionRun , error ) {
347+ func  GetRunByRepoAndID (ctx  context.Context , repoID ,  runID  int64 ) (* ActionRun , error ) {
346348	var  run  ActionRun 
347- 	has , err  :=  db .GetEngine (ctx ).Where ("id=?" , id ).Get (& run )
349+ 	has , err  :=  db .GetEngine (ctx ).Where ("id=? AND repo_id=? " , runID ,  repoID ).Get (& run )
348350	if  err  !=  nil  {
349351		return  nil , err 
350352	} else  if  ! has  {
351- 		return  nil , fmt .Errorf ("run with id %d: %w" , id , util .ErrNotExist )
353+ 		return  nil , fmt .Errorf ("run with id %d: %w" , runID , util .ErrNotExist )
352354	}
353355
354356	return  & run , nil 
@@ -419,17 +421,10 @@ func UpdateRun(ctx context.Context, run *ActionRun, cols ...string) error {
419421
420422	if  run .Status  !=  0  ||  slices .Contains (cols , "status" ) {
421423		if  run .RepoID  ==  0  {
422- 			run , err  =  GetRunByID (ctx , run .ID )
423- 			if  err  !=  nil  {
424- 				return  err 
425- 			}
424+ 			setting .PanicInDevOrTesting ("RepoID should not be 0" )
426425		}
427- 		if  run .Repo  ==  nil  {
428- 			repo , err  :=  repo_model .GetRepositoryByID (ctx , run .RepoID )
429- 			if  err  !=  nil  {
430- 				return  err 
431- 			}
432- 			run .Repo  =  repo 
426+ 		if  err  =  run .LoadRepo (ctx ); err  !=  nil  {
427+ 			return  err 
433428		}
434429		if  err  :=  updateRepoRunsNumbers (ctx , run .Repo ); err  !=  nil  {
435430			return  err 
0 commit comments