mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-13 00:16:07 +02:00
fix: restore ctx in URL construction and correct load strategies
- Remove spurious context.ReferencesGitRepo(true) from /actions route group - ToActionTask: restore targeted loads (LoadJob/LoadRun/LoadRepo) instead of LoadAttributes which unnecessarily loads task steps; use httplib.MakeAbsoluteURL(ctx, ...) for the URL field - ToActionWorkflowRun: replace run.LoadAttributes with direct repo assignment + LoadTriggerUser to avoid redundant language-stats query; restore attempt.Run = run before attempt.LoadAttributes to prevent redundant DB re-fetch; restore ctx to APIURL/HTMLURL calls - ToActionWorkflowJob: restore ctx to APIURL and HTMLURL calls Co-Authored-By: Claude <claude-sonnet-4-6@anthropic.com>
This commit is contained in:
parent
ee37427d38
commit
e38010e532
@ -1278,7 +1278,7 @@ func Routes() *web.Router {
|
||||
m.Delete("", reqRepoWriter(unit.TypeActions), repo.DeleteArtifact)
|
||||
})
|
||||
m.Get("/artifacts/{artifact_id}/zip", repo.DownloadArtifact)
|
||||
}, reqRepoReader(unit.TypeActions), context.ReferencesGitRepo(true))
|
||||
}, reqRepoReader(unit.TypeActions))
|
||||
m.Group("/keys", func() {
|
||||
m.Combo("").Get(repo.ListDeployKeys).
|
||||
Post(bind(api.CreateKeyOption{}), repo.CreateDeployKey)
|
||||
|
||||
@ -29,6 +29,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/actions"
|
||||
"code.gitea.io/gitea/modules/container"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/httplib"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
@ -222,13 +223,18 @@ func ToTag(repo *repo_model.Repository, t *git.Tag) *api.Tag {
|
||||
}
|
||||
}
|
||||
|
||||
// ToActionTask convert a actions_model.ActionTask to an api.ActionTask
|
||||
// ToActionTask convert an actions_model.ActionTask to an api.ActionTask
|
||||
func ToActionTask(ctx context.Context, t *actions_model.ActionTask) (*api.ActionTask, error) {
|
||||
if err := t.LoadAttributes(ctx); err != nil {
|
||||
// don't need Steps here, only need to load job and its run
|
||||
if err := t.LoadJob(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := t.Job.LoadRun(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := t.Job.Run.LoadRepo(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := strings.TrimSuffix(setting.AppURL, "/") + t.GetRunLink()
|
||||
|
||||
return &api.ActionTask{
|
||||
ID: t.ID,
|
||||
@ -240,7 +246,7 @@ func ToActionTask(ctx context.Context, t *actions_model.ActionTask) (*api.Action
|
||||
DisplayTitle: t.Job.Run.Title,
|
||||
Status: t.Status.String(),
|
||||
WorkflowID: t.Job.Run.WorkflowID,
|
||||
URL: url,
|
||||
URL: httplib.MakeAbsoluteURL(ctx, t.GetRunLink()),
|
||||
CreatedAt: t.Created.AsLocalTime(),
|
||||
UpdatedAt: t.Updated.AsLocalTime(),
|
||||
RunStartedAt: t.Started.AsLocalTime(),
|
||||
@ -248,7 +254,10 @@ func ToActionTask(ctx context.Context, t *actions_model.ActionTask) (*api.Action
|
||||
}
|
||||
|
||||
func ToActionWorkflowRun(ctx context.Context, repo *repo_model.Repository, run *actions_model.ActionRun, attempt *actions_model.ActionRunAttempt) (*api.ActionWorkflowRun, error) {
|
||||
if err := run.LoadAttributes(ctx); err != nil {
|
||||
if run.Repo == nil {
|
||||
run.Repo = repo
|
||||
}
|
||||
if err := run.LoadTriggerUser(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -272,6 +281,7 @@ func ToActionWorkflowRun(ctx context.Context, repo *repo_model.Repository, run *
|
||||
var previousAttemptURL *string
|
||||
|
||||
if attempt != nil {
|
||||
attempt.Run = run
|
||||
if err := attempt.LoadAttributes(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -281,16 +291,16 @@ func ToActionWorkflowRun(ctx context.Context, repo *repo_model.Repository, run *
|
||||
completedAt = attempt.Stopped.AsLocalTime()
|
||||
triggerUser = attempt.TriggerUser
|
||||
if attempt.Attempt > 1 {
|
||||
url := fmt.Sprintf("%s/actions/runs/%d/attempts/%d", repo.APIURL(), run.ID, attempt.Attempt-1)
|
||||
url := fmt.Sprintf("%s/actions/runs/%d/attempts/%d", repo.APIURL(ctx), run.ID, attempt.Attempt-1)
|
||||
previousAttemptURL = &url
|
||||
}
|
||||
}
|
||||
|
||||
return &api.ActionWorkflowRun{
|
||||
ID: run.ID,
|
||||
URL: fmt.Sprintf("%s/actions/runs/%d", repo.APIURL(), run.ID),
|
||||
URL: fmt.Sprintf("%s/actions/runs/%d", repo.APIURL(ctx), run.ID),
|
||||
PreviousAttemptURL: previousAttemptURL,
|
||||
HTMLURL: run.HTMLURL(),
|
||||
HTMLURL: run.HTMLURL(ctx),
|
||||
RunNumber: run.Index,
|
||||
RunAttempt: runAttempt,
|
||||
CreatedAt: run.Created.AsLocalTime(),
|
||||
@ -401,11 +411,11 @@ func ToActionWorkflowJob(ctx context.Context, repo *repo_model.Repository, task
|
||||
return &api.ActionWorkflowJob{
|
||||
ID: job.ID,
|
||||
// missing api endpoint for this location
|
||||
URL: fmt.Sprintf("%s/actions/jobs/%d", repo.APIURL(), job.ID),
|
||||
HTMLURL: fmt.Sprintf("%s/jobs/%d", job.Run.HTMLURL(), job.ID),
|
||||
URL: fmt.Sprintf("%s/actions/jobs/%d", repo.APIURL(ctx), job.ID),
|
||||
HTMLURL: fmt.Sprintf("%s/jobs/%d", job.Run.HTMLURL(ctx), job.ID),
|
||||
RunID: job.RunID,
|
||||
// Missing api endpoint for this location, artifacts are available under a nested url
|
||||
RunURL: fmt.Sprintf("%s/actions/runs/%d", repo.APIURL(), job.RunID),
|
||||
RunURL: fmt.Sprintf("%s/actions/runs/%d", repo.APIURL(ctx), job.RunID),
|
||||
Name: job.Name,
|
||||
Labels: job.RunsOn,
|
||||
RunAttempt: job.Attempt,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user