fix QoL and Ai integration
This commit is contained in:
23
ai_store.go
23
ai_store.go
@@ -111,6 +111,12 @@ func (s *aiStoredState) Merge(pr PRDetails) PRDetails {
|
||||
}
|
||||
for i := range result.Threads {
|
||||
if comments := s.Annotations[result.Threads[i].ID]; len(comments) > 0 {
|
||||
comments = slices.Clone(comments)
|
||||
for index := range comments {
|
||||
if comments[index].Origin == reviewOriginLocalAIUser && pr.ViewerLogin != "" {
|
||||
comments[index].Author = pr.ViewerLogin
|
||||
}
|
||||
}
|
||||
result.Threads[i].Comments = append(result.Threads[i].Comments, comments...)
|
||||
}
|
||||
}
|
||||
@@ -118,7 +124,7 @@ func (s *aiStoredState) Merge(pr PRDetails) PRDetails {
|
||||
}
|
||||
|
||||
func (s *aiStoredState) Apply(
|
||||
pr PRDetails, output aiOutput, provider, model, targetThread string,
|
||||
pr PRDetails, output aiOutput, provider, model, targetThread, message string,
|
||||
validLines map[string]map[int]bool,
|
||||
validDeleted map[string]map[int]bool,
|
||||
diffText map[string]string,
|
||||
@@ -142,6 +148,9 @@ func (s *aiStoredState) Apply(
|
||||
for _, comment := range thread.Comments {
|
||||
existing[aiFingerprint(thread.Path, thread.StartLine, thread.Line, "", comment.Body)] = true
|
||||
existing[aiFingerprint(thread.ID, 0, 0, "", comment.Body)] = true
|
||||
if comment.Origin == reviewOriginLocalAIUser {
|
||||
existing[aiFingerprint(thread.ID, 0, 0, "user", comment.Body)] = true
|
||||
}
|
||||
combined.WriteString(" ")
|
||||
combined.WriteString(comment.Body)
|
||||
}
|
||||
@@ -234,6 +243,18 @@ func (s *aiStoredState) Apply(
|
||||
if targetThread != "" {
|
||||
validThreads = map[string]bool{targetThread: true}
|
||||
}
|
||||
message = safeAIText(message)
|
||||
if targetThread != "" && strings.TrimSpace(message) != "" {
|
||||
fingerprint := aiFingerprint(targetThread, 0, 0, "user", message)
|
||||
if !existing[fingerprint] {
|
||||
existing[fingerprint] = true
|
||||
s.Annotations[targetThread] = append(s.Annotations[targetThread], ReviewComment{
|
||||
ID: "local-ai-user-" + fingerprint,
|
||||
Author: firstNonEmpty(pr.ViewerLogin, "you"), Body: message,
|
||||
CreatedAt: time.Now(), Origin: reviewOriginLocalAIUser,
|
||||
})
|
||||
}
|
||||
}
|
||||
for _, annotation := range output.ThreadComments {
|
||||
if !validThreads[annotation.ThreadID] {
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user