Skip to content
Draft
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 .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/src/renderer/utils/forges/github/ @afonsojramos @setchy
/src/renderer/utils/forges/gitea/ @afonsojramos @bircni
/src/renderer/utils/forges/gitlab/ @afonsojramos
/src/renderer/utils/forges/gerrit/ @QuentinBtd
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ Gitify supports notifications from multiple Git forges. New forges may be added
- **Capability-honest UI:** features unsupported by a forge (e.g. mark-as-done) must hide gracefully, not silently no-op.
- **No core-platform churn:** Octicons, Octokit, and the Primer Design System remain in place. Octokit is scoped to the GitHub adapter; other adapters use plain `fetch`.

Currently supported forges: **GitHub** (Cloud, Enterprise Server, Enterprise Cloud with Data Residency), **Gitea** (incl. Forgejo, Codeberg), **Bitbucket Cloud** and **GitLab** (Cloud and Self-Managed).
Currently supported forges: **GitHub** (Cloud, Enterprise Server, Enterprise Cloud with Data Residency), **Gitea** (incl. Forgejo, Codeberg), **Bitbucket Cloud**, **GitLab** (Cloud and Self-Managed), and **Gerrit** (3.12 or later recommended; older versions warn in logs but are not blocked).

#### 🚫 Things we won't do

Expand Down
12 changes: 7 additions & 5 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ Gitify is maintained by a small team. Each forge adapter has at least one design

## Forge adapter maintainers

| Forge | Maintainer | Source |
| ------ | -------------------------------------------------------------------------------------- | ----------------------------------- |
| GitHub | [@setchy](https://github.com/setchy), [@afonsojramos](https://github.com/afonsojramos) | `src/renderer/utils/forges/github/` |
| Gitea | [@bircni](https://github.com/bircni), [@afonsojramos](https://github.com/afonsojramos) | `src/renderer/utils/forges/gitea/` |
| GitLab | [@afonsojramos](https://github.com/afonsojramos) | `src/renderer/utils/forges/gitlab/` |
| Forge | Maintainer | Source |
| --------- | -------------------------------------------------------------------------------------- | -------------------------------------- |
| GitHub | [@setchy](https://github.com/setchy), [@afonsojramos](https://github.com/afonsojramos) | `src/renderer/utils/forges/github/` |
| Gitea | [@bircni](https://github.com/bircni), [@afonsojramos](https://github.com/afonsojramos) | `src/renderer/utils/forges/gitea/` |
| GitLab | [@afonsojramos](https://github.com/afonsojramos) | `src/renderer/utils/forges/gitlab/` |
| Bitbucket | [@setchy](https://github.com/setchy) | `src/renderer/utils/forges/bitbucket/` |
| Gerrit | [@QuentinBtd](https://github.com/QuentinBtd) | `src/renderer/utils/forges/gerrit/` |

## Adding a new forge

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
## 📦 Features

- 🔔 Unified notifications from your Git platforms
- ⚒️ Multi-forge: GitHub Cloud, GitHub Enterprise, Gitea, Forgejo, Codeberg, Bitbucket Cloud, GitLab
- ⚒️ Multi-forge: GitHub Cloud, GitHub Enterprise, Gitea, Forgejo, Codeberg, Bitbucket Cloud, GitLab, Gerrit
- 💻 Cross-platform: macOS, Windows, and Linux
- 🎨 Customizable settings, filters and themes
- 🖥️ Tray/menu bar integration
Expand All @@ -31,7 +31,7 @@ Gitify uses a forge adapter pattern so notifications can come from any compatibl
| **Bitbucket** Cloud | ✅ | ✅ | ✅ | — | — | — |
| **GitLab** Cloud & Self-Managed | ✅ | ✅ | ✅ | ✅ | — | ✅ |
| **Azure DevOps** | 💭 | — | — | — | — | — |
| **Gerrit** | 💭 | — | — | — | — | — |
| **Gerrit** | ✅ | ✅ | ✅ | — | — | — |

<details>
<summary><strong>Status legend</strong></summary>
Expand All @@ -49,6 +49,8 @@ Gitify uses a forge adapter pattern so notifications can come from any compatibl
> [!NOTE]
> _A new forge needs an [adapter](src/renderer/utils/forges/) plus a designated maintainer. See [our contributing guide](CONTRIBUTING.md#multi-forge-support) for the full policy._

Gerrit 3.12 or later is recommended. Older detected versions produce a log warning but can still sign in; compatibility is not guaranteed. Unknown versions are also allowed.

## 🚀 Quick Start

1. **Download** Gitify for free from [gitify.io][website].
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"electron",
"electron-menubar",
"forgejo",
"gerrit",
"gitea",
"github",
"gitify",
Expand Down
1 change: 1 addition & 0 deletions src/__helpers__/gitify-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function createGitifyBridgeApi(platform: TestPlatform = 'macos'): Window[
decryptValue: vi.fn().mockResolvedValue({ token: 'decrypted' }),
encryptValue: vi.fn().mockResolvedValue('encrypted'),
githubCliToken: vi.fn().mockResolvedValue({ token: 'gh-cli-token' }),
gerritRequest: vi.fn(),
setWindowVibrancy: vi.fn().mockResolvedValue(undefined),
setNativeTheme: vi.fn().mockResolvedValue(undefined),
platform: {
Expand Down
53 changes: 53 additions & 0 deletions src/main/handlers/gerrit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { net } from 'electron';

import type { IGerritRequest } from '../../shared/events';

import { gerritRequest } from './gerrit';

vi.mock('electron', () => ({
ipcMain: { handle: vi.fn() },
net: { fetch: vi.fn() },
}));

const request: IGerritRequest = {
url: 'https://gerrit.example.com/a/changes/proj~1/attention/self/delete',
method: 'POST',
authorization: 'Basic abc',
body: '{"reason":"x"}',
};

describe('main/handlers/gerrit.ts', () => {
beforeEach(() => {
vi.mocked(net.fetch).mockReset();
});

it('sends the request with Basic auth, JSON body and no redirects', async () => {
vi.mocked(net.fetch).mockResolvedValueOnce(
new Response(")]}'\n{}", { status: 200, statusText: 'OK' }),
);

const result = await gerritRequest(request);

expect(result).toEqual({ status: 200, statusText: 'OK', body: ")]}'\n{}" });
expect(net.fetch).toHaveBeenCalledWith(request.url, {
method: 'POST',
headers: {
Accept: 'application/json',
Authorization: 'Basic abc',
'Content-Type': 'application/json; charset=UTF-8',
},
body: request.body,
redirect: 'error',
});
});

it.each([
['plain http', { url: 'http://gerrit.example.com/a/changes/' }],
['a path outside the /a/ API', { url: 'https://example.com/anything' }],
['an unsupported method', { method: 'DELETE' as IGerritRequest['method'] }],
['non-Basic credentials', { authorization: 'Bearer abc' }],
])('refuses %s without sending it', async (_, override) => {
await expect(gerritRequest({ ...request, ...override })).rejects.toThrow(/Refusing/);
expect(net.fetch).not.toHaveBeenCalled();
});
});
54 changes: 54 additions & 0 deletions src/main/handlers/gerrit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { net } from 'electron';

import type { IGerritRequest, IGerritResponse } from '../../shared/events';
import { EVENTS } from '../../shared/events';

import { handleMainEvent } from '../events';

/**
* Only Gerrit's authenticated REST API (`https://<host>/a/...`) with HTTP
* Basic credentials is proxied, so this cannot become a general-purpose fetch.
* The renderer validates the host against the signed-in account.
*/
export function assertGerritRequest(request: IGerritRequest): URL {
const url = new URL(request.url);
if (url.protocol !== 'https:' || !url.pathname.startsWith('/a/')) {
throw new Error('Refusing non-Gerrit API request.');
}
if (request.method !== 'GET' && request.method !== 'POST') {
throw new Error('Refusing unsupported Gerrit request method.');
}
if (!request.authorization.startsWith('Basic ')) {
throw new Error('Refusing Gerrit request without Basic credentials.');
}
return url;
}

export async function gerritRequest(request: IGerritRequest): Promise<IGerritResponse> {
const url = assertGerritRequest(request);
const headers: Record<string, string> = {
Accept: 'application/json',
Authorization: request.authorization,
};
if (request.body !== undefined) {
headers['Content-Type'] = 'application/json; charset=UTF-8';
}

const response = await net.fetch(url.toString(), {
method: request.method,
headers,
body: request.body,
// Never replay credentials to wherever a redirect points.
redirect: 'error',
});

return {
status: response.status,
statusText: response.statusText,
body: await response.text(),
};
}

export function registerGerritHandlers(): void {
handleMainEvent(EVENTS.GERRIT_REQUEST, (_, request) => gerritRequest(request));
}
1 change: 1 addition & 0 deletions src/main/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './app';
export * from './gerrit';
export * from './github-cli';
export * from './native-notifications';
export * from './storage';
Expand Down
1 change: 1 addition & 0 deletions src/main/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ vi.mock('./config', () => ({
vi.mock('./handlers', () => ({
registerAppHandlers: vi.fn(),
registerGitHubCliHandlers: vi.fn(),
registerGerritHandlers: vi.fn(),
registerNativeNotificationHandlers: vi.fn(),
registerStorageHandlers: vi.fn(),
registerSystemHandlers: vi.fn(),
Expand Down
2 changes: 2 additions & 0 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { logError, toError } from '../shared/logger';
import { Paths, WindowConfig } from './config';
import {
registerAppHandlers,
registerGerritHandlers,
registerGitHubCliHandlers,
registerNativeNotificationHandlers,
registerStorageHandlers,
Expand Down Expand Up @@ -78,6 +79,7 @@ app
registerSystemHandlers(mb);
registerStorageHandlers();
registerGitHubCliHandlers();
registerGerritHandlers();
registerAppHandlers(mb);
registerUpdaterHandlers(appUpdater);
})
Expand Down
9 changes: 9 additions & 0 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { contextBridge, webFrame } from 'electron';

import type {
IGerritRequest,
IKeyboardShortcut,
INativeNotificationActionEvent,
INativeNotificationClickEvent,
Expand Down Expand Up @@ -61,6 +62,14 @@ export const api = {
*/
githubCliToken: (hostname: string) => invokeMainEvent(EVENTS.GITHUB_CLI_TOKEN, hostname),

/**
* Run an authenticated Gerrit REST call from the main process (avoids CORS).
*
* @param request - The `/a/` API URL, method, Basic auth header and optional JSON body.
* @returns The response status and raw body text.
*/
gerritRequest: (request: IGerritRequest) => invokeMainEvent(EVENTS.GERRIT_REQUEST, request),

/**
* Enable or disable launching the application at system login.
*
Expand Down
11 changes: 11 additions & 0 deletions src/renderer/__mocks__/account-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ export const mockBitbucketAccount: Account = {
user: mockGitifyUser,
};

export const mockGerritAccount: Account = {
forge: 'gerrit',
platform: 'Gerrit',
method: 'Personal Access Token',
token: 'token-gerrit' as Token,
hostname: 'gerrit.example.com' as Hostname,
username: 'jdoe',
user: { ...mockGitifyUser, login: 'jdoe' },
version: '3.12.0',
};

export function mockAccountWithError(error: GitifyError): AccountNotifications {
return {
account: mockGitHubCloudAccount,
Expand Down
7 changes: 7 additions & 0 deletions src/renderer/__mocks__/notifications-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from '../types';

import {
mockGerritAccount,
mockGiteaAccount,
mockGitifyOAuthAppAccount,
mockGitHubCloudAccount,
Expand Down Expand Up @@ -306,6 +307,12 @@ export const mockGiteaGitifyNotification: GitifyNotification = {
account: mockGiteaAccount,
};

/** Same shape as cloud notification, but bound to a Gerrit account. */
export const mockGerritGitifyNotification: GitifyNotification = {
...mockGitifyNotification,
account: mockGerritAccount,
};

export const mockMultipleAccountNotifications: AccountNotifications[] = [
{
account: mockGitHubCloudAccount,
Expand Down
14 changes: 13 additions & 1 deletion src/renderer/components/Sidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { navigateMock, renderWithProviders } from '../__helpers__/test-utils';
import { mockGitHubCloudAccount } from '../__mocks__/account-mocks';
import { mockGerritAccount, mockGitHubCloudAccount } from '../__mocks__/account-mocks';
import { mockSettings } from '../__mocks__/state-mocks';

import { APPLICATION } from '../../shared/constants';
Expand Down Expand Up @@ -338,4 +338,16 @@ describe('renderer/components/Sidebar.tsx', () => {
expect(quitAppSpy).toHaveBeenCalledTimes(1);
});
// Keyboard bindings moved to App.test.tsx
it('opens Gerrit changes and hides the unsupported issues link', async () => {
renderWithProviders(<Sidebar />, { accounts: [mockGerritAccount] });
expect(screen.queryByRole('button', { name: /^My issues/ })).not.toBeInTheDocument();
await userEvent.click(screen.getByRole('button', { name: /^My pull requests/ }));
expect(openExternalLinkSpy).toHaveBeenLastCalledWith(
'https://gerrit.example.com/q/status:open+owner:jdoe',
);
await userEvent.click(screen.getByRole('button', { name: /^Notifications/ }));
expect(openExternalLinkSpy).toHaveBeenLastCalledWith(
'https://gerrit.example.com/q/attention:jdoe',
);
});
});
20 changes: 11 additions & 9 deletions src/renderer/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,17 @@ export function Sidebar() {
variant={hasFilters ? 'primary' : 'invisible'}
/>

<IconButton
aria-label={t('sidebar.my_issues', 'My issues ↗')}
icon={IssueOpenedIcon}
keybindingHint={shortcuts.myIssues.key}
onClick={() => shortcuts.myIssues.action()}
size="small"
tooltipDirection="e"
variant="invisible"
/>
{shortcuts.myIssues.isAllowed && (
<IconButton
aria-label={t('sidebar.my_issues', 'My issues ↗')}
icon={IssueOpenedIcon}
keybindingHint={shortcuts.myIssues.key}
onClick={() => shortcuts.myIssues.action()}
size="small"
tooltipDirection="e"
variant="invisible"
/>
)}

<IconButton
aria-label={t('sidebar.my_pull_requests', 'My pull requests ↗')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export interface LoginWithPersonalAccessTokenFormProps {
showUsernameField?: boolean;
usernamePlaceholder?: string;
usernameCaption?: string;
usernameLabel?: string;
usernameInputType?: 'email' | 'text';
/** Forge-specific content rendered below the token settings row (e.g. scope hints). */
children?: ReactNode;
}
Expand All @@ -76,6 +78,8 @@ export function LoginWithPersonalAccessTokenForm({
showUsernameField = false,
usernamePlaceholder = '',
usernameCaption = '',
usernameLabel,
usernameInputType = 'text',
children,
}: Readonly<LoginWithPersonalAccessTokenFormProps>) {
const { t } = useTranslation();
Expand Down Expand Up @@ -170,7 +174,7 @@ export function LoginWithPersonalAccessTokenForm({
{showUsernameField && (
<FormControl id="login-username" required>
<FormControl.Label>
{t('login.pat.atlassian_email', 'Atlassian Email')}
{usernameLabel ?? t('login.pat.username', 'Username')}
</FormControl.Label>
{usernameCaption && (
<FormControl.Caption>
Expand All @@ -179,11 +183,12 @@ export function LoginWithPersonalAccessTokenForm({
)}
<TextInput
aria-invalid={errors.username ? 'true' : 'false'}
autoComplete={usernameInputType === 'email' ? 'email' : 'username'}
block
name="username"
onChange={handleInputChange}
placeholder={usernamePlaceholder}
type="email"
type={usernameInputType}
value={formData.username ?? ''}
/>
{errors.username && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { renderWithProviders } from '../../__helpers__/test-utils';
import { mockGitHubCloudAccount } from '../../__mocks__/account-mocks';
import { mockGerritAccount, mockGitHubCloudAccount } from '../../__mocks__/account-mocks';

import * as links from '../../utils/system/links';
import { AccountHeader, type AccountHeaderProps } from './AccountHeader';
Expand Down Expand Up @@ -58,6 +58,13 @@ describe('renderer/components/notifications/AccountHeader.tsx', () => {
expect(openHostIssuesSpy).toHaveBeenCalledWith(mockGitHubCloudAccount);
});

it('hides issues for Gerrit while retaining the account and changes links', () => {
renderWithProviders(<AccountHeader {...props} account={mockGerritAccount} />);
expect(screen.queryByTestId('account-issues')).not.toBeInTheDocument();
expect(screen.getByTestId('account-profile')).toBeInTheDocument();
expect(screen.getByTestId('account-pull-requests')).toBeInTheDocument();
});

it('opens my pull requests when clicked', async () => {
const openHostPullsSpy = vi.spyOn(links, 'openHostPulls').mockImplementation(vi.fn());

Expand Down
Loading
Loading