Skip to content

refactor: octokit openapi types #1626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 package.json
Original file line number Diff line number Diff line change
@@ -139,6 +139,7 @@
"@biomejs/biome": "1.9.4",
"@discordapp/twemoji": "15.1.0",
"@electron/notarize": "2.5.0",
"@octokit/openapi-types": "22.2.0",
"@primer/octicons-react": "19.12.0",
"@testing-library/react": "16.0.1",
"@types/jest": "29.5.14",
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

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

8 changes: 5 additions & 3 deletions src/renderer/components/RepositoryNotifications.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { CheckIcon, MarkGithubIcon, ReadIcon } from '@primer/octicons-react';
import { type FC, type MouseEvent, useContext, useState } from 'react';
import { AppContext } from '../context/App';
import { Opacity, Size } from '../types';
import { type Link, Opacity, Size } from '../types';
import type { Notification } from '../typesGitHub';
import { cn } from '../utils/cn';
import { openExternalLink } from '../utils/comms';
import {
getChevronDetails,
isMarkAsDoneFeatureSupported,
} from '../utils/helpers';
import { openRepository } from '../utils/links';
import { HoverGroup } from './HoverGroup';
import { NotificationRow } from './NotificationRow';
import { InteractionButton } from './buttons/InteractionButton';
@@ -67,7 +67,9 @@ export const RepositoryNotifications: FC<IRepositoryNotifications> = ({
onClick={(event: MouseEvent<HTMLElement>) => {
// Don't trigger onClick of parent element.
event.stopPropagation();
openRepository(repoNotifications[0].repository);
openExternalLink(
repoNotifications[0].repository.html_url as Link,
);
}}
>
{repoName}
6 changes: 3 additions & 3 deletions src/renderer/components/notification/NotificationHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { MarkGithubIcon } from '@primer/octicons-react';
import { type FC, type MouseEvent, useContext } from 'react';
import { AppContext } from '../../context/App';
import { Opacity, Size } from '../../types';
import { type Link, Opacity, Size } from '../../types';
import type { Notification } from '../../typesGitHub';
import { cn } from '../../utils/cn';
import { openRepository } from '../../utils/links';
import { openExternalLink } from '../../utils/comms';
import { AvatarIcon } from '../icons/AvatarIcon';

interface INotificationHeader {
@@ -43,7 +43,7 @@ export const NotificationHeader: FC<INotificationHeader> = ({
onClick={(event: MouseEvent<HTMLElement>) => {
// Don't trigger onClick of parent element.
event.stopPropagation();
openRepository(notification.repository);
openExternalLink(notification.repository.html_url as Link);
}}
>
{repoSlug}
498 changes: 91 additions & 407 deletions src/renderer/typesGitHub.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/renderer/utils/api/__mocks__/response-mocks.ts
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ export const mockNotificationUser: User = {
id: 123456789,
node_id: 'MDQ6VXNlcjE=',
avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4' as Link,
gravatar_url: '' as Link,
gravatar_id: '',
url: 'https://api.github.com/users/octocat' as Link,
html_url: 'https://github.com/octocat' as Link,
followers_url: 'https://api.github.com/users/octocat/followers' as Link,
4 changes: 2 additions & 2 deletions src/renderer/utils/auth/utils.ts
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ export async function getUserData(
id: response.id,
login: response.login,
name: response.name,
avatar: response.avatar_url,
avatar: response.avatar_url as Link,
};
}

@@ -162,7 +162,7 @@ export async function refreshAccount(account: Account): Promise<Account> {
id: res.data.id,
login: res.data.login,
name: res.data.name,
avatar: res.data.avatar_url,
avatar: res.data.avatar_url as Link,
};

// Refresh platform version
16 changes: 2 additions & 14 deletions src/renderer/utils/links.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { partialMockUser } from '../__mocks__/partial-mocks';
import { mockGitHubCloudAccount } from '../__mocks__/state-mocks';
import type { Hostname, Link } from '../types';
import type { Repository } from '../typesGitHub';
import { mockSingleNotification } from './api/__mocks__/response-mocks';
import * as authUtils from './auth/utils';
import * as comms from './comms';
@@ -17,7 +16,6 @@
openGitifyReleaseNotes,
openHost,
openNotification,
openRepository,
openUserProfile,
} from './links';

@@ -67,7 +65,7 @@

it('openUserProfile', () => {
const mockUser = partialMockUser('mock-user');
openUserProfile(mockUser);

Check failure on line 68 in src/renderer/utils/links.test.ts

GitHub Actions / Run Tests

Argument of type '{ name?: string; email?: string; login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; ... 8 more ...; starred_at?: string; }' is not assignable to parameter of type 'SubjectUser'.
expect(openExternalLinkMock).toHaveBeenCalledWith(
'https://github.com/mock-user',
);
@@ -88,19 +86,9 @@
expect(openExternalLinkMock).toHaveBeenCalledWith(mockSettingsURL);
});

it('openRepository', () => {
const mockHtmlUrl = 'https://github.com/gitify-app/gitify';

const repo = {
html_url: mockHtmlUrl,
} as Repository;

openRepository(repo);
expect(openExternalLinkMock).toHaveBeenCalledWith(mockHtmlUrl);
});

it('openNotification', async () => {
const mockNotificationUrl = mockSingleNotification.repository.html_url;
const mockNotificationUrl = mockSingleNotification.repository
.html_url as Link;
jest
.spyOn(helpers, 'generateGitHubWebUrl')
.mockResolvedValue(mockNotificationUrl);
6 changes: 1 addition & 5 deletions src/renderer/utils/links.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Account, Hostname, Link } from '../types';
import type { Notification, Repository, SubjectUser } from '../typesGitHub';
import type { Notification, SubjectUser } from '../typesGitHub';
import { getDeveloperSettingsURL } from './auth/utils';
import { openExternalLink } from './comms';
import { Constants } from './constants';
@@ -48,10 +48,6 @@ export function openDeveloperSettings(account: Account) {
openExternalLink(url);
}

export function openRepository(repository: Repository) {
openExternalLink(repository.html_url);
}

export async function openNotification(notification: Notification) {
const url = await generateGitHubWebUrl(notification);
openExternalLink(url);
13 changes: 8 additions & 5 deletions src/renderer/utils/subject.ts
Original file line number Diff line number Diff line change
@@ -10,9 +10,12 @@
Notification,
PullRequest,
PullRequestReview,
PullRequestReviewState,
PullRequestStateType,
StateType,
SubjectUser,
User,
UserType,
WorkflowRunAttributes,
} from '../typesGitHub';
import {
@@ -224,10 +227,10 @@

return {
number: issue.number,
state: issue.state_reason ?? issue.state,
state: issue.state_reason ?? (issue.state as StateType),
user: getSubjectUser([issueCommentUser, issue.user]),
comments: issue.comments,
labels: issue.labels?.map((label) => label.name) ?? [],

Check failure on line 233 in src/renderer/utils/subject.ts

GitHub Actions / Run Tests

Property 'name' does not exist on type 'string | { id?: number; node_id?: string; url?: string; name?: string; description?: string; color?: string; default?: boolean; }'.
milestone: issue.milestone,
};
}
@@ -313,7 +316,7 @@

if (!reviewerFound) {
reviewers.push({
state: prReview.state,
state: prReview.state as PullRequestReviewState,
users: [prReview.user.login],
});
} else {
@@ -421,9 +424,9 @@
if (user) {
subjectUser = {
login: user.login,
html_url: user.html_url,
avatar_url: user.avatar_url,
type: user.type,
html_url: user.html_url as Link,
avatar_url: user.avatar_url as Link,
type: user.type as UserType,
};

return subjectUser;