Skip to content
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
17 changes: 14 additions & 3 deletions internal/event/callback/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,17 @@ const (
issueOpenedTitle = ":rotating_light: %s New issue opened! %s by %s"
issueAssignedTitleFormat = ":pray: %s assigned to %s"
issueClosedTitleFormat = ":x: %s closed by %s"
commentBodyMaxRunes = 100
)

func truncateRunes(s string, max int) string {
runes := []rune(s)
if len(runes) <= max {
return s
}
return string(runes[:max]) + "..."
}
Comment on lines +24 to +30

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

잘림 결과가 설정 길이(100 rune)를 초과할 수 있습니다.

현재 구현은 max rune를 남긴 뒤 "..."를 붙여, 잘린 경우 결과가 최대 max+3 rune가 됩니다. “100 rune 제한”을 엄밀히 지키려면 suffix 길이를 포함해 자르는 방식으로 바꾸는 게 맞습니다.

수정 예시
 func truncateRunes(s string, max int) string {
+	if max <= 0 {
+		return ""
+	}
 	runes := []rune(s)
 	if len(runes) <= max {
 		return s
 	}
-	return string(runes[:max]) + "..."
+	const suffix = "..."
+	suffixRunes := len([]rune(suffix))
+	if max <= suffixRunes {
+		return string(runes[:max])
+	}
+	return string(runes[:max-suffixRunes]) + suffix
 }
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func truncateRunes(s string, max int) string {
runes := []rune(s)
if len(runes) <= max {
return s
}
return string(runes[:max]) + "..."
}
func truncateRunes(s string, max int) string {
if max <= 0 {
return ""
}
runes := []rune(s)
if len(runes) <= max {
return s
}
const suffix = "..."
suffixRunes := len([]rune(suffix))
if max <= suffixRunes {
return string(runes[:max])
}
return string(runes[:max-suffixRunes]) + suffix
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/event/callback/issue.go` around lines 24 - 30, The truncateRunes
function currently appends "..." after taking max runes, which can produce
strings longer than max; update truncateRunes to account for the suffix length
by measuring suffixRunes := len([]rune("...")) and when len(runes) > max return
string(runes[:max-suffixRunes]) + "..." so the total rune count <= max; also
handle the edge case where max <= suffixRunes by returning string(runes[:max])
(i.e., no room for the full suffix) so you never exceed the requested max.


func NewIssueCommentCreated(commonSvc *svc.CommonSvc, issueSvc *svc.IssueSvc) *IssueCommentCreated {
return &IssueCommentCreated{
commonSvc: commonSvc,
Expand Down Expand Up @@ -85,9 +94,11 @@ func (cb *IssueCommentCreated) buildMessage(ctx context.Context, installCtx gith
title = fmt.Sprintf(issueCommentCreatedTitleFormat, mentionTexts.String(), model.InlineLink(event.Issue.GetHTMLURL(), "issue"), sender)
}

return model.NewMessage(
model.NewTextBlock(title),
), nil
blocks := []model.MessageBlock{model.NewTextBlock(title)}
if body := truncateRunes(event.Comment.GetBody(), commentBodyMaxRunes); body != "" {
blocks = append(blocks, model.NewTextBlock(model.EscapedString(body)))
}
return model.NewMessage(blocks...), nil
}

func NewIssuesEventOpened(commonSvc *svc.CommonSvc, issueSvc *svc.IssueSvc) *IssuesEventOpened {
Expand Down
Loading