mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-30 12:20:33 +00:00
Add "path" support to gitea on push hooks (#235)
This commit is contained in:
parent
70958acc44
commit
ee3e4bb189
5 changed files with 78 additions and 17 deletions
|
@ -386,7 +386,7 @@ when:
|
||||||
|
|
||||||
Execute a step only on commit with certain files added/removed/modified:
|
Execute a step only on commit with certain files added/removed/modified:
|
||||||
|
|
||||||
**NOTE: Feature is only available for Github repositories.**
|
**NOTE: Feature is only available for Github and Gitea repositories.**
|
||||||
|
|
||||||
```diff
|
```diff
|
||||||
when:
|
when:
|
||||||
|
@ -396,7 +396,7 @@ when:
|
||||||
Execute a step only on commit excluding certain files added/removed/modified:
|
Execute a step only on commit excluding certain files added/removed/modified:
|
||||||
|
|
||||||
|
|
||||||
**NOTE: Feature is only available for Github repositories.**
|
**NOTE: Feature is only available for Github and Gitea repositories.**
|
||||||
|
|
||||||
```diff
|
```diff
|
||||||
when:
|
when:
|
||||||
|
|
|
@ -30,7 +30,10 @@ const HookPush = `
|
||||||
"name": "Gordon the Gopher",
|
"name": "Gordon the Gopher",
|
||||||
"email": "gordon@golang.org",
|
"email": "gordon@golang.org",
|
||||||
"username": "gordon"
|
"username": "gordon"
|
||||||
}
|
},
|
||||||
|
"added": ["CHANGELOG.md"],
|
||||||
|
"removed": [],
|
||||||
|
"modified": ["app/controller/application.rb"]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -99,9 +99,24 @@ func buildFromPush(hook *pushHook) *model.Build {
|
||||||
Email: hook.Sender.Email,
|
Email: hook.Sender.Email,
|
||||||
Timestamp: time.Now().UTC().Unix(),
|
Timestamp: time.Now().UTC().Unix(),
|
||||||
Sender: sender,
|
Sender: sender,
|
||||||
|
ChangedFiles: getChangedFilesFromPushHook(hook),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getChangedFilesFromPushHook(hook *pushHook) []string {
|
||||||
|
files := make([]string, 0)
|
||||||
|
|
||||||
|
if len(hook.Commits) == 0 {
|
||||||
|
return files
|
||||||
|
}
|
||||||
|
|
||||||
|
files = append(files, hook.Commits[0].Added...)
|
||||||
|
files = append(files, hook.Commits[0].Removed...)
|
||||||
|
files = append(files, hook.Commits[0].Modified...)
|
||||||
|
|
||||||
|
return files
|
||||||
|
}
|
||||||
|
|
||||||
// helper function that extracts the Build data from a Gitea tag hook
|
// helper function that extracts the Build data from a Gitea tag hook
|
||||||
func buildFromTag(hook *pushHook) *model.Build {
|
func buildFromTag(hook *pushHook) *model.Build {
|
||||||
avatar := expandAvatar(
|
avatar := expandAvatar(
|
||||||
|
|
|
@ -13,3 +13,43 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package gitea
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/franela/goblin"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/model"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/remote/gitea/fixtures"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_parser(t *testing.T) {
|
||||||
|
g := goblin.Goblin(t)
|
||||||
|
g.Describe("Gitea parser", func() {
|
||||||
|
g.It("should ignore unsupported hook events", func() {
|
||||||
|
buf := bytes.NewBufferString(fixtures.HookPullRequest)
|
||||||
|
req, _ := http.NewRequest("POST", "/hook", buf)
|
||||||
|
req.Header = http.Header{}
|
||||||
|
req.Header.Set(hookEvent, "issues")
|
||||||
|
r, b, err := parseHook(req)
|
||||||
|
g.Assert(r == nil).IsTrue()
|
||||||
|
g.Assert(b == nil).IsTrue()
|
||||||
|
g.Assert(err == nil).IsTrue()
|
||||||
|
})
|
||||||
|
g.Describe("given a push hook", func() {
|
||||||
|
g.It("should extract repository and build details", func() {
|
||||||
|
buf := bytes.NewBufferString(fixtures.HookPush)
|
||||||
|
req, _ := http.NewRequest("POST", "/hook", buf)
|
||||||
|
req.Header = http.Header{}
|
||||||
|
req.Header.Set(hookEvent, hookPush)
|
||||||
|
r, b, err := parseHook(req)
|
||||||
|
g.Assert(err == nil).IsTrue()
|
||||||
|
g.Assert(r != nil).IsTrue()
|
||||||
|
g.Assert(b != nil).IsTrue()
|
||||||
|
g.Assert(b.Event).Equal(model.EventPush)
|
||||||
|
g.Assert(b.ChangedFiles).Equal([]string{"CHANGELOG.md", "app/controller/application.rb"})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -46,6 +46,9 @@ type pushHook struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
|
Added []string `json:"added"`
|
||||||
|
Removed []string `json:"removed"`
|
||||||
|
Modified []string `json:"modified"`
|
||||||
} `json:"commits"`
|
} `json:"commits"`
|
||||||
|
|
||||||
Sender struct {
|
Sender struct {
|
||||||
|
|
Loading…
Reference in a new issue