8000 feat: add commit message linter by mtojek · Pull Request #12 · coder/aicommit · GitHub
[go: up one dir, main page]

Skip to content

feat: add commit message linter #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
exit code
  • Loading branch information
mtojek committed Dec 6, 2024
commit 2bf3e0f15bfbfbcfdf3a6b6cb6c2694cc1918eab
15 changes: 14 additions & 1 deletion cmd/aicommit/lint.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package main

import (
"fmt"
"io"
"os"
"strings"

"github.com/coder/aicommit"
"github.com/coder/serpent"
Expand Down Expand Up @@ -56,6 +58,8 @@ func lint(inv *serpent.Invocation, opts runOptions) error {
}
defer stream.Close()

var validationFailed bool

for {
resp, err := stream.Recv()
if err != nil {
Expand All @@ -67,7 +71,12 @@ func lint(inv *serpent.Invocation, opts runOptions) error {
}

if len(resp.Choices) > 0 {
inv.Stdout.Write([]byte(resp.Choices[0].Delta.Content))
c := resp.Choices[0].Delta.Content
inv.Stdout.Write([]byte(c))

if strings.HasPrefix(c, "❌") {
validationFailed = true
}
} else {
inv.Stdout.Write([]byte("\n"))
}
Expand All @@ -77,5 +86,9 @@ func lint(inv *serpent.Invocation, opts runOptions) error {
debugf("total tokens: %d", resp.Usage.TotalTokens)
}
}

if validationFailed {
return fmt.Errorf("validation failed")
}
return nil
}
0