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
3 changes: 1 addition & 2 deletions src/renderer/stores/useAccountsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type { Account, Forge, Hostname, Token } from '../types';
import type { AuthMethod } from '../utils/auth/types';
import type { AccountsState, AccountsStore } from './types';

import { resolvePlatform } from '../utils/auth/platform';
import { getAccountUUID, isValidHostname, refreshAccount } from '../utils/auth/utils';
import { rendererLogInfo, rendererLogWarn } from '../utils/core/logger';
import { getAdapter, isKnownForge } from '../utils/forges/registry';
Expand Down Expand Up @@ -64,7 +63,7 @@ const useAccountsStore = create<AccountsStore>()(
forge,
hostname: hostname,
method: method,
platform: resolvePlatform(forge, hostname),
platform: getAdapter(forge).getPlatform(hostname),
token: encryptedToken,
username,
user: null, // Will be updated during the refresh call below
Expand Down
79 changes: 0 additions & 79 deletions src/renderer/utils/auth/platform.test.ts

This file was deleted.

40 changes: 0 additions & 40 deletions src/renderer/utils/auth/platform.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/renderer/utils/forges/bitbucket/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const bitbucketAdapter: ForgeAdapter = {
icon: BitbucketIcon,
capabilities,

getPlatform: () => 'Bitbucket Cloud',
formatUserLogin: (login) => login,

fetchAuthenticatedUser,
Expand Down
1 change: 1 addition & 0 deletions src/renderer/utils/forges/gitea/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const giteaAdapter: ForgeAdapter = {
icon: ServerIcon,
capabilities,

getPlatform: () => 'Gitea',
formatUserLogin: (login) => `@${login}`,

fetchAuthenticatedUser,
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/utils/forges/github/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
} from './flows';
import { createNotificationHandler } from './handlers';
import { clearOctokitClientCacheForAccount, createOctokitClient } from './octokit';
import { getGitHubPlatform } from './platform';
import { transformNotifications } from './transform';

async function fetchAuthenticatedUser(account: Account): Promise<RefreshAccountData> {
Expand Down Expand Up @@ -80,6 +81,7 @@ export const githubAdapter: ForgeAdapter = {
icon: MarkGithubIcon,
capabilities: githubCapabilities,

getPlatform: getGitHubPlatform,
formatUserLogin: (login) => `@${login}`,

fetchAuthenticatedUser,
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/utils/forges/github/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { Constants } from '../../../constants';

import type { Account, ClientID, Hostname, Link, Token } from '../../../types';

import { getPlatformFromHostname } from '../../auth/platform';
import { getRecommendedScopeNames } from '../../auth/scopes';
import { getGitHubPlatform } from './platform';

/**
* Normalize a GitHub Enterprise Server version string to a semver string.
Expand Down Expand Up @@ -39,7 +39,7 @@ export function extractHostVersion(version: string | null): string | undefined {
* @returns The base URL to use for OAuth API requests.
*/
export function getGitHubAuthBaseUrl(hostname: Hostname): URL {
const platform = getPlatformFromHostname(hostname);
const platform = getGitHubPlatform(hostname);
const url = new URL(APPLICATION.GITHUB_BASE_URL);

switch (platform) {
Expand Down
25 changes: 24 additions & 1 deletion src/renderer/utils/forges/github/capabilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import {
mockGitHubEnterpriseServerAccount,
} from '../../../__mocks__/account-mocks';

import { githubCapabilities, supportsAnsweredDiscussion } from './capabilities';
import {
githubCapabilities,
supportsAnsweredDiscussion,
supportsStackedPullRequests,
} from './capabilities';

describe('renderer/utils/forges/github/capabilities.ts', () => {
describe('markAsDone', () => {
Expand Down Expand Up @@ -71,4 +75,23 @@ describe('renderer/utils/forges/github/capabilities.ts', () => {
).toBe(false);
});
});

describe('supportsStackedPullRequests', () => {
it('returns true for GitHub Cloud', () => {
expect(supportsStackedPullRequests(mockGitHubCloudAccount)).toBe(true);
});

it('returns false for GitHub Enterprise Server', () => {
expect(supportsStackedPullRequests(mockGitHubEnterpriseServerAccount)).toBe(false);
});

it('returns false when the GHES version is unknown', () => {
expect(
supportsStackedPullRequests({
...mockGitHubEnterpriseServerAccount,
version: undefined,
}),
).toBe(false);
});
});
});
19 changes: 16 additions & 3 deletions src/renderer/utils/forges/github/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import semver from 'semver';
import type { Account } from '../../../types';
import type { ForgeCapabilities } from '../types';

import { isEnterpriseServerHost } from '../../auth/platform';
import { isGitHubCloudHost, isGitHubEnterpriseServerHost } from './platform';

/**
* GitHub feature capabilities exposed through the forge adapter contract.
Expand All @@ -14,7 +14,7 @@ import { isEnterpriseServerHost } from '../../auth/platform';
*/
export const githubCapabilities: ForgeCapabilities = {
markAsDone(account: Account): boolean {
if (!isEnterpriseServerHost(account.hostname)) {
if (!isGitHubEnterpriseServerHost(account.hostname)) {
return true;
}
if (account.version) {
Expand All @@ -36,11 +36,24 @@ export const githubCapabilities: ForgeCapabilities = {
* GHES exposed `isAnswered` from version 3.12 onwards.
*/
export function supportsAnsweredDiscussion(account: Account): boolean {
if (!isEnterpriseServerHost(account.hostname)) {
if (!isGitHubEnterpriseServerHost(account.hostname)) {
return true;
}
if (account.version) {
return semver.gte(account.version, '3.12.0');
}
return false;
}

/**
* GitHub-only capability: whether the GraphQL `PullRequest` schema exposes the
* native `stackEntry` field used for stacked PR metrics. Lives outside the
* shared `ForgeCapabilities` because no other forge supports stacked PRs and
* the only consumer is the GitHub GraphQL query construction in `client.ts`.
*
* Stacked PRs are a GitHub Cloud feature and are not available on GitHub
* Enterprise Server.
*/
export function supportsStackedPullRequests(account: Account): boolean {
return isGitHubCloudHost(account.hostname);
}
2 changes: 2 additions & 0 deletions src/renderer/utils/forges/github/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ describe('renderer/utils/forges/github/client.ts', () => {
firstLabels: Constants.GRAPHQL_ARGS.FIRST_LABELS,
lastComments: Constants.GRAPHQL_ARGS.LAST_COMMENTS,
lastReviews: Constants.GRAPHQL_ARGS.LAST_REVIEWS,
includeStackEntry: true,
},
);
});
Expand Down Expand Up @@ -440,6 +441,7 @@ describe('renderer/utils/forges/github/client.ts', () => {
firstClosingIssues: 100,
firstLabels: 100,
includeIsAnswered: true,
includeStackEntry: true,
isDiscussionNotification0: false,
isDiscussionNotification1: false,
isIssueNotification0: true,
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/utils/forges/github/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
} from './types';

import { reportServerPollInterval } from '../../notifications/pollInterval';
import { supportsAnsweredDiscussion } from './capabilities';
import { supportsAnsweredDiscussion, supportsStackedPullRequests } from './capabilities';
import {
FetchDiscussionByNumberDocument,
type FetchDiscussionByNumberQuery,
Expand Down Expand Up @@ -250,6 +250,7 @@ export async function fetchPullByNumber(
firstLabels: Constants.GRAPHQL_ARGS.FIRST_LABELS,
lastComments: Constants.GRAPHQL_ARGS.LAST_COMMENTS,
lastReviews: Constants.GRAPHQL_ARGS.LAST_REVIEWS,
includeStackEntry: supportsStackedPullRequests(notification.account),
});
} /**
* Fetch notification details for supported types (ie: Discussions, Issues and Pull Requests).
Expand Down Expand Up @@ -297,6 +298,7 @@ export async function fetchNotificationDetailsForList(

builder.setSharedVariables({
includeIsAnswered: supportsAnsweredDiscussion(notifications[0].account),
includeStackEntry: supportsStackedPullRequests(notifications[0].account),
firstClosingIssues: Constants.GRAPHQL_ARGS.FIRST_CLOSING_ISSUES,
firstLabels: Constants.GRAPHQL_ARGS.FIRST_LABELS,
lastComments: Constants.GRAPHQL_ARGS.LAST_COMMENTS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('renderer/utils/forges/github/graphql/MergeQueryBuilder.ts', () => {
firstLabels: 10,
firstClosingIssues: 8,
includeIsAnswered: true,
includeStackEntry: true,
};

const nodeVarsA: FetchBatchMergedTemplateIndexedBaseVariables = {
Expand Down Expand Up @@ -51,6 +52,7 @@ describe('renderer/utils/forges/github/graphql/MergeQueryBuilder.ts', () => {
expect(query).toContain('$firstLabels: Int');
expect(query).toContain('$firstClosingIssues: Int');
expect(query).toContain('$includeIsAnswered: Boolean!');
expect(query).toContain('$includeStackEntry: Boolean!');

expect(query).toContain('$owner0: String!');
expect(query).toContain('$name0: String!');
Expand Down Expand Up @@ -82,6 +84,7 @@ describe('renderer/utils/forges/github/graphql/MergeQueryBuilder.ts', () => {
firstLabels: 10,
firstClosingIssues: 8,
includeIsAnswered: true,
includeStackEntry: true,
owner0: 'octocat',
name0: 'hello-world',
number0: 123,
Expand Down
Loading