Skip to content

Commit 73a256c

Browse files
committed
Fix actions trigger
1 parent a69004c commit 73a256c

File tree

5 files changed

+18
-24
lines changed

5 files changed

+18
-24
lines changed

modules/structs/hook.go

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

491491
// CommitStatusPayload represents a payload information of commit status event.
492492
type CommitStatusPayload struct {
493-
// TODO: add Branches
493+
// TODO: add Branches per https://docs.github.com/en/webhooks/webhook-events-and-payloads#status
494494
Commit *PayloadCommit `json:"commit"`
495495
Context string `json:"context"`
496496
// 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: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"code.gitea.io/gitea/modules/log"
1717
api "code.gitea.io/gitea/modules/structs"
1818
webhook_module "code.gitea.io/gitea/modules/webhook"
19+
commitstatus_service "code.gitea.io/gitea/services/repository/commitstatus"
1920

2021
"github.com/nektos/act/pkg/jobparser"
2122
)
@@ -122,23 +123,16 @@ func createCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er
122123
if err != nil {
123124
return fmt.Errorf("HashTypeInterfaceFromHashString: %w", err)
124125
}
125-
if err := git_model.NewCommitStatus(ctx, git_model.NewCommitStatusOptions{
126-
Repo: repo,
127-
SHA: commitID,
128-
Creator: creator,
129-
CommitStatus: &git_model.CommitStatus{
130-
SHA: sha,
131-
TargetURL: fmt.Sprintf("%s/jobs/%d", run.Link(), index),
132-
Description: description,
133-
Context: ctxname,
134-
CreatorID: creator.ID,
135-
State: state,
136-
},
137-
}); err != nil {
138-
return fmt.Errorf("NewCommitStatus: %w", err)
126+
status := git_model.CommitStatus{
127+
SHA: sha,
128+
TargetURL: fmt.Sprintf("%s/jobs/%d", run.Link(), index),
129+
Description: description,
130+
Context: ctxname,
131+
CreatorID: creator.ID,
132+
State: state,
139133
}
140134

141-
return nil
135+
return commitstatus_service.CreateCommitStatus(ctx, repo, creator, commitID.String(), &status)
142136
}
143137

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

services/repository/commitstatus/commitstatus.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import (
1313
repo_model "code.gitea.io/gitea/models/repo"
1414
user_model "code.gitea.io/gitea/models/user"
1515
"code.gitea.io/gitea/modules/cache"
16-
"code.gitea.io/gitea/modules/git"
1716
"code.gitea.io/gitea/modules/gitrepo"
1817
"code.gitea.io/gitea/modules/log"
18+
"code.gitea.io/gitea/modules/repository"
1919
api "code.gitea.io/gitea/modules/structs"
2020
"code.gitea.io/gitea/services/automerge"
21+
"code.gitea.io/gitea/services/notify"
2122
)
2223

2324
func getCacheKey(repoID int64, brancheName string) string {
@@ -48,16 +49,10 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato
4849
}
4950
defer closer.Close()
5051

51-
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
52-
5352
commit, err := gitRepo.GetCommit(sha)
5453
if err != nil {
5554
return fmt.Errorf("GetCommit[%s]: %w", sha, err)
5655
}
57-
if len(sha) != objectFormat.FullLength() {
58-
// use complete commit sha
59-
sha = commit.ID.String()
60-
}
6156

6257
if err := git_model.NewCommitStatus(ctx, git_model.NewCommitStatusOptions{
6358
Repo: repo,
@@ -68,6 +63,10 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato
6863
return fmt.Errorf("NewCommitStatus[repo_id: %d, user_id: %d, sha: %s]: %w", repo.ID, creator.ID, sha, err)
6964
}
7065

66+
pushCommit := repository.CommitToPushCommit(commit)
67+
68+
notify.CreateCommitStatus(ctx, repo, pushCommit, creator, status)
69+
7170
defaultBranchCommit, err := gitRepo.GetBranchCommit(repo.DefaultBranch)
7271
if err != nil {
7372
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
@@ -877,7 +877,7 @@ func (m *webhookNotifier) CreateCommitStatus(ctx context.Context, repo *repo_mod
877877
t := status.UpdatedUnix.AsTime().UTC()
878878
payload.UpdatedAt = &t
879879
}
880-
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventPush, &payload); err != nil {
880+
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventStatus, &payload); err != nil {
881881
log.Error("PrepareWebhooks: %v", err)
882882
}
883883
}

0 commit comments

Comments
 (0)