Skip to content

Commit

Permalink
feat: Don't save to a folder, save relative
Browse files Browse the repository at this point in the history
  • Loading branch information
kmesiab committed Jan 17, 2024
1 parent b90544f commit 6880210
Showing 1 changed file with 28 additions and 2 deletions.
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
}

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

0 comments on commit 6880210

Please sign in to comment.