mirror of
https://github.com/alibaba/open-code-review.git
synced 2026-07-09 17:28:58 +00:00
feat: 区分没有diff和没有评论的反馈
This commit is contained in:
parent
5aea3ac1ed
commit
a217a6f439
3 changed files with 31 additions and 2 deletions
|
|
@ -132,8 +132,32 @@ func buildDiffLines(comment model.LlmComment) []suggestdiff.DiffLine {
|
|||
return suggestdiff.ComputeLineDiff(oldLines, newLines)
|
||||
}
|
||||
|
||||
type jsonOutput struct {
|
||||
Status string `json:"status"`
|
||||
Message string `json:"message,omitempty"`
|
||||
Comments []model.LlmComment `json:"comments"`
|
||||
}
|
||||
|
||||
func outputJSON(comments []model.LlmComment) error {
|
||||
out := jsonOutput{
|
||||
Status: "success",
|
||||
Comments: comments,
|
||||
}
|
||||
if len(comments) == 0 {
|
||||
out.Message = "No comments generated."
|
||||
}
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
return enc.Encode(comments)
|
||||
return enc.Encode(out)
|
||||
}
|
||||
|
||||
func outputJSONNoFiles() error {
|
||||
out := jsonOutput{
|
||||
Status: "skipped",
|
||||
Message: "No supported files changed.",
|
||||
Comments: []model.LlmComment{},
|
||||
}
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
return enc.Encode(out)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,6 +133,11 @@ func runReview(args []string) error {
|
|||
telemetry.RecordCommentsGenerated(ctx, int64(len(comments)))
|
||||
}
|
||||
|
||||
// If no files were reviewed (e.g. workspace has no changes), inform the caller in JSON mode.
|
||||
if opts.outputFormat == "json" && len(comments) == 0 && ag.FilesReviewed() == 0 {
|
||||
return outputJSONNoFiles()
|
||||
}
|
||||
|
||||
telemetry.PrintTraceSummary(ag.FilesReviewed(), int64(len(comments)), ag.TotalInputTokens(), ag.TotalOutputTokens(), ag.TotalTokensUsed(), duration)
|
||||
|
||||
if opts.outputFormat == "json" {
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ func (a *Agent) Run(ctx context.Context) ([]model.LlmComment, error) {
|
|||
fmt.Fprintln(stdout.Writer(), "[ocr] No supported files changed. Skipping review.")
|
||||
telemetry.Event(ctx, "no.files.changed")
|
||||
a.session.Finalize()
|
||||
return nil, nil
|
||||
return []model.LlmComment{}, nil
|
||||
}
|
||||
|
||||
a.currentDate = time.Now().Format("2006-01-02 15:04")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue