Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/renderer/__mocks__/state-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const mockGitHubCloudAccount: Account = {
token: 'token-123-456' as Token,
hostname: Constants.DEFAULT_AUTH_OPTIONS.hostname,
user: mockGitifyUser,
version: 'latest',
};

export const mockGitHubEnterpriseServerAccount: Account = {
Expand Down
24 changes: 24 additions & 0 deletions src/renderer/utils/auth/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,30 @@ describe('renderer/utils/auth/utils.ts', () => {
});
});

it('extractHostVersion', () => {
expect(auth.extractHostVersion(null)).toBe('latest');

expect(auth.extractHostVersion('foo')).toBe(null);

expect(auth.extractHostVersion('3')).toBe('3.0.0');

expect(auth.extractHostVersion('3.15')).toBe('3.15.0');

expect(auth.extractHostVersion('3.15.0')).toBe('3.15.0');

expect(auth.extractHostVersion('3.15.0-beta1')).toBe('3.15.0');

expect(auth.extractHostVersion('enterprise-server@3')).toBe('3.0.0');

expect(auth.extractHostVersion('enterprise-server@3.15')).toBe('3.15.0');

expect(auth.extractHostVersion('enterprise-server@3.15.0')).toBe('3.15.0');

expect(auth.extractHostVersion('enterprise-server@3.15.0-beta1')).toBe(
'3.15.0',
);
});

it('getDeveloperSettingsURL', () => {
expect(
auth.getDeveloperSettingsURL({
Expand Down
14 changes: 12 additions & 2 deletions src/renderer/utils/auth/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BrowserWindow } from '@electron/remote';
import { format } from 'date-fns';
import log from 'electron-log';
import semver from 'semver';
import type {
Account,
AuthCode,
Expand Down Expand Up @@ -165,15 +166,24 @@ export async function refreshAccount(account: Account): Promise<Account> {
avatar: res.data.avatar_url,
};

// Refresh platform version
account.version = res.headers['x-github-enterprise-version'] ?? 'latest';
account.version = extractHostVersion(
res.headers['x-github-enterprise-version'],
);
} catch (error) {
log.error('Failed to refresh account', error);
}

return account;
}

export function extractHostVersion(version: string | null): string {
if (version) {
return semver.valid(semver.coerce(version));
}

return 'latest';
}

export function getDeveloperSettingsURL(account: Account): Link {
const settingsURL = new URL(`https://${account.hostname}`);

Expand Down
22 changes: 2 additions & 20 deletions src/renderer/utils/features.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,12 @@ describe('renderer/utils/features.ts', () => {
it('should return true for GitHub Enterprise Server >= v3.13', () => {
const account = {
...mockGitHubEnterpriseServerAccount,
version: '3.13.3',
version: '3.13.0',
};

expect(isMarkAsDoneFeatureSupported(account)).toBe(true);
});

it('should return false for GitHub Enterprise Server when partial version available', () => {
const account = {
...mockGitHubEnterpriseServerAccount,
version: '3',
};

expect(isMarkAsDoneFeatureSupported(account)).toBe(false);
});

it('should return false for GitHub Enterprise Server when no version available', () => {
const account = {
...mockGitHubEnterpriseServerAccount,
Expand Down Expand Up @@ -70,21 +61,12 @@ describe('renderer/utils/features.ts', () => {
it('should return true for GitHub Enterprise Server >= v3.12', () => {
const account = {
...mockGitHubEnterpriseServerAccount,
version: '3.12.3',
version: '3.12.0',
};

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,
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/utils/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { isEnterpriseServerHost } from './helpers';
export function isMarkAsDoneFeatureSupported(account: Account): boolean {
if (isEnterpriseServerHost(account.hostname)) {
if (account.version) {
return semver.gte(semver.coerce(account.version), '3.13.0');
return semver.gte(account.version, '3.13.0');
}

return false;
Expand All @@ -30,7 +30,7 @@ export function isAnsweredDiscussionFeatureSupported(
): boolean {
if (isEnterpriseServerHost(account.hostname)) {
if (account.version) {
return semver.gte(semver.coerce(account.version), '3.12.0');
return semver.gte(account.version, '3.12.0');
}

return false;
Expand Down
Loading