mirror of
https://github.com/alvierahman90/gohookr.git
synced 2024-11-21 16:49:52 +00:00
Rewrite how tests are defined
This commit is contained in:
parent
a82726ca52
commit
4691ea5cc3
@ -3,7 +3,13 @@
|
||||
"test": {
|
||||
"Script": "./example.sh",
|
||||
"Secret": "THISISVERYSECRET",
|
||||
"SignatureHeader": "X-Gitea-Signature"
|
||||
"SignatureHeader": "X-Gitea-Signature",
|
||||
"Tests": [
|
||||
{
|
||||
"Command": "git",
|
||||
"Arguments": [ "pull" ]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
9
main.go
9
main.go
@ -73,7 +73,7 @@ func webhook(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Run tests, immediately stop if one fails
|
||||
for _, test := range service.Tests {
|
||||
if _, err := exec.Command(test[0], test[1:]...).Output(); err != nil {
|
||||
if _, err := exec.Command(test.Command, test.Arguments...).Output(); err != nil {
|
||||
writeResponse(w, 409,
|
||||
fmt.Sprintf("409 Conflict: Test failed: %v", err.Error()),
|
||||
)
|
||||
@ -101,12 +101,17 @@ func getSha256HMACSignature(secret []byte, data string) string {
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
type Test struct {
|
||||
Command string
|
||||
Arguments []string
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
Gitea bool
|
||||
Script string
|
||||
Secret string
|
||||
SignatureHeader string
|
||||
Tests [][]string
|
||||
Tests []Test
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
|
Loading…
Reference in New Issue
Block a user