Skip to content
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

feat: Add emojis to console output #4

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ To review a pull request, run the following command:
./cadre --url [url to github pull request]
```

ex:

![Screenshot](./assets/cadre-cli-screenshot.png)

or

```bash
Expand Down
Binary file added assets/cadre-cli-screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 0 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@ github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/kmesiab/go-github-diff v0.1.0-alpha h1:Iq05K3nXD/iyh2RGTjKudmI5YDs/nI1I8+ChE27gcN8=
github.com/kmesiab/go-github-diff v0.1.0-alpha/go.mod h1:eqE039Qx1HUnJ4hjLBPU9UHE+3KxbEmUOear9QcV12M=
github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0=
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw=
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
Expand All @@ -45,7 +42,6 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
Expand All @@ -58,14 +54,11 @@ golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
Expand Down
40 changes: 24 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func main() {
os.Exit(cli.Run(new(argT), func(ctx *cli.Context) error {
argv := ctx.Argv().(*argT)

printGreeting()

mergedArgs, err := coalesceConfiguration(argv)
if err != nil {
return fmt.Errorf("couldn't figure out the configuration. %s", err)
Expand All @@ -40,22 +42,25 @@ func main() {
"or set the OPENAI_API_KEY environment variable")
}

fmt.Printf("📡 Getting pull request from GitHub...\n")

parsedDiffFiles, err := processPullRequest(mergedArgs.URL, &GithubDiffClient{})

if err != nil {
return err
}

fmt.Printf("Processing %d diff files. This may take a while...\n", len(parsedDiffFiles))
fmt.Printf("\n⌛ Processing %d diff files. This may take a while...\n\n", len(parsedDiffFiles))

reviews, err := getCodeReviews(parsedDiffFiles, "gpt-4", mergedArgs.ApiKey, &OpenAICompletionService{})
reviews, err := getCodeReviews(parsedDiffFiles, "gpt-4-1106-preview", mergedArgs.ApiKey, &OpenAICompletionService{})
if err != nil {
return err
}

for _, review := range reviews {

if review.Error != nil {
fmt.Printf("ERROR: couldn't get the review for %s: %s\n",
fmt.Printf("⚠️ couldn't get the review for %s: %s\n",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message for a failed review retrieval is clear and includes the filename, which is helpful for debugging purposes. However, consider logging the full path for more clarity in cases where filenames might be duplicated in different directories.

- fmt.Printf("⚠️ couldn't get the review for %s:  %s\n",
+ fmt.Printf("⚠️ couldn't get the review for %s:  %s\n",
  path.Base(review.Diff.FilePathNew),
  review.Error,
)

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
fmt.Printf("⚠️ couldn't get the review for %s: %s\n",
fmt.Printf("⚠️ couldn't get the review for %s: %s\n",
path.Base(review.Diff.FilePathNew),
review.Error,
)

path.Base(review.Diff.FilePathNew),
review.Error,
)
Expand All @@ -68,26 +73,18 @@ func main() {
err := saveReviewToFile(filename, review.Review)

if err != nil {
fmt.Printf("couldn't save the review for %s: %s",
fmt.Printf("⚠️ couldn't save the review for %s: %s\n",
filename,
err,
)

continue
}

fmt.Printf("Saved review to %s\n", filename)

if err != nil {
fmt.Printf("couldn't save the review for %s: %s",
filename,
err,
)

continue
}
fmt.Printf("💾 Saved review to %s\n", filename)
}

fmt.Println("Done! 🏁")
return nil
}))
}
Expand All @@ -98,7 +95,7 @@ func getCodeReviews(diffs []*gh.GitDiff, model, apiKey string, svc CompletionSer

for _, diff := range diffs {
go func(d *gh.GitDiff) {
fmt.Printf("Processing %s\n", path.Base(d.FilePathNew))
fmt.Printf("🤖 Getting code review for %s\n", path.Base(d.FilePathNew))

review, err := svc.GetCompletion(d.DiffContents, model, apiKey)

Expand Down Expand Up @@ -165,7 +162,6 @@ func saveReviewToFile(filename, reviewContent string) error {
return fmt.Errorf("failed to write review to file: %s", err)
}

fmt.Printf("Saved review to %s\n", filename)
return nil
}

Expand All @@ -186,3 +182,15 @@ func coalesceConfiguration(cliArgs *argT) (*argT, error) {

return cliArgs, nil
}

func printGreeting() {
fmt.Println(`
_____ ___ ____________ _____
/ __ \ / _ \| _ \ ___ \ ___|
| / \// /_\ \ | | | |_/ / |__
| | | _ | | | | /| __|
| \__/\| | | | |/ /| |\ \| |___
\____/\_| |_/___/ \_| \_\____/

`)
}
Comment on lines +186 to +196
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The printGreeting function prints a stylized greeting banner. This is a nice touch for the user interface, but ensure that the output is well-formatted on all terminal sizes to avoid visual clutter.

Loading