* Fetch existing comments on the issue
( owner: string, repo: string, issueNumber: number, githubToken: string )
| 26 | * Fetch existing comments on the issue |
| 27 | */ |
| 28 | async function fetchIssueComments( |
| 29 | owner: string, |
| 30 | repo: string, |
| 31 | issueNumber: number, |
| 32 | githubToken: string |
| 33 | ): Promise<string> { |
| 34 | try { |
| 35 | const client = new Octokit({ auth: githubToken }); |
| 36 | |
| 37 | const { data: comments } = await retryWithBackoff(async () => { |
| 38 | return await client.issues.listComments({ |
| 39 | owner, |
| 40 | repo, |
| 41 | issue_number: issueNumber, |
| 42 | per_page: MAX_COMMENTS_TO_FETCH, |
| 43 | sort: "created", |
| 44 | direction: "asc", |
| 45 | }); |
| 46 | }); |
| 47 | |
| 48 | if (comments.length === 0) { |
| 49 | return "(No comments yet)"; |
| 50 | } |
| 51 | |
| 52 | // Format comments with author and body |
| 53 | const formattedComments = comments |
| 54 | .map((comment, index) => { |
| 55 | const author = comment.user?.login || "unknown"; |
| 56 | const body = comment.body || ""; |
| 57 | return `Comment ${index + 1} by @${author}:\n${body}`; |
| 58 | }) |
| 59 | .join("\n\n---\n\n"); |
| 60 | |
| 61 | // Truncate if too long |
| 62 | if (formattedComments.length > MAX_COMMENTS_LENGTH) { |
| 63 | return formattedComments.substring(0, MAX_COMMENTS_LENGTH) + "\n\n[Comments truncated for length]"; |
| 64 | } |
| 65 | |
| 66 | return formattedComments; |
| 67 | } catch (error) { |
| 68 | console.error("Error fetching issue comments:", error); |
| 69 | return "(Unable to fetch comments)"; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Initialize Bedrock client with AWS credentials |
no test coverage detected