From 4691ea5cc37349fe0ef6a7b8a6f1c30195007fa1 Mon Sep 17 00:00:00 2001 From: Alvie Rahman Date: Thu, 29 Jul 2021 07:42:02 +0100 Subject: [PATCH] Rewrite how tests are defined --- config.json | 8 +++++++- main.go | 9 +++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/config.json b/config.json index d7d9f38..2a3f74b 100644 --- a/config.json +++ b/config.json @@ -3,7 +3,13 @@ "test": { "Script": "./example.sh", "Secret": "THISISVERYSECRET", - "SignatureHeader": "X-Gitea-Signature" + "SignatureHeader": "X-Gitea-Signature", + "Tests": [ + { + "Command": "git", + "Arguments": [ "pull" ] + } + ] } } } diff --git a/main.go b/main.go index 0afef6b..dee5f93 100644 --- a/main.go +++ b/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 {