mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-11-04 06:24:11 +01:00 
			
		
		
		
	wip test and fixes
This commit is contained in:
		
							parent
							
								
									ca6bbc6c6d
								
							
						
					
					
						commit
						875c7745e4
					
				@ -962,7 +962,7 @@ func GetWorkflowRuns(ctx *context.APIContext) {
 | 
			
		||||
 | 
			
		||||
	res.Entries = make([]*api.ActionWorkflowRun, len(runs))
 | 
			
		||||
	for i := range runs {
 | 
			
		||||
		convertedRun, err := convert.ToActionWorkflowRun(ctx.Repo.Repository, runs[i])
 | 
			
		||||
		convertedRun, err := convert.ToActionWorkflowRun(ctx, ctx.Repo.Repository, runs[i])
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			ctx.APIErrorInternal(err)
 | 
			
		||||
			return
 | 
			
		||||
@ -1011,7 +1011,7 @@ func GetWorkflowRun(ctx *context.APIContext) {
 | 
			
		||||
		ctx.APIError(http.StatusNotFound, util.ErrNotExist)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	convertedArtifact, err := convert.ToActionWorkflowRun(ctx.Repo.Repository, job)
 | 
			
		||||
	convertedArtifact, err := convert.ToActionWorkflowRun(ctx, ctx.Repo.Repository, job)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.APIErrorInternal(err)
 | 
			
		||||
		return
 | 
			
		||||
 | 
			
		||||
@ -786,7 +786,7 @@ func (n *actionsNotifier) WorkflowRunStatusUpdate(ctx context.Context, repo *rep
 | 
			
		||||
 | 
			
		||||
	convertedWorkflow, err := convert.GetActionWorkflow(ctx, gitRepo, repo, run.WorkflowID)
 | 
			
		||||
 | 
			
		||||
	convertedRun, err := convert.ToActionWorkflowRun(repo, run)
 | 
			
		||||
	convertedRun, err := convert.ToActionWorkflowRun(ctx, repo, run)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Error("ToActionWorkflowRun: %v", err)
 | 
			
		||||
		return
 | 
			
		||||
 | 
			
		||||
@ -234,7 +234,8 @@ func ToActionTask(ctx context.Context, t *actions_model.ActionTask) (*api.Action
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func ToActionWorkflowRun(repo *repo_model.Repository, run *actions_model.ActionRun) (*api.ActionWorkflowRun, error) {
 | 
			
		||||
func ToActionWorkflowRun(ctx context.Context, repo *repo_model.Repository, run *actions_model.ActionRun) (*api.ActionWorkflowRun, error) {
 | 
			
		||||
	run.LoadRepo(ctx)
 | 
			
		||||
	status, conclusion := ToActionsStatus(run.Status)
 | 
			
		||||
	return &api.ActionWorkflowRun{
 | 
			
		||||
		ID:           run.ID,
 | 
			
		||||
@ -243,13 +244,13 @@ func ToActionWorkflowRun(repo *repo_model.Repository, run *actions_model.ActionR
 | 
			
		||||
		RunNumber:    run.Index,
 | 
			
		||||
		StartedAt:    run.Started.AsLocalTime(),
 | 
			
		||||
		CompletedAt:  run.Stopped.AsLocalTime(),
 | 
			
		||||
		Event:        run.TriggerEvent,
 | 
			
		||||
		Event:        string(run.Event),
 | 
			
		||||
		DisplayTitle: run.Title,
 | 
			
		||||
		HeadBranch:   git.RefName(run.Ref).BranchName(),
 | 
			
		||||
		HeadSha:      run.CommitSHA,
 | 
			
		||||
		Status:       status,
 | 
			
		||||
		Conclusion:   conclusion,
 | 
			
		||||
		Path:         fmt.Sprint("%s@%s", run.WorkflowID, run.Ref),
 | 
			
		||||
		Path:         fmt.Sprintf("%s@%s", run.WorkflowID, run.Ref),
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -996,7 +996,7 @@ func (*webhookNotifier) WorkflowRunStatusUpdate(ctx context.Context, repo *repo_
 | 
			
		||||
 | 
			
		||||
	convertedWorkflow, err := convert.GetActionWorkflow(ctx, gitRepo, repo, run.WorkflowID)
 | 
			
		||||
 | 
			
		||||
	convertedRun, err := convert.ToActionWorkflowRun(repo, run)
 | 
			
		||||
	convertedRun, err := convert.ToActionWorkflowRun(ctx, repo, run)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Error("ToActionWorkflowRun: %v", err)
 | 
			
		||||
		return
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										72
									
								
								tests/integration/workflow_run_api_check_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								tests/integration/workflow_run_api_check_test.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,72 @@
 | 
			
		||||
// Copyright 2025 The Gitea Authors. All rights reserved.
 | 
			
		||||
// SPDX-License-Identifier: MIT
 | 
			
		||||
 | 
			
		||||
package integration
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	auth_model "code.gitea.io/gitea/models/auth"
 | 
			
		||||
	api "code.gitea.io/gitea/modules/structs"
 | 
			
		||||
	"code.gitea.io/gitea/tests"
 | 
			
		||||
 | 
			
		||||
	"github.com/stretchr/testify/assert"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestAPIWorkflowRunRepoApi(t *testing.T) {
 | 
			
		||||
	defer tests.PrepareTestEnv(t)()
 | 
			
		||||
	userUsername := "user5"
 | 
			
		||||
	token := getUserToken(t, userUsername, auth_model.AccessTokenScopeWriteRepository)
 | 
			
		||||
 | 
			
		||||
	req := NewRequest(t, "GET", "/api/v1/repos/user5/repo4/actions/runs").AddTokenAuth(token)
 | 
			
		||||
	runnerListResp := MakeRequest(t, req, http.StatusOK)
 | 
			
		||||
	runnerList := api.ActionWorkflowRunsResponse{}
 | 
			
		||||
	DecodeJSON(t, runnerListResp, &runnerList)
 | 
			
		||||
 | 
			
		||||
	assert.Len(t, runnerList.Entries, 4)
 | 
			
		||||
 | 
			
		||||
	for _, run := range runnerList.Entries {
 | 
			
		||||
		req := NewRequest(t, "GET", fmt.Sprintf("%s/%s", run.URL, "jobs")).AddTokenAuth(token)
 | 
			
		||||
		jobsResp := MakeRequest(t, req, http.StatusOK)
 | 
			
		||||
		jobList := api.ActionWorkflowJobsResponse{}
 | 
			
		||||
		DecodeJSON(t, jobsResp, &jobList)
 | 
			
		||||
 | 
			
		||||
		// assert.NotEmpty(t, jobList.Entries)
 | 
			
		||||
		for _, job := range jobList.Entries {
 | 
			
		||||
			req := NewRequest(t, "GET", job.URL).AddTokenAuth(token)
 | 
			
		||||
			jobsResp := MakeRequest(t, req, http.StatusOK)
 | 
			
		||||
			apiJob := api.ActionWorkflowJob{}
 | 
			
		||||
			DecodeJSON(t, jobsResp, &apiJob)
 | 
			
		||||
			assert.Equal(t, job.ID, apiJob.ID)
 | 
			
		||||
			assert.Equal(t, job.RunID, apiJob.RunID)
 | 
			
		||||
			assert.Equal(t, job.Status, apiJob.Status)
 | 
			
		||||
			assert.Equal(t, job.Conclusion, apiJob.Conclusion)
 | 
			
		||||
		}
 | 
			
		||||
		// assert.NotEmpty(t, run.ID)
 | 
			
		||||
		// assert.NotEmpty(t, run.Status)
 | 
			
		||||
		// assert.NotEmpty(t, run.Event)
 | 
			
		||||
		// assert.NotEmpty(t, run.WorkflowID)
 | 
			
		||||
		// assert.NotEmpty(t, run.HeadBranch)
 | 
			
		||||
		// assert.NotEmpty(t, run.HeadSHA)
 | 
			
		||||
		// assert.NotEmpty(t, run.CreatedAt)
 | 
			
		||||
		// assert.NotEmpty(t, run.UpdatedAt)
 | 
			
		||||
		// assert.NotEmpty(t, run.URL)
 | 
			
		||||
		// assert.NotEmpty(t, run.HTMLURL)
 | 
			
		||||
		// assert.NotEmpty(t, run.PullRequests)
 | 
			
		||||
		// assert.NotEmpty(t, run.WorkflowURL)
 | 
			
		||||
		// assert.NotEmpty(t, run.HeadCommit)
 | 
			
		||||
		// assert.NotEmpty(t, run.HeadRepository)
 | 
			
		||||
		// assert.NotEmpty(t, run.Repository)
 | 
			
		||||
		// assert.NotEmpty(t, run.HeadRepository)
 | 
			
		||||
		// assert.NotEmpty(t, run.HeadRepository.Owner)
 | 
			
		||||
		// assert.NotEmpty(t, run.HeadRepository.Name)
 | 
			
		||||
		// assert.NotEmpty(t, run.Repository.Owner)
 | 
			
		||||
		// assert.NotEmpty(t, run.Repository.Name)
 | 
			
		||||
		// assert.NotEmpty(t, run.HeadRepository.Owner.Login)
 | 
			
		||||
		// assert.NotEmpty(t, run.HeadRepository.Name)
 | 
			
		||||
		// assert.NotEmpty(t, run.Repository.Owner.Login)
 | 
			
		||||
		// assert.NotEmpty(t, run.Repository.Name)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user