Something went wrong. Try again.
CLI that turns LLM input into well-formatted Conventional Commits
Something went wrong. Try again.
git-format git.go
1.1 kB · 50 lines
Go
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>//// SPDX-License-Identifier: AGPL-3.0-or-later
package main
import ( "fmt" "os" "os/exec")
func runGitWithStdin(args []string, content string) error { gitCmd := exec.Command("git", args...) gitCmd.Stdout = os.Stdout gitCmd.Stderr = os.Stderr
stdin, err := gitCmd.StdinPipe() if err != nil { return fmt.Errorf("failed to create stdin pipe: %w", err) }
if err := gitCmd.Start(); err != nil { return fmt.Errorf("failed to start git command: %w", err) }
if _, err := stdin.Write([]byte(content)); err != nil { return fmt.Errorf("failed to write to git stdin: %w", err) }
if err := stdin.Close(); err != nil { return fmt.Errorf("failed to close stdin: %w", err) }
if err := gitCmd.Wait(); err != nil { return fmt.Errorf("git %s failed: %w", args[0], err) }
return nil}
func validateSubjectLength(subject string) error { length := len(subject) if length > 50 { exceededBy := length - 50 truncated := subject[:50] + "…" return fmt.Errorf("subject exceeds 50 character limit by %d:\n%s", exceededBy, truncated) } return nil}