Rewrite how tests are defined

This commit is contained in:
Akbar Rahman 2021-07-29 07:42:02 +01:00
parent a82726ca52
commit 4691ea5cc3
2 changed files with 14 additions and 3 deletions

View File

@ -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" ]
}
]
} }
} }
} }

View File

@ -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 {