Skip to content

Commit b959da2

Browse files
committed
feat: login with github app
Signed-off-by: Adam Setch <[email protected]>
1 parent c06a8ee commit b959da2

File tree

3 files changed

+81
-8
lines changed

3 files changed

+81
-8
lines changed

src/routes/Accounts.test.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,27 @@ describe('routes/Accounts.tsx', () => {
238238
});
239239

240240
describe('Add new accounts', () => {
241+
it('should show login with github app', async () => {
242+
await act(async () => {
243+
render(
244+
<AppContext.Provider
245+
value={{
246+
auth: { accounts: [mockOAuthAccount] },
247+
settings: mockSettings,
248+
}}
249+
>
250+
<MemoryRouter>
251+
<AccountsRoute />
252+
</MemoryRouter>
253+
</AppContext.Provider>,
254+
);
255+
});
256+
257+
expect(screen.getByTitle('Login with GitHub App').hidden).toBe(false);
258+
259+
fireEvent.click(screen.getByTitle('Login with GitHub App'));
260+
});
261+
241262
it('should show login with personal access token', async () => {
242263
await act(async () => {
243264
render(

src/routes/Accounts.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
FeedPersonIcon,
33
KeyIcon,
4+
MarkGithubIcon,
45
PersonIcon,
56
PlusIcon,
67
SignOutIcon,
@@ -9,6 +10,7 @@ import {
910
SyncIcon,
1011
} from '@primer/octicons-react';
1112

13+
import log from 'electron-log';
1214
import { type FC, useCallback, useContext } from 'react';
1315
import { useNavigate } from 'react-router-dom';
1416
import { Header } from '../components/Header';
@@ -29,7 +31,8 @@ import {
2931
import { saveState } from '../utils/storage';
3032

3133
export const AccountsRoute: FC = () => {
32-
const { auth, settings, logoutFromAccount } = useContext(AppContext);
34+
const { auth, settings, loginWithGitHubApp, logoutFromAccount } =
35+
useContext(AppContext);
3336
const navigate = useNavigate();
3437

3538
const logoutAccount = useCallback(
@@ -48,6 +51,14 @@ export const AccountsRoute: FC = () => {
4851
navigate('/accounts', { replace: true });
4952
}, []);
5053

54+
const loginWithGitHub = useCallback(async () => {
55+
try {
56+
await loginWithGitHubApp();
57+
} catch (err) {
58+
log.error('Auth: failed to login with GitHub', err);
59+
}
60+
}, []);
61+
5162
const loginWithPersonalAccessToken = useCallback(() => {
5263
return navigate('/login-personal-access-token', { replace: true });
5364
}, []);
@@ -97,7 +108,7 @@ export const AccountsRoute: FC = () => {
97108
onClick={() => openHost(account.hostname)}
98109
>
99110
<PlatformIcon type={account.platform} size={Size.XSMALL} />
100-
{account.platform} - {account.hostname}
111+
{account.hostname}
101112
</button>
102113
</div>
103114
<div>
@@ -172,6 +183,18 @@ export const AccountsRoute: FC = () => {
172183
<div className="flex items-center justify-between bg-gray-200 px-8 py-1 text-sm dark:bg-gray-darker">
173184
<div className="font-semibold italic">Add new account</div>
174185
<div>
186+
<button
187+
type="button"
188+
className={BUTTON_CLASS_NAME}
189+
title="Login with GitHub App"
190+
onClick={loginWithGitHub}
191+
>
192+
<MarkGithubIcon
193+
size={Size.LARGE}
194+
aria-label="Login with GitHub App"
195+
/>
196+
<PlusIcon size={Size.SMALL} className="mb-2 ml-1" />
197+
</button>
175198
<button
176199
type="button"
177200
className={BUTTON_CLASS_NAME}

src/routes/__snapshots__/Accounts.test.tsx.snap

Lines changed: 35 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)