From 1c9d0944fc3919689531df7aa17edbf208f76ab9 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Fri, 6 Dec 2024 06:07:50 -0500 Subject: [PATCH 1/2] fix(discussions): answered discussions only supported in GHSE 3.12 or higher Signed-off-by: Adam Setch --- src/renderer/utils/api/client.ts | 4 ++ src/renderer/utils/api/graphql/discussions.ts | 3 +- src/renderer/utils/helpers.test.ts | 45 +++++++++++++++++++ src/renderer/utils/helpers.ts | 26 ++++++++++- 4 files changed, 76 insertions(+), 2 deletions(-) diff --git a/src/renderer/utils/api/client.ts b/src/renderer/utils/api/client.ts index e5c4e5dd9..47e66da57 100644 --- a/src/renderer/utils/api/client.ts +++ b/src/renderer/utils/api/client.ts @@ -22,6 +22,7 @@ import type { Release, UserDetails, } from '../../typesGitHub'; +import { isAnsweredDiscussionFeatureSupported } from '../helpers'; import { QUERY_SEARCH_DISCUSSIONS } from './graphql/discussions'; import { formatAsGitHubSearchSyntax } from './graphql/utils'; import { apiRequestAuth } from './request'; @@ -244,6 +245,9 @@ export async function searchDiscussions( firstDiscussions: 1, lastComments: 1, lastReplies: 1, + includeIsAnswered: isAnsweredDiscussionFeatureSupported( + notification.account, + ), }, }, ); diff --git a/src/renderer/utils/api/graphql/discussions.ts b/src/renderer/utils/api/graphql/discussions.ts index 93ec4c91a..edc7ca8d0 100644 --- a/src/renderer/utils/api/graphql/discussions.ts +++ b/src/renderer/utils/api/graphql/discussions.ts @@ -27,6 +27,7 @@ export const QUERY_SEARCH_DISCUSSIONS = gql` $firstDiscussions: Int $lastComments: Int $lastReplies: Int + $includeIsAnswered: Boolean! ) { search(query: $queryStatement, type: DISCUSSION, first: $firstDiscussions) { nodes { @@ -34,7 +35,7 @@ export const QUERY_SEARCH_DISCUSSIONS = gql` number title stateReason - isAnswered + isAnswered @include(if: $includeIsAnswered) url author { ...AuthorFields diff --git a/src/renderer/utils/helpers.test.ts b/src/renderer/utils/helpers.test.ts index 3656aaf6b..56f3beef6 100644 --- a/src/renderer/utils/helpers.test.ts +++ b/src/renderer/utils/helpers.test.ts @@ -27,6 +27,7 @@ import { getChevronDetails, getFilterCount, getPlatformFromHostname, + isAnsweredDiscussionFeatureSupported, isEnterpriseServerHost, isMarkAsDoneFeatureSupported, } from './helpers'; @@ -110,6 +111,50 @@ describe('renderer/utils/helpers.ts', () => { }); }); + describe('isAnsweredDiscussionFeatureSupported', () => { + it('should return true for GitHub Cloud', () => { + expect(isAnsweredDiscussionFeatureSupported(mockGitHubCloudAccount)).toBe( + true, + ); + }); + + it('should return false for GitHub Enterprise Server < v3.12', () => { + const account = { + ...mockGitHubEnterpriseServerAccount, + version: '3.11.0', + }; + + expect(isAnsweredDiscussionFeatureSupported(account)).toBe(false); + }); + + it('should return true for GitHub Enterprise Server >= v3.12', () => { + const account = { + ...mockGitHubEnterpriseServerAccount, + version: '3.12.3', + }; + + expect(isAnsweredDiscussionFeatureSupported(account)).toBe(true); + }); + + it('should return false for GitHub Enterprise Server when partial version available', () => { + const account = { + ...mockGitHubEnterpriseServerAccount, + version: '3', + }; + + expect(isAnsweredDiscussionFeatureSupported(account)).toBe(false); + }); + + it('should return false for GitHub Enterprise Server when no version available', () => { + const account = { + ...mockGitHubEnterpriseServerAccount, + version: null, + }; + + expect(isMarkAsDoneFeatureSupported(account)).toBe(false); + }); + }); + describe('generateNotificationReferrerId', () => { it('should generate the notification_referrer_id', () => { const referrerId = generateNotificationReferrerId(mockSingleNotification); diff --git a/src/renderer/utils/helpers.ts b/src/renderer/utils/helpers.ts index e3b2a7bc1..889e04617 100644 --- a/src/renderer/utils/helpers.ts +++ b/src/renderer/utils/helpers.ts @@ -27,9 +27,13 @@ export function isEnterpriseServerHost(hostname: Hostname): boolean { return !hostname.endsWith(Constants.DEFAULT_AUTH_OPTIONS.hostname); } +/** + * Check if the "Mark as done" feature is supported for the given account. + * + * GitHub Cloud or GitHub Enterprise Server 3.13 or newer is required to support this feature. + */ export function isMarkAsDoneFeatureSupported(account: Account): boolean { if (isEnterpriseServerHost(account.hostname)) { - // Support for "Mark as done" was added to GitHub Enterprise Server in v3.13 or newer if (account.version) { const version = account?.version.split('.').map(Number); return version[0] >= 3 && version[1] >= 13; @@ -41,6 +45,26 @@ export function isMarkAsDoneFeatureSupported(account: Account): boolean { return true; } +/** + * Check if the "answered" discussions are supported for the given account. + * + * GitHub Cloud or GitHub Enterprise Server 3.12 or newer is required to support this feature. + */ +export function isAnsweredDiscussionFeatureSupported( + account: Account, +): boolean { + if (isEnterpriseServerHost(account.hostname)) { + if (account.version) { + const version = account?.version.split('.').map(Number); + return version[0] >= 3 && version[1] >= 12; + } + + return false; + } + + return true; +} + export function generateNotificationReferrerId( notification: Notification, ): string { From dcce4a63864879e7bd0fb0034c6c3f063e14d5dc Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Fri, 6 Dec 2024 06:08:58 -0500 Subject: [PATCH 2/2] fix(discussions): answered discussions only supported in GHSE 3.12 or higher Signed-off-by: Adam Setch --- src/renderer/typesGitHub.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/typesGitHub.ts b/src/renderer/typesGitHub.ts index 5d6486051..95e6b2ffc 100644 --- a/src/renderer/typesGitHub.ts +++ b/src/renderer/typesGitHub.ts @@ -500,7 +500,7 @@ export interface Discussion { number: number; title: string; stateReason: DiscussionStateType; - isAnswered: boolean; + isAnswered: boolean | null; url: Link; author: DiscussionAuthor; comments: DiscussionComments;