Skip to content

Commit e7c6adb

Browse files
committed
add LoadRepository for task
1 parent 5a033a0 commit e7c6adb

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

models/actions/task.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
auth_model "code.gitea.io/gitea/models/auth"
1313
"code.gitea.io/gitea/models/db"
14+
repo_model "code.gitea.io/gitea/models/repo"
1415
"code.gitea.io/gitea/models/unit"
1516
"code.gitea.io/gitea/modules/container"
1617
"code.gitea.io/gitea/modules/log"
@@ -37,9 +38,10 @@ type ActionTask struct {
3738
Started timeutil.TimeStamp `xorm:"index"`
3839
Stopped timeutil.TimeStamp `xorm:"index(stopped_log_expired)"`
3940

40-
RepoID int64 `xorm:"index"`
41-
OwnerID int64 `xorm:"index"`
42-
CommitSHA string `xorm:"index"`
41+
RepoID int64 `xorm:"index"`
42+
Repo *repo_model.Repository `xorm:"-"`
43+
OwnerID int64 `xorm:"index"`
44+
CommitSHA string `xorm:"index"`
4345
IsForkPullRequest bool
4446

4547
Token string `xorm:"-"`
@@ -151,6 +153,14 @@ func (task *ActionTask) GenerateToken() (err error) {
151153
return err
152154
}
153155

156+
func (task *ActionTask) LoadRepository(ctx context.Context) (err error) {
157+
if task.Repo != nil {
158+
return nil
159+
}
160+
task.Repo, err = repo_model.GetRepositoryByID(ctx, task.RepoID)
161+
return
162+
}
163+
154164
func GetTaskByID(ctx context.Context, id int64) (*ActionTask, error) {
155165
var task ActionTask
156166
has, err := db.GetEngine(ctx).Where("id=?", id).Get(&task)

routers/web/repo/githttp.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,12 @@ func httpBase(ctx *context.Context) *serviceHandler {
195195
return nil
196196
}
197197
if task.RepoID != repo.ID {
198-
actionsCfg := repo.MustGetUnit(ctx, unit.TypeActions).ActionsConfig()
199-
taskRepo, err := repo_model.GetRepositoryByID(ctx, task.RepoID)
200-
if err != nil {
201-
ctx.ServerError("GetRepositoryByID", err)
198+
if err := task.LoadRepository(ctx); err != nil {
199+
ctx.ServerError("LoadRepository", err)
202200
return nil
203201
}
204-
if !actionsCfg.IsCollaborativeOwner(taskRepo.OwnerID) || taskRepo.OwnerID != repo.OwnerID || !taskRepo.IsPrivate {
202+
actionsCfg := repo.MustGetUnit(ctx, unit.TypeActions).ActionsConfig()
203+
if !actionsCfg.IsCollaborativeOwner(task.Repo.OwnerID) || !task.Repo.IsPrivate {
205204
// See https://docs.github.com/en/actions/sharing-automations/sharing-actions-and-workflows-from-your-private-repository
206205
// Any actions or reusable workflows stored in the private repository can be used in
207206
// workflows defined in other private repositories owned by the same organization or user.

0 commit comments

Comments
 (0)