Skip to content

Commit

Permalink
added -names as optional solution (#2)
Browse files Browse the repository at this point in the history
* added -names as optional solution

* switched names to logins
  • Loading branch information
m1ome authored Oct 2, 2024
1 parent 65601b8 commit cba635e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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)
}
Expand Down

0 comments on commit cba635e

Please sign in to comment.