@@ -21,35 +21,60 @@ func CreateCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er
2121 }
2222
2323 run := job .Run
24- if run .Event != webhook_module .HookEventPush {
25- return nil
26- }
24+ var (
25+ sha string
26+ creatorID int64
27+ )
2728
28- payload , err := run .GetPushEventPayload ()
29- if err != nil {
30- return fmt .Errorf ("GetPushEventPayload: %w" , err )
31- }
29+ switch run .Event {
30+ case webhook_module .HookEventPush :
31+ payload , err := run .GetPushEventPayload ()
32+ if err != nil {
33+ return fmt .Errorf ("GetPushEventPayload: %w" , err )
34+ }
3235
33- // Since the payload comes from json data, we should check if it's broken, or it will cause panic
34- switch {
35- case payload .Repo == nil :
36- return fmt .Errorf ("repo is missing in event payload" )
37- case payload .Pusher == nil :
38- return fmt .Errorf ("pusher is missing in event payload" )
39- case payload .HeadCommit == nil :
40- return fmt .Errorf ("head commit is missing in event payload" )
41- }
36+ // Since the payload comes from json data, we should check if it's broken, or it will cause panic
37+ switch {
38+ case payload .Repo == nil :
39+ return fmt .Errorf ("repo is missing in event payload" )
40+ case payload .Pusher == nil :
41+ return fmt .Errorf ("pusher is missing in event payload" )
42+ case payload .HeadCommit == nil :
43+ return fmt .Errorf ("head commit is missing in event payload" )
44+ }
4245
43- creator , err := user_model .GetUserByID (ctx , payload .Pusher .ID )
44- if err != nil {
45- return fmt .Errorf ("GetUserByID: %w" , err )
46+ sha = payload .HeadCommit .ID
47+ creatorID = payload .Pusher .ID
48+ case webhook_module .HookEventPullRequest :
49+ payload , err := run .GetPullRequestEventPayload ()
50+ if err != nil {
51+ return fmt .Errorf ("GetPullRequestEventPayload: %w" , err )
52+ }
53+
54+ switch {
55+ case payload .PullRequest == nil :
56+ return fmt .Errorf ("pull request is missing in event payload" )
57+ case payload .PullRequest .Head == nil :
58+ return fmt .Errorf ("head of pull request is missing in event payload" )
59+ case payload .PullRequest .Head .Repository == nil :
60+ return fmt .Errorf ("head repository of pull request is missing in event payload" )
61+ case payload .PullRequest .Head .Repository .Owner == nil :
62+ return fmt .Errorf ("owner of head repository of pull request is missing in evnt payload" )
63+ }
64+
65+ sha = payload .PullRequest .Head .Sha
66+ creatorID = payload .PullRequest .Head .Repository .Owner .ID
67+ default :
68+ return nil
4669 }
4770
4871 repo := run .Repo
49- sha := payload .HeadCommit .ID
5072 ctxname := job .Name
5173 state := toCommitStatus (job .Status )
52-
74+ creator , err := user_model .GetUserByID (ctx , creatorID )
75+ if err != nil {
76+ return fmt .Errorf ("GetUserByID: %w" , err )
77+ }
5378 if statuses , _ , err := git_model .GetLatestCommitStatus (ctx , repo .ID , sha , db.ListOptions {}); err == nil {
5479 for _ , v := range statuses {
5580 if v .Context == ctxname {
@@ -65,14 +90,14 @@ func CreateCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er
6590
6691 if err := git_model .NewCommitStatus (ctx , git_model.NewCommitStatusOptions {
6792 Repo : repo ,
68- SHA : payload . HeadCommit . ID ,
93+ SHA : sha ,
6994 Creator : creator ,
7095 CommitStatus : & git_model.CommitStatus {
7196 SHA : sha ,
7297 TargetURL : run .Link (),
7398 Description : "" ,
7499 Context : ctxname ,
75- CreatorID : payload . Pusher . ID ,
100+ CreatorID : creatorID ,
76101 State : state ,
77102 },
78103 }); err != nil {
0 commit comments