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: Don't save to a folder, save relative #3

Merged
merged 1 commit into from
Jan 17, 2024
Merged
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
30 changes: 28 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,18 @@ func main() {
continue
}

filename := "reviews/" + path.Base(review.Diff.FilePathNew) + ".md"
err := os.WriteFile(filename, []byte(review.Review), 0o644)
filename := path.Base(review.Diff.FilePathNew) + ".md"

err := saveReviewToFile(filename, review.Review)

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

continue
}
Comment on lines +70 to +77
Copy link

Choose a reason for hiding this comment

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

There is duplicated error handling code for the file saving process. The second error check and message are unnecessary since the loop will continue regardless.

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

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
if err != nil {
fmt.Printf("couldn't save the review for %s: %s",
filename,
err,
)
continue
}


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

Expand Down Expand Up @@ -143,6 +153,22 @@ func processPullRequest(prURL string, ghClient GithubDiffClientInterface) ([]*gh
return parsedDiff, nil
}

func saveReviewToFile(filename, reviewContent string) error {
// Check if the file already exists
if _, err := os.Stat(filename); err == nil {
return fmt.Errorf("file %s already exists, not overwriting", filename)
}

// Write the review content to the file
err := os.WriteFile(filename, []byte(reviewContent), 0644)
if err != nil {
return fmt.Errorf("failed to write review to file: %s", err)
}

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

func coalesceConfiguration(cliArgs *argT) (*argT, error) {
envArgs := &argT{}

Expand Down
Loading