From d8835c2998873ba2df34863f5169c758fa2abda9 Mon Sep 17 00:00:00 2001 From: Philip Gai Date: Thu, 2 Dec 2021 05:17:19 +0000 Subject: [PATCH] Conditionally require discussion category Only required when creating a repo discussion Fixes #40 --- web-app/src/eventHandlers/pullRequestEventHandler.ts | 2 +- web-app/src/services/parserService.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/web-app/src/eventHandlers/pullRequestEventHandler.ts b/web-app/src/eventHandlers/pullRequestEventHandler.ts index 07baa51..14d5789 100644 --- a/web-app/src/eventHandlers/pullRequestEventHandler.ts +++ b/web-app/src/eventHandlers/pullRequestEventHandler.ts @@ -438,7 +438,7 @@ Please fix the issues and recreate a new PR: } const discussionCategoryMatch = repoDiscussionCategories.find( (node) => - node?.name.trim().localeCompare(parsedItems.discussionCategoryName, undefined, { + node?.name.trim().localeCompare(parsedItems.discussionCategoryName!, undefined, { sensitivity: 'accent' }) === 0 ); diff --git a/web-app/src/services/parserService.ts b/web-app/src/services/parserService.ts index d3977dd..84d27a4 100644 --- a/web-app/src/services/parserService.ts +++ b/web-app/src/services/parserService.ts @@ -6,7 +6,7 @@ export interface ParsedMarkdownDiscussion { repoOwner: string | undefined; team: string | undefined; teamOwner: string | undefined; - discussionCategoryName: string; + discussionCategoryName: string | undefined; postBody: string; postTitle: string; author: string; @@ -86,7 +86,9 @@ export class ParserService { return teamName; } - public getDiscussionCategoryName(): string { + public getDiscussionCategoryName(): string | undefined { + const repoUrl = this.getTargetRepoUrl(); + if (!repoUrl) return; const rawCat = this._yamlHeader.category as string; const categoryName = rawCat?.split('/').pop()?.trim(); if (!categoryName) throw new Error('Unable to get discussion category');