From 3f6ddd9beea6e9f2e5870f78cf35a3700a3fe5d5 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 9 Apr 2024 07:30:55 +0800 Subject: [PATCH] Fix create commit status (#30225) (#30340) Partially backport #30223 This PR uses the service layer `CreateCommitstatus` method instead of the git model method. --- services/actions/commit_status.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/services/actions/commit_status.go b/services/actions/commit_status.go index 08a7dde67c..14233068e8 100644 --- a/services/actions/commit_status.go +++ b/services/actions/commit_status.go @@ -12,9 +12,11 @@ import ( "code.gitea.io/gitea/models/db" git_model "code.gitea.io/gitea/models/git" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" api "code.gitea.io/gitea/modules/structs" webhook_module "code.gitea.io/gitea/modules/webhook" + commitstatus_service "code.gitea.io/gitea/services/repository/commitstatus" "github.com/nektos/act/pkg/jobparser" ) @@ -114,19 +116,20 @@ func createCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er } creator := user_model.NewActionsUser() - if err := git_model.NewCommitStatus(ctx, git_model.NewCommitStatusOptions{ - Repo: repo, - SHA: sha, - Creator: creator, - CommitStatus: &git_model.CommitStatus{ - SHA: sha, + commitID, err := git.NewIDFromString(sha) + if err != nil { + return fmt.Errorf("HashTypeInterfaceFromHashString: %w", err) + } + if err := commitstatus_service.CreateCommitStatus(ctx, repo, creator, + commitID.String(), + &git_model.CommitStatus{ + SHA: commitID.String(), TargetURL: fmt.Sprintf("%s/jobs/%d", run.Link(), index), Description: description, Context: ctxname, CreatorID: creator.ID, State: state, - }, - }); err != nil { + }); err != nil { return fmt.Errorf("NewCommitStatus: %w", err) }