From 6857222c56605564e145e02b99e88320287eb9b4 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Thu, 6 Feb 2025 16:01:24 -0500 Subject: [PATCH 1/2] fix: issues identified by sonar Signed-off-by: Adam Setch --- src/renderer/components/fields/Checkbox.tsx | 4 ++-- src/renderer/components/metrics/MetricPill.tsx | 4 +++- src/renderer/utils/auth/utils.test.ts | 4 +++- src/renderer/utils/auth/utils.ts | 4 +++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/renderer/components/fields/Checkbox.tsx b/src/renderer/components/fields/Checkbox.tsx index c532e97ec..578904836 100644 --- a/src/renderer/components/fields/Checkbox.tsx +++ b/src/renderer/components/fields/Checkbox.tsx @@ -54,11 +54,11 @@ export const Checkbox: FC = ({ )} - {counter && ( + {counter ? ( {counter} - )} + ) : null} ) ); diff --git a/src/renderer/components/metrics/MetricPill.tsx b/src/renderer/components/metrics/MetricPill.tsx index 9719565fb..1840c51a3 100644 --- a/src/renderer/components/metrics/MetricPill.tsx +++ b/src/renderer/components/metrics/MetricPill.tsx @@ -23,7 +23,9 @@ export const MetricPill: FC = (props: IMetricPill) => { > - {props.metric && {props.metric}} + {props.metric ? ( + {props.metric} + ) : null} ); diff --git a/src/renderer/utils/auth/utils.test.ts b/src/renderer/utils/auth/utils.test.ts index b17ed3c11..9e38b5ff6 100644 --- a/src/renderer/utils/auth/utils.test.ts +++ b/src/renderer/utils/auth/utils.test.ts @@ -101,7 +101,9 @@ describe('renderer/utils/auth/utils.ts', () => { }); await expect(async () => await auth.authGitHub()).rejects.toEqual( - "Oops! Something went wrong and we couldn't log you in using GitHub. Please try again. Reason: The redirect_uri is missing or invalid. Docs: https://docs.github.com/en/developers/apps/troubleshooting-oauth-errors", + new Error( + "Oops! Something went wrong and we couldn't log you in using GitHub. Please try again. Reason: The redirect_uri is missing or invalid. Docs: https://docs.github.com/en/developers/apps/troubleshooting-oauth-errors", + ), ); expect(openExternalLinkMock).toHaveBeenCalledTimes(1); diff --git a/src/renderer/utils/auth/utils.ts b/src/renderer/utils/auth/utils.ts index d75d6c2ad..061bb80f3 100644 --- a/src/renderer/utils/auth/utils.ts +++ b/src/renderer/utils/auth/utils.ts @@ -54,7 +54,9 @@ export function authGitHub( }); } else if (error) { reject( - `Oops! Something went wrong and we couldn't log you in using GitHub. Please try again. Reason: ${errorDescription} Docs: ${errorUri}`, + new Error( + `Oops! Something went wrong and we couldn't log you in using GitHub. Please try again. Reason: ${errorDescription} Docs: ${errorUri}`, + ), ); } }; From 6d57078908984a578936c4280791b5860a285767 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Thu, 6 Feb 2025 16:19:34 -0500 Subject: [PATCH 2/2] fix: issues identified by sonar Signed-off-by: Adam Setch --- src/renderer/components/avatars/AvatarWithFallback.tsx | 7 ++----- src/renderer/components/notifications/NotificationRow.tsx | 5 +++-- src/renderer/typesGitHub.ts | 2 +- src/renderer/utils/auth/utils.ts | 4 +--- src/renderer/utils/constants.ts | 3 +-- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/renderer/components/avatars/AvatarWithFallback.tsx b/src/renderer/components/avatars/AvatarWithFallback.tsx index 476d71d74..93a51ae02 100644 --- a/src/renderer/components/avatars/AvatarWithFallback.tsx +++ b/src/renderer/components/avatars/AvatarWithFallback.tsx @@ -26,6 +26,7 @@ export const AvatarWithFallback: React.FC = ({ const [isBroken, setIsBroken] = useState(false); const isNonHuman = isNonHumanUser(userType); + const DefaultUserIcon = isNonHuman ? MarkGithubIcon : FeedPersonIcon; // TODO explore using AnchoredOverlay component (https://primer.style/components/anchored-overlay/react/alpha) to render Avatar Card on hover return ( @@ -36,11 +37,7 @@ export const AvatarWithFallback: React.FC = ({ data-testid="avatar" > {!src || isBroken ? ( - isNonHuman ? ( - - ) : ( - - ) + ) : ( = ({ ? `#${notification.subject.number}` : ''; - const notificationTitle = - `${notification.subject.title} ${notificationNumber && `[${notificationNumber}]`}`.trim(); + const notificationTitle = notificationNumber + ? `${notification.subject.title} [${notificationNumber}]` + : notification.subject.title; const groupByDate = settings.groupBy === GroupBy.DATE; diff --git a/src/renderer/typesGitHub.ts b/src/renderer/typesGitHub.ts index f2da59075..d38ff2c27 100644 --- a/src/renderer/typesGitHub.ts +++ b/src/renderer/typesGitHub.ts @@ -94,7 +94,7 @@ export type PullRequestReviewAuthorAssociation = | 'NONE' | 'OWNER'; -// TODO: Add explicit types for GitHub API response vs Gitify Notifications object +// TODO: #828 Add explicit types for GitHub API response vs Gitify Notifications object export type Notification = GitHubNotification & GitifyNotification; export interface GitHubNotification { diff --git a/src/renderer/utils/auth/utils.ts b/src/renderer/utils/auth/utils.ts index 061bb80f3..9fcc79714 100644 --- a/src/renderer/utils/auth/utils.ts +++ b/src/renderer/utils/auth/utils.ts @@ -259,9 +259,7 @@ export function getNewOAuthAppURL(hostname: Hostname): Link { } export function isValidHostname(hostname: Hostname) { - return /^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$/i.test( - hostname, - ); + return /^([A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}$/i.test(hostname); } export function isValidClientId(clientId: ClientID) { diff --git a/src/renderer/utils/constants.ts b/src/renderer/utils/constants.ts index 79e9d10d8..afaee132a 100644 --- a/src/renderer/utils/constants.ts +++ b/src/renderer/utils/constants.ts @@ -1,5 +1,4 @@ -import type { Link } from '../types'; -import type { ClientID, ClientSecret, Hostname } from '../types'; +import type { ClientID, ClientSecret, Hostname, Link } from '../types'; export const Constants = { REPO_SLUG: 'gitify-app/gitify',