···
+
"github.com/urfave/cli/v3"
+
// The hook command is nested like so:
+
// knot hook --[flags] [hook]
+
func Command() *cli.Command {
+
Usage: "run git hooks",
+
Usage: "base directory for git repos",
+
Usage: "git user's did",
+
Usage: "git user's handle",
+
Usage: "endpoint for the internal API",
+
Value: "http://localhost:5444",
+
Commands: []*cli.Command{
+
Usage: "sends a post-recieve hook to the knot (waits for stdin)",
+
func postRecieve(ctx context.Context, cmd *cli.Command) error {
+
gitDir := cmd.String("git-dir")
+
userDid := cmd.String("user-did")
+
userHandle := cmd.String("user-handle")
+
endpoint := cmd.String("internal-api")
+
payloadReader := bufio.NewReader(os.Stdin)
+
payload, _ := payloadReader.ReadString('\n')
+
client := &http.Client{}
+
req, err := http.NewRequest("POST", endpoint+"/hooks/post-receive", strings.NewReader(payload))
+
return fmt.Errorf("failed to create request: %w", err)
+
req.Header.Set("Content-Type", "text/plain")
+
req.Header.Set("X-Git-Dir", gitDir)
+
req.Header.Set("X-Git-User-Did", userDid)
+
req.Header.Set("X-Git-User-Handle", userHandle)
+
resp, err := client.Do(req)
+
return fmt.Errorf("failed to execute request: %w", err)
+
defer resp.Body.Close()
+
if resp.StatusCode != http.StatusOK {
+
return fmt.Errorf("unexpected status code: %d", resp.StatusCode)