Skip to content

Commit aaf1c93

Browse files
committed
Fix actions trigger
1 parent 6e801ae commit aaf1c93

File tree

5 files changed

+9
-13
lines changed

5 files changed

+9
-13
lines changed

modules/structs/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ func (p *WorkflowDispatchPayload) JSONPayload() ([]byte, error) {
505505

506506
// CommitStatusPayload represents a payload information of commit status event.
507507
type CommitStatusPayload struct {
508-
// TODO: add Branches
508+
// TODO: add Branches per https://docs.github.com/en/webhooks/webhook-events-and-payloads#status
509509
Commit *PayloadCommit `json:"commit"`
510510
Context string `json:"context"`
511511
// swagger:strfmt date-time

modules/webhook/type.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const (
3232
HookEventRelease HookEventType = "release"
3333
HookEventPackage HookEventType = "package"
3434
HookEventSchedule HookEventType = "schedule"
35+
HookEventStatus HookEventType = "status"
3536
)
3637

3738
// Event returns the HookEventType as an event string

services/actions/commit_status.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,16 @@ func createCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er
128128
if err != nil {
129129
return fmt.Errorf("HashTypeInterfaceFromHashString: %w", err)
130130
}
131-
if err := commitstatus_service.CreateCommitStatus(ctx, repo, creator, commitID.String(), &git_model.CommitStatus{
131+
status := git_model.CommitStatus{
132132
SHA: sha,
133133
TargetURL: fmt.Sprintf("%s/jobs/%d", run.Link(), index),
134134
Description: description,
135135
Context: ctxname,
136136
CreatorID: creator.ID,
137137
State: state,
138-
}); err != nil {
139-
return fmt.Errorf("NewCommitStatus: %w", err)
140138
}
141139

142-
return nil
140+
return commitstatus_service.CreateCommitStatus(ctx, repo, creator, commitID.String(), &status)
143141
}
144142

145143
func toCommitStatus(status actions_model.Status) api.CommitStatusState {

services/repository/commitstatus/commitstatus.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
repo_model "code.gitea.io/gitea/models/repo"
1515
user_model "code.gitea.io/gitea/models/user"
1616
"code.gitea.io/gitea/modules/cache"
17-
"code.gitea.io/gitea/modules/git"
1817
"code.gitea.io/gitea/modules/gitrepo"
1918
"code.gitea.io/gitea/modules/json"
2019
"code.gitea.io/gitea/modules/log"
@@ -79,16 +78,10 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato
7978
}
8079
defer closer.Close()
8180

82-
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
83-
8481
commit, err := gitRepo.GetCommit(sha)
8582
if err != nil {
8683
return fmt.Errorf("GetCommit[%s]: %w", sha, err)
8784
}
88-
if len(sha) != objectFormat.FullLength() {
89-
// use complete commit sha
90-
sha = commit.ID.String()
91-
}
9285

9386
if err := db.WithTx(ctx, func(ctx context.Context) error {
9487
if err := git_model.NewCommitStatus(ctx, git_model.NewCommitStatusOptions{
@@ -105,6 +98,10 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato
10598
return err
10699
}
107100

101+
pushCommit := repo_module.CommitToPushCommit(commit)
102+
103+
notify.CreateCommitStatus(ctx, repo, pushCommit, creator, status)
104+
108105
defaultBranchCommit, err := gitRepo.GetBranchCommit(repo.DefaultBranch)
109106
if err != nil {
110107
return fmt.Errorf("GetBranchCommit[%s]: %w", repo.DefaultBranch, err)

services/webhook/notifier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ func (m *webhookNotifier) CreateCommitStatus(ctx context.Context, repo *repo_mod
887887
t := status.UpdatedUnix.AsTime().UTC()
888888
payload.UpdatedAt = &t
889889
}
890-
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventPush, &payload); err != nil {
890+
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventStatus, &payload); err != nil {
891891
log.Error("PrepareWebhooks: %v", err)
892892
}
893893
}

0 commit comments

Comments
 (0)