mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-30 08:06:52 +02:00
parent
5214813a23
commit
af2c278723
@ -482,6 +482,11 @@ func (c *Gitea) Hook(ctx context.Context, r *http.Request) (*model.Repo, *model.
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if repo == nil || pipeline == nil {
|
||||
// ignore hook
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
if pipeline.Event == model.EventPull && len(pipeline.ChangedFiles) == 0 {
|
||||
index, err := strconv.ParseInt(strings.Split(pipeline.Ref, "/")[2], 10, 64)
|
||||
if err != nil {
|
||||
|
@ -20,6 +20,8 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||
)
|
||||
|
||||
@ -41,7 +43,8 @@ const (
|
||||
// parseHook parses a Gitea hook from an http.Request request and returns
|
||||
// Repo and Pipeline detail. If a hook type is unsupported nil values are returned.
|
||||
func parseHook(r *http.Request) (*model.Repo, *model.Pipeline, error) {
|
||||
switch r.Header.Get(hookEvent) {
|
||||
hookType := r.Header.Get(hookEvent)
|
||||
switch hookType {
|
||||
case hookPush:
|
||||
return parsePushHook(r.Body)
|
||||
case hookCreated:
|
||||
@ -49,6 +52,7 @@ func parseHook(r *http.Request) (*model.Repo, *model.Pipeline, error) {
|
||||
case hookPullRequest:
|
||||
return parsePullRequestHook(r.Body)
|
||||
}
|
||||
log.Debug().Msgf("unsuported hook type: '%s'", hookType)
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
@ -104,11 +108,14 @@ func parsePullRequestHook(payload io.Reader) (*model.Repo, *model.Pipeline, erro
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Don't trigger pipelines for non-code changes, or if PR is not open
|
||||
// Don't trigger pipelines for non-code changes ...
|
||||
if pr.Action != actionOpen && pr.Action != actionSync {
|
||||
log.Debug().Msgf("pull_request action is '%s' and no open or sync", pr.Action)
|
||||
return nil, nil, nil
|
||||
}
|
||||
// ... or if PR is not open
|
||||
if pr.PullRequest.State != stateOpen {
|
||||
log.Debug().Msg("pull_request is closed")
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user