mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-03 06:08:42 +00:00
parent
5214813a23
commit
af2c278723
2 changed files with 14 additions and 2 deletions
|
@ -482,6 +482,11 @@ func (c *Gitea) Hook(ctx context.Context, r *http.Request) (*model.Repo, *model.
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if repo == nil || pipeline == nil {
|
||||||
|
// ignore hook
|
||||||
|
return nil, nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
if pipeline.Event == model.EventPull && len(pipeline.ChangedFiles) == 0 {
|
if pipeline.Event == model.EventPull && len(pipeline.ChangedFiles) == 0 {
|
||||||
index, err := strconv.ParseInt(strings.Split(pipeline.Ref, "/")[2], 10, 64)
|
index, err := strconv.ParseInt(strings.Split(pipeline.Ref, "/")[2], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -20,6 +20,8 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -41,7 +43,8 @@ const (
|
||||||
// parseHook parses a Gitea hook from an http.Request request and returns
|
// 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.
|
// Repo and Pipeline detail. If a hook type is unsupported nil values are returned.
|
||||||
func parseHook(r *http.Request) (*model.Repo, *model.Pipeline, error) {
|
func parseHook(r *http.Request) (*model.Repo, *model.Pipeline, error) {
|
||||||
switch r.Header.Get(hookEvent) {
|
hookType := r.Header.Get(hookEvent)
|
||||||
|
switch hookType {
|
||||||
case hookPush:
|
case hookPush:
|
||||||
return parsePushHook(r.Body)
|
return parsePushHook(r.Body)
|
||||||
case hookCreated:
|
case hookCreated:
|
||||||
|
@ -49,6 +52,7 @@ func parseHook(r *http.Request) (*model.Repo, *model.Pipeline, error) {
|
||||||
case hookPullRequest:
|
case hookPullRequest:
|
||||||
return parsePullRequestHook(r.Body)
|
return parsePullRequestHook(r.Body)
|
||||||
}
|
}
|
||||||
|
log.Debug().Msgf("unsuported hook type: '%s'", hookType)
|
||||||
return nil, nil, nil
|
return nil, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,11 +108,14 @@ func parsePullRequestHook(payload io.Reader) (*model.Repo, *model.Pipeline, erro
|
||||||
return nil, nil, err
|
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 {
|
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
|
return nil, nil, nil
|
||||||
}
|
}
|
||||||
|
// ... or if PR is not open
|
||||||
if pr.PullRequest.State != stateOpen {
|
if pr.PullRequest.State != stateOpen {
|
||||||
|
log.Debug().Msg("pull_request is closed")
|
||||||
return nil, nil, nil
|
return nil, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue