Skip to content
Open
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: 3 additions & 0 deletions codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const config: CodegenConfig = {
'https://api.github.com/graphql': {
headers: {
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
// Issue fields are exposed behind this feature flag header; without it
// the schema omits `issueFieldValues` and its union types.
'GraphQL-Features': 'issue_fields',
},
// GitHub's live schema currently fails graphql-js's stricter
// interface-deprecation-consistency validation (added in graphql v17).
Expand Down
33 changes: 32 additions & 1 deletion src/renderer/components/metrics/LabelsPill.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { renderWithProviders } from '../../__helpers__/test-utils';
import { LabelsPill, type LabelsPillProps } from './LabelsPill';

describe('renderer/components/metrics/LabelsPill.tsx', () => {
it('renders without labels', () => {
it('renders without labels or issue fields', () => {
const props: LabelsPillProps = { labels: [] };

const tree = renderWithProviders(<LabelsPill {...props} />);
Expand All @@ -23,4 +23,35 @@ describe('renderer/components/metrics/LabelsPill.tsx', () => {

expect(tree.container).toMatchSnapshot();
});

it('renders field tokens when there are no labels', () => {
const props: LabelsPillProps = {
labels: [],
issueFields: [{ name: 'Priority', value: 'High', fillColor: '#cf222e' }],
};

const tree = renderWithProviders(<LabelsPill {...props} />);

expect(tree.getByText('Priority: High')).toBeInTheDocument();
expect(tree.container.innerHTML).toContain('--label-r: 207');
});

it('renders field tokens prepended before labels', () => {
const props: LabelsPillProps = {
labels: [{ name: 'enhancement', color: 'a2eeef' }],
issueFields: [
{ name: 'Priority', value: 'High', fillColor: '#cf222e' },
{ name: 'Effort', value: '5' },
],
};

const tree = renderWithProviders(<LabelsPill {...props} />);
const textContent = tree.container.textContent!;

expect(textContent).toContain('Priority: High');
expect(textContent).toContain('Effort: 5');
expect(textContent).toContain('enhancement');
expect(textContent.indexOf('Priority: High')).toBeLessThan(textContent.indexOf('enhancement'));
expect(textContent.indexOf('Effort: 5')).toBeLessThan(textContent.indexOf('enhancement'));
});
});
49 changes: 32 additions & 17 deletions src/renderer/components/metrics/LabelsPill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,55 @@ import type { FC } from 'react';
import { TagIcon } from '@primer/octicons-react';
import { IssueLabelToken, LabelGroup } from '@primer/react';

import { type GitifyLabels, IconColor } from '../../types';
import { type GitifyIssueField, type GitifyLabels, IconColor } from '../../types';

import { MetricPill } from './MetricPill';

export interface LabelsPillProps {
labels: GitifyLabels[];
issueFields?: GitifyIssueField[];
}

export const LabelsPill: FC<LabelsPillProps> = ({ labels }) => {
if (!labels?.length) {
return null;
}
export const LabelsPill: FC<LabelsPillProps> = ({ labels, issueFields }) => {
const fieldTokens = (issueFields ?? []).map((field) => ({
text: `${field.name}: ${field.value}`,
fillColor: field.fillColor,
}));

const labelsContent = (
<LabelGroup>
{labels.map((label) => {
return (
const labelsContent =
labels?.length || fieldTokens.length ? (
<LabelGroup>
{fieldTokens.map((field) => (
<IssueLabelToken
fillColor={label.color ? `#${label.color}` : undefined}
key={label.name}
fillColor={field.fillColor}
key={field.text}
size="small"
text={label.name}
text={field.text}
/>
);
})}
</LabelGroup>
);
))}
{(labels ?? []).map((label) => {
return (
<IssueLabelToken
fillColor={label.color ? `#${label.color}` : undefined}
key={label.name}
size="small"
text={label.name}
/>
);
})}
</LabelGroup>
) : null;

if (!labelsContent) {
return null;
}

return (
<MetricPill
color={IconColor.GRAY}
contents={labelsContent}
icon={TagIcon}
metric={labels.length}
metric={fieldTokens.length + (labels?.length ?? 0)}
/>
);
};
40 changes: 40 additions & 0 deletions src/renderer/components/metrics/MetricGroup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,44 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => {

expect(tree.getByText('2/3')).toBeInTheDocument();
});

it('should render issue field pills immediately before label pills', async () => {
const props: MetricGroupProps = {
notification: {
...mockGitifyNotification,
subject: {
...mockGitifyNotification.subject,
issueFields: [{ name: 'Priority', value: 'High', fillColor: '#cf222e' }],
labels: [{ name: 'enhancement', color: '0e8a16' }],
},
},
};

const tree = renderWithProviders(<MetricGroup {...props} />, {
settings: { ...mockSettings, showPills: true },
});

const textContent = tree.container.textContent;
expect(textContent).toContain('Priority: High');
expect(textContent).toContain('enhancement');
expect(textContent.indexOf('Priority: High')).toBeLessThan(textContent.indexOf('enhancement'));
});

it('should not render field pills when showPills is disabled', async () => {
const props: MetricGroupProps = {
notification: {
...mockGitifyNotification,
subject: {
...mockGitifyNotification.subject,
issueFields: [{ name: 'Priority', value: 'High', fillColor: '#cf222e' }],
},
},
};

const tree = renderWithProviders(<MetricGroup {...props} />, {
settings: { ...mockSettings, showPills: false },
});

expect(tree.queryByText('Priority: High')).not.toBeInTheDocument();
});
});
5 changes: 4 additions & 1 deletion src/renderer/components/metrics/MetricGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export const MetricGroup: FC<MetricGroupProps> = ({ notification }) => {

<MilestonePill milestone={notification.subject.milestone!} />

<LabelsPill labels={notification.subject.labels ?? []} />
<LabelsPill
labels={notification.subject.labels ?? []}
issueFields={notification.subject.issueFields ?? []}
/>
</div>
);
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/renderer/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const Constants = {
GRAPHQL_ARGS: {
FIRST_LABELS: 100,
FIRST_CLOSING_ISSUES: 100,
FIRST_ISSUE_FIELD_VALUES: 100,
LAST_COMMENTS: 1,
LAST_THREADED_COMMENTS: 10,
LAST_REPLIES: 10,
Expand Down
12 changes: 12 additions & 0 deletions src/renderer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ export interface GitifySubject {
stackDepth?: number;
/** GitHub-native issue type (e.g. Bug, Feature, Task) */
issueType?: GitifyIssueType;
/** GitHub issue fields (e.g. Priority, Effort) with values set */
issueFields?: GitifyIssueField[];
/** Milestone state/title */
milestone?: GitifyMilestone;
/** Deep link to notification thread */
Expand Down Expand Up @@ -483,6 +485,16 @@ export interface GitifyIssueType {
color: IconColor;
}

/** GitHub issue field value, normalized for display */
export interface GitifyIssueField {
/** Field name, e.g. "Priority" */
name: string;
/** Display value, e.g. "High", "5", "2026-09-01" */
value: string;
/** Option fill color when available */
fillColor?: string;
}

export type GitifyMilestone = MilestoneFieldsFragment;

export type GitifyReactionGroup = ReactionGroupFieldsFragment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export function mockIssueResponseNode(mocks: {
comments: { totalCount: 0, nodes: [] },
milestone: null,
issueType: null,
issueFieldValues: null,
reactions: {
totalCount: 0,
},
Expand Down
49 changes: 49 additions & 0 deletions src/renderer/utils/forges/github/capabilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
githubCapabilities,
getGitHubCapabilities,
supportsAnsweredDiscussion,
supportsIssueFields,
supportsStackedPullRequests,
} from './capabilities';

Expand Down Expand Up @@ -96,18 +97,66 @@ describe('renderer/utils/forges/github/capabilities.ts', () => {
});
});

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

it('returns false for GitHub Enterprise Server < v3.23', () => {
expect(
supportsIssueFields({
...mockGitHubEnterpriseServerAccount,
version: '3.22.0',
}),
).toBe(false);
});

it('returns true for GitHub Enterprise Server >= v3.23', () => {
expect(
supportsIssueFields({
...mockGitHubEnterpriseServerAccount,
version: '3.23.0',
}),
).toBe(true);
});

it('returns false when the GHES version is unknown', () => {
expect(
supportsIssueFields({
...mockGitHubEnterpriseServerAccount,
version: undefined,
}),
).toBe(false);
});
});

describe('getGitHubCapabilities', () => {
it('enables all gated capabilities for GitHub Cloud', () => {
expect(getGitHubCapabilities(mockGitHubCloudAccount)).toEqual({
stackedPullRequests: true,
answeredDiscussion: true,
issueFields: true,
});
});

it('disables gated capabilities for GitHub Enterprise Server', () => {
expect(getGitHubCapabilities(mockGitHubEnterpriseServerAccount)).toEqual({
stackedPullRequests: false,
answeredDiscussion: false,
issueFields: false,
});
});

it('enables issueFields for GitHub Enterprise Server >= v3.23', () => {
expect(
getGitHubCapabilities({
...mockGitHubEnterpriseServerAccount,
version: '3.23.0',
}),
).toEqual({
stackedPullRequests: false,
answeredDiscussion: true,
issueFields: true,
});
});
});
Expand Down
22 changes: 22 additions & 0 deletions src/renderer/utils/forges/github/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ export function supportsStackedPullRequests(account: Account): boolean {
return isGitHubCloudHost(account.hostname);
}

/**
* GitHub-only capability: whether the GraphQL `Issue` schema exposes the
* native `issueFieldValues` field used for issue field metrics. Lives outside
* the shared `ForgeCapabilities` because no other forge supports issue fields
* and the only consumer is the GitHub GraphQL query construction in
* `client.ts`.
*
* Issue fields are a GitHub Cloud feature and ship in GitHub Enterprise
* Server from version 3.23 onwards.
*/
export function supportsIssueFields(account: Account): boolean {
if (!isGitHubEnterpriseServerHost(account.hostname)) {
return true;
}
if (account.version) {
return semver.gte(account.version, '3.23.0');
}
return false;
}

/**
* The set of capabilities that gate GraphQL field selections via the custom
* `@gated(requires: ...)` directive. The keys must match the `requires`
Expand All @@ -66,6 +86,7 @@ export function supportsStackedPullRequests(account: Account): boolean {
export type GitHubGatedCapabilities = {
stackedPullRequests: boolean;
answeredDiscussion: boolean;
issueFields: boolean;
};

/**
Expand All @@ -77,5 +98,6 @@ export function getGitHubCapabilities(account: Account): GitHubGatedCapabilities
return {
stackedPullRequests: supportsStackedPullRequests(account),
answeredDiscussion: supportsAnsweredDiscussion(account),
issueFields: supportsIssueFields(account),
};
}
4 changes: 4 additions & 0 deletions src/renderer/utils/forges/github/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ describe('renderer/utils/forges/github/client.ts', () => {
name: mockNotification.repository.name,
number: 123,
firstLabels: Constants.GRAPHQL_ARGS.FIRST_LABELS,
firstIssueFieldValues: Constants.GRAPHQL_ARGS.FIRST_ISSUE_FIELD_VALUES,
lastComments: Constants.GRAPHQL_ARGS.LAST_COMMENTS,
},
);
Expand Down Expand Up @@ -488,6 +489,7 @@ describe('renderer/utils/forges/github/client.ts', () => {
expect.stringMatching(/node0|node1/),
{
firstClosingIssues: 100,
firstIssueFieldValues: 100,
firstLabels: 100,
firstReviewThreads: 100,
isDiscussionNotification0: false,
Expand All @@ -512,6 +514,7 @@ describe('renderer/utils/forges/github/client.ts', () => {
const query = performGraphQLRequestStringSpy.mock.calls[0][1];
expect(query).toContain('stackEntry');
expect(query).toContain('isAnswered');
expect(query).toContain('issueFieldValues');
expect(query).not.toContain('@gated');
});

Expand All @@ -534,6 +537,7 @@ describe('renderer/utils/forges/github/client.ts', () => {
expect(account).toBe(mockGitHubEnterpriseServerAccount);
expect(query).not.toContain('stackEntry');
expect(query).not.toContain('isAnswered');
expect(query).not.toContain('issueFieldValues');
expect(query).not.toContain('@gated');
expect(query).toContain('FetchMergedNotifications');
expect(variables).not.toHaveProperty('includeStackEntry');
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/utils/forges/github/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export async function fetchIssueByNumber(
name: notification.repository.name,
number: number,
firstLabels: Constants.GRAPHQL_ARGS.FIRST_LABELS,
firstIssueFieldValues: Constants.GRAPHQL_ARGS.FIRST_ISSUE_FIELD_VALUES,
lastComments: Constants.GRAPHQL_ARGS.LAST_COMMENTS,
});
}
Expand Down Expand Up @@ -311,6 +312,7 @@ export async function fetchNotificationDetailsForList(
builder.setSharedVariables({
firstClosingIssues: Constants.GRAPHQL_ARGS.FIRST_CLOSING_ISSUES,
firstLabels: Constants.GRAPHQL_ARGS.FIRST_LABELS,
firstIssueFieldValues: Constants.GRAPHQL_ARGS.FIRST_ISSUE_FIELD_VALUES,
lastComments: Constants.GRAPHQL_ARGS.LAST_COMMENTS,
lastThreadedComments: Constants.GRAPHQL_ARGS.LAST_THREADED_COMMENTS,
lastReplies: Constants.GRAPHQL_ARGS.LAST_REPLIES,
Expand Down
Loading