Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add empty arrays for variables that could be undefined to prevent errors #54

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions GPTPullRequestReview/src/pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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, {
Expand Down