Skip to content

Commit 40f03ab

Browse files
authored
fix(discussions): answered discussions only available in GHES 3.12 or higher (#1665)
* fix(discussions): answered discussions only supported in GHSE 3.12 or higher Signed-off-by: Adam Setch <[email protected]> * fix(discussions): answered discussions only supported in GHSE 3.12 or higher Signed-off-by: Adam Setch <[email protected]> --------- Signed-off-by: Adam Setch <[email protected]>
1 parent 7db6883 commit 40f03ab

File tree

5 files changed

+77
-3
lines changed

5 files changed

+77
-3
lines changed

src/renderer/typesGitHub.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ export interface Discussion {
500500
number: number;
501501
title: string;
502502
stateReason: DiscussionStateType;
503-
isAnswered: boolean;
503+
isAnswered: boolean | null;
504504
url: Link;
505505
author: DiscussionAuthor;
506506
comments: DiscussionComments;

src/renderer/utils/api/client.ts

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import type {
2222
Release,
2323
UserDetails,
2424
} from '../../typesGitHub';
25+
import { isAnsweredDiscussionFeatureSupported } from '../helpers';
2526
import { QUERY_SEARCH_DISCUSSIONS } from './graphql/discussions';
2627
import { formatAsGitHubSearchSyntax } from './graphql/utils';
2728
import { apiRequestAuth } from './request';
@@ -244,6 +245,9 @@ export async function searchDiscussions(
244245
firstDiscussions: 1,
245246
lastComments: 1,
246247
lastReplies: 1,
248+
includeIsAnswered: isAnsweredDiscussionFeatureSupported(
249+
notification.account,
250+
),
247251
},
248252
},
249253
);

src/renderer/utils/api/graphql/discussions.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ export const QUERY_SEARCH_DISCUSSIONS = gql`
2727
$firstDiscussions: Int
2828
$lastComments: Int
2929
$lastReplies: Int
30+
$includeIsAnswered: Boolean!
3031
) {
3132
search(query: $queryStatement, type: DISCUSSION, first: $firstDiscussions) {
3233
nodes {
3334
... on Discussion {
3435
number
3536
title
3637
stateReason
37-
isAnswered
38+
isAnswered @include(if: $includeIsAnswered)
3839
url
3940
author {
4041
...AuthorFields

src/renderer/utils/helpers.test.ts

+45
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
getChevronDetails,
2828
getFilterCount,
2929
getPlatformFromHostname,
30+
isAnsweredDiscussionFeatureSupported,
3031
isEnterpriseServerHost,
3132
isMarkAsDoneFeatureSupported,
3233
} from './helpers';
@@ -110,6 +111,50 @@ describe('renderer/utils/helpers.ts', () => {
110111
});
111112
});
112113

114+
describe('isAnsweredDiscussionFeatureSupported', () => {
115+
it('should return true for GitHub Cloud', () => {
116+
expect(isAnsweredDiscussionFeatureSupported(mockGitHubCloudAccount)).toBe(
117+
true,
118+
);
119+
});
120+
121+
it('should return false for GitHub Enterprise Server < v3.12', () => {
122+
const account = {
123+
...mockGitHubEnterpriseServerAccount,
124+
version: '3.11.0',
125+
};
126+
127+
expect(isAnsweredDiscussionFeatureSupported(account)).toBe(false);
128+
});
129+
130+
it('should return true for GitHub Enterprise Server >= v3.12', () => {
131+
const account = {
132+
...mockGitHubEnterpriseServerAccount,
133+
version: '3.12.3',
134+
};
135+
136+
expect(isAnsweredDiscussionFeatureSupported(account)).toBe(true);
137+
});
138+
139+
it('should return false for GitHub Enterprise Server when partial version available', () => {
140+
const account = {
141+
...mockGitHubEnterpriseServerAccount,
142+
version: '3',
143+
};
144+
145+
expect(isAnsweredDiscussionFeatureSupported(account)).toBe(false);
146+
});
147+
148+
it('should return false for GitHub Enterprise Server when no version available', () => {
149+
const account = {
150+
...mockGitHubEnterpriseServerAccount,
151+
version: null,
152+
};
153+
154+
expect(isMarkAsDoneFeatureSupported(account)).toBe(false);
155+
});
156+
});
157+
113158
describe('generateNotificationReferrerId', () => {
114159
it('should generate the notification_referrer_id', () => {
115160
const referrerId = generateNotificationReferrerId(mockSingleNotification);

src/renderer/utils/helpers.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ export function isEnterpriseServerHost(hostname: Hostname): boolean {
2727
return !hostname.endsWith(Constants.DEFAULT_AUTH_OPTIONS.hostname);
2828
}
2929

30+
/**
31+
* Check if the "Mark as done" feature is supported for the given account.
32+
*
33+
* GitHub Cloud or GitHub Enterprise Server 3.13 or newer is required to support this feature.
34+
*/
3035
export function isMarkAsDoneFeatureSupported(account: Account): boolean {
3136
if (isEnterpriseServerHost(account.hostname)) {
32-
// Support for "Mark as done" was added to GitHub Enterprise Server in v3.13 or newer
3337
if (account.version) {
3438
const version = account?.version.split('.').map(Number);
3539
return version[0] >= 3 && version[1] >= 13;
@@ -41,6 +45,26 @@ export function isMarkAsDoneFeatureSupported(account: Account): boolean {
4145
return true;
4246
}
4347

48+
/**
49+
* Check if the "answered" discussions are supported for the given account.
50+
*
51+
* GitHub Cloud or GitHub Enterprise Server 3.12 or newer is required to support this feature.
52+
*/
53+
export function isAnsweredDiscussionFeatureSupported(
54+
account: Account,
55+
): boolean {
56+
if (isEnterpriseServerHost(account.hostname)) {
57+
if (account.version) {
58+
const version = account?.version.split('.').map(Number);
59+
return version[0] >= 3 && version[1] >= 12;
60+
}
61+
62+
return false;
63+
}
64+
65+
return true;
66+
}
67+
4468
export function generateNotificationReferrerId(
4569
notification: Notification,
4670
): string {

0 commit comments

Comments
 (0)