From cba635e4e217b647004cec5273795d19e9a13b14 Mon Sep 17 00:00:00 2001 From: Pavel Makarenko Date: Wed, 2 Oct 2024 16:18:07 +0100 Subject: [PATCH] added -names as optional solution (#2) * added -names as optional solution * switched names to logins --- main.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 86408c5..0e52399 100644 --- a/main.go +++ b/main.go @@ -8,19 +8,24 @@ import ( "net/http" "os" "os/exec" + "slices" "strings" ) -var gist, codeword, cmd string +var gist, codeword, cmd, logins string type Comment struct { Body string `json:"body"` + User struct { + Login string `json:"login"` + } `json:"user"` } func init() { flag.StringVar(&gist, "gist", "", "gist id to look on") flag.StringVar(&codeword, "codeword", "", "codeword to work with") flag.StringVar(&cmd, "cmd", "", "command to run") + flag.StringVar(&logins, "logins", "", "possible name restrictions") flag.Parse() } @@ -38,6 +43,10 @@ func main() { for _, comment := range comments { if strings.Contains(comment.Body, codeword) { + if logins != "" && !slices.Contains(strings.Split(logins, ","), comment.User.Login) { + break + } + if err := exec.Command(command[0], command[1:]...).Start(); err != nil { log.Fatalf("error executing command: %v", err) }