@@ -95,7 +95,7 @@ func GetEventsFromContent(content []byte) ([]*jobparser.Event, error) {
9595 return events , nil
9696}
9797
98- func DetectWorkflows (commit * git.Commit , triggedEvent webhook_module.HookEventType , payload api.Payloader ) ([]* DetectedWorkflow , error ) {
98+ func DetectWorkflows (gitRepo * git. Repository , commit * git.Commit , triggedEvent webhook_module.HookEventType , payload api.Payloader ) ([]* DetectedWorkflow , error ) {
9999 entries , err := ListWorkflows (commit )
100100 if err != nil {
101101 return nil , err
@@ -114,7 +114,7 @@ func DetectWorkflows(commit *git.Commit, triggedEvent webhook_module.HookEventTy
114114 }
115115 for _ , evt := range events {
116116 log .Trace ("detect workflow %q for event %#v matching %q" , entry .Name (), evt , triggedEvent )
117- if detectMatched (commit , triggedEvent , payload , evt ) {
117+ if detectMatched (gitRepo , commit , triggedEvent , payload , evt ) {
118118 dwf := & DetectedWorkflow {
119119 EntryName : entry .Name (),
120120 TriggerEvent : evt .Name ,
@@ -128,7 +128,7 @@ func DetectWorkflows(commit *git.Commit, triggedEvent webhook_module.HookEventTy
128128 return workflows , nil
129129}
130130
131- func detectMatched (commit * git.Commit , triggedEvent webhook_module.HookEventType , payload api.Payloader , evt * jobparser.Event ) bool {
131+ func detectMatched (gitRepo * git. Repository , commit * git.Commit , triggedEvent webhook_module.HookEventType , payload api.Payloader , evt * jobparser.Event ) bool {
132132 if ! canGithubEventMatch (evt .Name , triggedEvent ) {
133133 return false
134134 }
@@ -168,7 +168,7 @@ func detectMatched(commit *git.Commit, triggedEvent webhook_module.HookEventType
168168 webhook_module .HookEventPullRequestSync ,
169169 webhook_module .HookEventPullRequestAssign ,
170170 webhook_module .HookEventPullRequestLabel :
171- return matchPullRequestEvent (commit , payload .(* api.PullRequestPayload ), evt )
171+ return matchPullRequestEvent (gitRepo , commit , payload .(* api.PullRequestPayload ), evt )
172172
173173 case // pull_request_review
174174 webhook_module .HookEventPullRequestReviewApproved ,
@@ -331,7 +331,7 @@ func matchIssuesEvent(commit *git.Commit, issuePayload *api.IssuePayload, evt *j
331331 return matchTimes == len (evt .Acts ())
332332}
333333
334- func matchPullRequestEvent (commit * git.Commit , prPayload * api.PullRequestPayload , evt * jobparser.Event ) bool {
334+ func matchPullRequestEvent (gitRepo * git. Repository , commit * git.Commit , prPayload * api.PullRequestPayload , evt * jobparser.Event ) bool {
335335 acts := evt .Acts ()
336336 activityTypeMatched := false
337337 matchTimes := 0
@@ -370,6 +370,18 @@ func matchPullRequestEvent(commit *git.Commit, prPayload *api.PullRequestPayload
370370 }
371371 }
372372
373+ var (
374+ headCommit = commit
375+ err error
376+ )
377+ if evt .Name == GithubEventPullRequestTarget && (len (acts ["paths" ]) > 0 || len (acts ["paths-ignore" ]) > 0 ) {
378+ headCommit , err = gitRepo .GetCommit (prPayload .PullRequest .Head .Sha )
379+ if err != nil {
380+ log .Error ("GetCommit [ref: %s]: %v" , prPayload .PullRequest .Head .Sha , err )
381+ return false
382+ }
383+ }
384+
373385 // all acts conditions should be satisfied
374386 for cond , vals := range acts {
375387 switch cond {
@@ -392,9 +404,9 @@ func matchPullRequestEvent(commit *git.Commit, prPayload *api.PullRequestPayload
392404 matchTimes ++
393405 }
394406 case "paths" :
395- filesChanged , err := commit .GetFilesChangedSinceCommit (prPayload .PullRequest .Base .Ref )
407+ filesChanged , err := headCommit .GetFilesChangedSinceCommit (prPayload .PullRequest .Base .Ref )
396408 if err != nil {
397- log .Error ("GetFilesChangedSinceCommit [commit_sha1: %s]: %v" , commit .ID .String (), err )
409+ log .Error ("GetFilesChangedSinceCommit [commit_sha1: %s]: %v" , headCommit .ID .String (), err )
398410 } else {
399411 patterns , err := workflowpattern .CompilePatterns (vals ... )
400412 if err != nil {
@@ -405,9 +417,9 @@ func matchPullRequestEvent(commit *git.Commit, prPayload *api.PullRequestPayload
405417 }
406418 }
407419 case "paths-ignore" :
408- filesChanged , err := commit .GetFilesChangedSinceCommit (prPayload .PullRequest .Base .Ref )
420+ filesChanged , err := headCommit .GetFilesChangedSinceCommit (prPayload .PullRequest .Base .Ref )
409421 if err != nil {
410- log .Error ("GetFilesChangedSinceCommit [commit_sha1: %s]: %v" , commit .ID .String (), err )
422+ log .Error ("GetFilesChangedSinceCommit [commit_sha1: %s]: %v" , headCommit .ID .String (), err )
411423 } else {
412424 patterns , err := workflowpattern .CompilePatterns (vals ... )
413425 if err != nil {
0 commit comments