testing with splitted issues
This commit is contained in:
parent
a9a2af6b3d
commit
b6ce1f8b29
1 changed files with 83 additions and 10 deletions
93
approval.go
93
approval.go
|
|
@ -85,9 +85,9 @@ func (a *approvalEnvironment) createApprovalIssue(ctx context.Context) error {
|
|||
formatAcceptedWords(deniedWords),
|
||||
)
|
||||
|
||||
if a.issueBody != "" {
|
||||
issueBody = fmt.Sprintf(">%s\n>\n%s", a.issueBody, issueBody)
|
||||
}
|
||||
// if a.issueBody != "" {
|
||||
// issueBody = fmt.Sprintf(">%s\n>\n%s", a.issueBody, issueBody)
|
||||
// }
|
||||
issueBody = fmt.Sprintf(">[!NOTE]\n%s", issueBody)
|
||||
|
||||
var err error
|
||||
|
|
@ -109,13 +109,14 @@ func (a *approvalEnvironment) createApprovalIssue(ctx context.Context) error {
|
|||
}
|
||||
a.approvalIssueNumber = a.approvalIssue.GetNumber()
|
||||
|
||||
// Now add a comment to the same issue
|
||||
commentBody := "This is a comment on the issue."
|
||||
_, _, err = a.client.Issues.CreateComment(ctx, a.targetRepoOwner, a.targetRepoName, *a.approvalIssue.Number, &github.IssueComment{
|
||||
Body: &commentBody,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to add comment to issue: %w", err)
|
||||
bodyChunks := splitLongString(a.issueBody, 65)
|
||||
for _, chunk := range bodyChunks {
|
||||
_, _, err = a.client.Issues.CreateComment(ctx, a.targetRepoOwner, a.targetRepoName, *a.approvalIssue.Number, &github.IssueComment{
|
||||
Body: &chunk,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to add comment chunk to issue: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("Issue created: %s\n", a.approvalIssue.GetHTMLURL())
|
||||
|
|
@ -253,3 +254,75 @@ func formatAcceptedWords(words []string) string {
|
|||
|
||||
return strings.Join(quotedWords, ", ")
|
||||
}
|
||||
|
||||
func splitLongLine(line string, maxL int) ([]string, bool) {
|
||||
if len(line) <= maxL {
|
||||
return []string{line}, false
|
||||
}
|
||||
|
||||
words := strings.Fields(line)
|
||||
var result []string
|
||||
var currentLine string
|
||||
|
||||
for _, word := range words {
|
||||
if len(currentLine)+len(word)+1 > maxL {
|
||||
result = append(result, currentLine)
|
||||
currentLine = word
|
||||
} else {
|
||||
if currentLine != "" {
|
||||
currentLine += " "
|
||||
}
|
||||
currentLine += word
|
||||
}
|
||||
}
|
||||
if currentLine != "" {
|
||||
result = append(result, currentLine)
|
||||
}
|
||||
return result, true
|
||||
}
|
||||
|
||||
func splitLongString(input string, maxLength int) []string {
|
||||
var result []string
|
||||
|
||||
lines := strings.Split(input, "\n")
|
||||
currentChunk := strings.Builder{}
|
||||
currentLength := 0
|
||||
|
||||
for i, line := range lines {
|
||||
if i < len(lines)-1 {
|
||||
lineLength++
|
||||
}
|
||||
|
||||
lineLength := len(line)
|
||||
if currentLength+lineLength > maxLength {
|
||||
if currentChunk.Len() > 0 {
|
||||
result = append(result, currentChunk.String())
|
||||
currentChunk.Reset()
|
||||
currentLength = 0
|
||||
}
|
||||
}
|
||||
|
||||
lineSplit, isLongLine := splitLongLine(line, maxLength)
|
||||
if isLongLine {
|
||||
if currentChunk.Len() > 0 {
|
||||
result = append(result, currentChunk.String())
|
||||
currentChunk.Reset()
|
||||
}
|
||||
result = append(result, lineSplit[:len(lineSplit)-1]...)
|
||||
currentChunk.WriteString(lineSplit[len(lineSplit)-1])
|
||||
currentLength = len(lineSplit[len(lineSplit)-1])
|
||||
} else {
|
||||
currentChunk.WriteString(line)
|
||||
currentLength += lineLength
|
||||
}
|
||||
|
||||
if i < len(lines)-1 {
|
||||
currentChunk.WriteString("\n")
|
||||
}
|
||||
}
|
||||
if currentChunk.Len() > 0 {
|
||||
result = append(result, currentChunk.String())
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue