@ -95,7 +95,7 @@ func GetEventsFromContent(content []byte) ([]*jobparser.Event, error) {
return events , nil
return events , nil
}
}
func DetectWorkflows ( commit * git . Commit , triggedEvent webhook_module . HookEventType , payload api . Payloader ) ( [ ] * DetectedWorkflow , error ) {
func DetectWorkflows ( gitRepo * git . Repository , commit * git . Commit , triggedEvent webhook_module . HookEventType , payload api . Payloader ) ( [ ] * DetectedWorkflow , error ) {
entries , err := ListWorkflows ( commit )
entries , err := ListWorkflows ( commit )
if err != nil {
if err != nil {
return nil , err
return nil , err
@ -114,7 +114,7 @@ func DetectWorkflows(commit *git.Commit, triggedEvent webhook_module.HookEventTy
}
}
for _ , evt := range events {
for _ , evt := range events {
log . Trace ( "detect workflow %q for event %#v matching %q" , entry . Name ( ) , evt , triggedEvent )
log . Trace ( "detect workflow %q for event %#v matching %q" , entry . Name ( ) , evt , triggedEvent )
if detectMatched ( commit, triggedEvent , payload , evt ) {
if detectMatched ( gitRepo, commit, triggedEvent , payload , evt ) {
dwf := & DetectedWorkflow {
dwf := & DetectedWorkflow {
EntryName : entry . Name ( ) ,
EntryName : entry . Name ( ) ,
TriggerEvent : evt . Name ,
TriggerEvent : evt . Name ,
@ -128,7 +128,7 @@ func DetectWorkflows(commit *git.Commit, triggedEvent webhook_module.HookEventTy
return workflows , nil
return workflows , nil
}
}
func detectMatched ( commit * git . Commit , triggedEvent webhook_module . HookEventType , payload api . Payloader , evt * jobparser . Event ) bool {
func detectMatched ( gitRepo * git . Repository , commit * git . Commit , triggedEvent webhook_module . HookEventType , payload api . Payloader , evt * jobparser . Event ) bool {
if ! canGithubEventMatch ( evt . Name , triggedEvent ) {
if ! canGithubEventMatch ( evt . Name , triggedEvent ) {
return false
return false
}
}
@ -168,7 +168,7 @@ func detectMatched(commit *git.Commit, triggedEvent webhook_module.HookEventType
webhook_module . HookEventPullRequestSync ,
webhook_module . HookEventPullRequestSync ,
webhook_module . HookEventPullRequestAssign ,
webhook_module . HookEventPullRequestAssign ,
webhook_module . HookEventPullRequestLabel :
webhook_module . HookEventPullRequestLabel :
return matchPullRequestEvent ( commit, payload . ( * api . PullRequestPayload ) , evt )
return matchPullRequestEvent ( gitRepo, commit, payload . ( * api . PullRequestPayload ) , evt )
case // pull_request_review
case // pull_request_review
webhook_module . HookEventPullRequestReviewApproved ,
webhook_module . HookEventPullRequestReviewApproved ,
@ -331,7 +331,7 @@ func matchIssuesEvent(commit *git.Commit, issuePayload *api.IssuePayload, evt *j
return matchTimes == len ( evt . Acts ( ) )
return matchTimes == len ( evt . Acts ( ) )
}
}
func matchPullRequestEvent ( commit * git . Commit , prPayload * api . PullRequestPayload , evt * jobparser . Event ) bool {
func matchPullRequestEvent ( gitRepo * git . Repository , commit * git . Commit , prPayload * api . PullRequestPayload , evt * jobparser . Event ) bool {
acts := evt . Acts ( )
acts := evt . Acts ( )
activityTypeMatched := false
activityTypeMatched := false
matchTimes := 0
matchTimes := 0
@ -370,6 +370,18 @@ func matchPullRequestEvent(commit *git.Commit, prPayload *api.PullRequestPayload
}
}
}
}
var (
headCommit = commit
err error
)
if evt . Name == GithubEventPullRequestTarget && ( len ( acts [ "paths" ] ) > 0 || len ( acts [ "paths-ignore" ] ) > 0 ) {
headCommit , err = gitRepo . GetCommit ( prPayload . PullRequest . Head . Sha )
if err != nil {
log . Error ( "GetCommit [ref: %s]: %v" , prPayload . PullRequest . Head . Sha , err )
return false
}
}
// all acts conditions should be satisfied
// all acts conditions should be satisfied
for cond , vals := range acts {
for cond , vals := range acts {
switch cond {
switch cond {
@ -392,9 +404,9 @@ func matchPullRequestEvent(commit *git.Commit, prPayload *api.PullRequestPayload
matchTimes ++
matchTimes ++
}
}
case "paths" :
case "paths" :
filesChanged , err := c ommit. GetFilesChangedSinceCommit ( prPayload . PullRequest . Base . Ref )
filesChanged , err := headC ommit. GetFilesChangedSinceCommit ( prPayload . PullRequest . Base . Ref )
if err != nil {
if err != nil {
log . Error ( "GetFilesChangedSinceCommit [commit_sha1: %s]: %v" , c ommit. ID . String ( ) , err )
log . Error ( "GetFilesChangedSinceCommit [commit_sha1: %s]: %v" , headC ommit. ID . String ( ) , err )
} else {
} else {
patterns , err := workflowpattern . CompilePatterns ( vals ... )
patterns , err := workflowpattern . CompilePatterns ( vals ... )
if err != nil {
if err != nil {
@ -405,9 +417,9 @@ func matchPullRequestEvent(commit *git.Commit, prPayload *api.PullRequestPayload
}
}
}
}
case "paths-ignore" :
case "paths-ignore" :
filesChanged , err := c ommit. GetFilesChangedSinceCommit ( prPayload . PullRequest . Base . Ref )
filesChanged , err := headC ommit. GetFilesChangedSinceCommit ( prPayload . PullRequest . Base . Ref )
if err != nil {
if err != nil {
log . Error ( "GetFilesChangedSinceCommit [commit_sha1: %s]: %v" , c ommit. ID . String ( ) , err )
log . Error ( "GetFilesChangedSinceCommit [commit_sha1: %s]: %v" , headC ommit. ID . String ( ) , err )
} else {
} else {
patterns , err := workflowpattern . CompilePatterns ( vals ... )
patterns , err := workflowpattern . CompilePatterns ( vals ... )
if err != nil {
if err != nil {