Skip to content

Commit 40b23ee

Browse files
feat: update
1 parent b902dc2 commit 40b23ee

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

internal/actions/test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"path/filepath"
99
"strings"
1010

11-
"github.com/google/go-github/v63/github"
1211
config "github.com/speakeasy-api/sdk-gen-config"
1312
"github.com/speakeasy-api/sdk-generation-action/internal/cli"
1413
"github.com/speakeasy-api/sdk-generation-action/internal/configuration"
@@ -156,11 +155,11 @@ func writeTestReportComment(g *git.Git, prNumber *int, testReportURL, targetName
156155
return nil
157156
}
158157

159-
currentPRComments, _ := g.ListPRComments(*prNumber)
158+
currentPRComments, _ := g.ListIssueComments(*prNumber)
160159
for _, comment := range currentPRComments {
161160
commentBody := comment.GetBody()
162161
if strings.Contains(commentBody, fmt.Sprintf(testReportCommentPrefix, targetName)) {
163-
if err := g.DeletePRComment(comment.GetID()); err != nil {
162+
if err := g.DeleteIssueComment(comment.GetID()); err != nil {
164163
fmt.Println(fmt.Sprintf("Failed to delete existing test report comment: %s\n", err.Error()))
165164
}
166165
}
@@ -173,7 +172,7 @@ func writeTestReportComment(g *git.Git, prNumber *int, testReportURL, targetName
173172

174173
body := titleComment + "\n\n" + fmt.Sprintf(testReportCommentPrefix, targetName) + " " + fmt.Sprintf("[here](%s)", testReportURL)
175174

176-
err := g.WritePRComment(*prNumber, body, github.PullRequestComment{})
175+
err := g.WriteIssueComment(*prNumber, body)
177176

178177
return err
179178
}

internal/git/git.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -875,19 +875,19 @@ func (g *Git) WritePRBody(prNumber int, body string) error {
875875
return nil
876876
}
877877

878-
func (g *Git) ListPRComments(prNumber int) ([]*github.PullRequestComment, error) {
879-
comments, _, err := g.client.PullRequests.ListComments(context.Background(), os.Getenv("GITHUB_REPOSITORY_OWNER"), GetRepo(), prNumber, nil)
878+
func (g *Git) ListIssueComments(prNumber int) ([]*github.IssueComment, error) {
879+
comments, _, err := g.client.Issues.ListComments(context.Background(), os.Getenv("GITHUB_REPOSITORY_OWNER"), GetRepo(), prNumber, nil)
880880
if err != nil {
881881
return nil, fmt.Errorf("failed to get PR comments: %w", err)
882882
}
883883

884884
return comments, nil
885885
}
886886

887-
func (g *Git) DeletePRComment(commentID int64) error {
888-
_, err := g.client.PullRequests.DeleteComment(context.Background(), os.Getenv("GITHUB_REPOSITORY_OWNER"), GetRepo(), commentID)
887+
func (g *Git) DeleteIssueComment(commentID int64) error {
888+
_, err := g.client.Issues.DeleteComment(context.Background(), os.Getenv("GITHUB_REPOSITORY_OWNER"), GetRepo(), commentID)
889889
if err != nil {
890-
return fmt.Errorf("failed to delete PR comment: %w", err)
890+
return fmt.Errorf("failed to delete issue comment: %w", err)
891891
}
892892

893893
return nil
@@ -912,6 +912,19 @@ func (g *Git) WritePRComment(prNumber int, fileName, body string, line int) erro
912912
return nil
913913
}
914914

915+
func (g *Git) WriteIssueComment(prNumber int, body string) error {
916+
comment := &github.IssueComment{
917+
Body: github.String(sanitizeExplanations(body)),
918+
}
919+
920+
_, _, err := g.client.Issues.CreateComment(context.Background(), os.Getenv("GITHUB_REPOSITORY_OWNER"), GetRepo(), prNumber, comment)
921+
if err != nil {
922+
return fmt.Errorf("failed to create issue comment: %w", err)
923+
}
924+
925+
return nil
926+
}
927+
915928
func sanitizeExplanations(str string) string {
916929
// Remove ANSI sequences
917930
ansiEscape := regexp.MustCompile(`\x1b[^m]*m`)

0 commit comments

Comments
 (0)