diff --git a/GPTPullRequestReview/src/pr.ts b/GPTPullRequestReview/src/pr.ts index 8cff1de..2695eb9 100644 --- a/GPTPullRequestReview/src/pr.ts +++ b/GPTPullRequestReview/src/pr.ts @@ -39,7 +39,7 @@ export async function deleteExistingComments(httpsAgent: Agent) { }); const threads = await threadsResponse.json() as { value: [] }; - const threadsWithContext = threads.value.filter((thread: any) => thread.threadContext !== null); + const threadsWithContext = (threads.value || []).filter((thread: any) => thread.threadContext !== null); const collectionUri = tl.getVariable('SYSTEM.TEAMFOUNDATIONCOLLECTIONURI') as string; const collectionName = getCollectionName(collectionUri); @@ -53,8 +53,9 @@ export async function deleteExistingComments(httpsAgent: Agent) { }); const comments = await commentsResponse.json() as { value: [] }; + const commmentsValues = comments.value || [] - for (const comment of comments.value.filter((comment: any) => comment.author.displayName === buildServiceName) as any[]) { + for (const comment of commmentsValues.filter((comment: any) => comment.author.displayName === buildServiceName) as any[]) { const removeCommentUrl = `${tl.getVariable('SYSTEM.TEAMFOUNDATIONCOLLECTIONURI')}${tl.getVariable('SYSTEM.TEAMPROJECTID')}/_apis/git/repositories/${tl.getVariable('Build.Repository.Name')}/pullRequests/${tl.getVariable('System.PullRequest.PullRequestId')}/threads/${thread.id}/comments/${comment.id}?api-version=5.1`; await fetch(removeCommentUrl, {