mirror of
https://github.com/alvierahman90/gohookr.git
synced 2024-11-25 05:39:52 +00:00
Rewrite how tests are defined
This commit is contained in:
parent
a82726ca52
commit
4691ea5cc3
@ -3,7 +3,13 @@
|
|||||||
"test": {
|
"test": {
|
||||||
"Script": "./example.sh",
|
"Script": "./example.sh",
|
||||||
"Secret": "THISISVERYSECRET",
|
"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
|
// Run tests, immediately stop if one fails
|
||||||
for _, test := range service.Tests {
|
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,
|
writeResponse(w, 409,
|
||||||
fmt.Sprintf("409 Conflict: Test failed: %v", err.Error()),
|
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))
|
return hex.EncodeToString(h.Sum(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Test struct {
|
||||||
|
Command string
|
||||||
|
Arguments []string
|
||||||
|
}
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
Gitea bool
|
Gitea bool
|
||||||
Script string
|
Script string
|
||||||
Secret string
|
Secret string
|
||||||
SignatureHeader string
|
SignatureHeader string
|
||||||
Tests [][]string
|
Tests []Test
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user