Skip to content
Merged
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
7 changes: 3 additions & 4 deletions src/hooks/useNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getEnterpriseAccountToken,
getTokenForHost,
isEnterpriseHost,
isGitHubLoggedIn,
} from '../utils/helpers';
import {
setTrayIconColor,
Expand Down Expand Up @@ -64,16 +65,14 @@ export const useNotifications = (colors: boolean): NotificationsState => {

const fetchNotifications = useCallback(
async (accounts: AuthState, settings: SettingsState) => {
const isGitHubLoggedIn = accounts.token !== null;

function getNotifications(hostname: string, token: string): AxiosPromise {
const endpointSuffix = `notifications?participating=${settings.participating}`;
const url = `${generateGitHubAPIUrl(hostname)}${endpointSuffix}`;
return apiRequestAuth(url, 'GET', token);
}

function getGitHubNotifications() {
if (!isGitHubLoggedIn) {
if (!isGitHubLoggedIn(accounts)) {
return;
}
return getNotifications(
Expand Down Expand Up @@ -111,7 +110,7 @@ export const useNotifications = (colors: boolean): NotificationsState => {
};
},
);
const data = isGitHubLoggedIn
const data = isGitHubLoggedIn(accounts)
? [
...enterpriseNotifications,
{
Expand Down
10 changes: 10 additions & 0 deletions src/utils/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,19 @@ import {
generateNotificationReferrerId,
getHtmlUrl,
isEnterpriseHost,
isGitHubLoggedIn,
} from './helpers';

describe('utils/helpers.ts', () => {
describe('isGitHubLoggedIn', () => {
it('logged in', () => {
expect(isGitHubLoggedIn({ ...mockAccounts, token: '1234' })).toBe(true);
});

it('logged out', () => {
expect(isGitHubLoggedIn({ ...mockAccounts, token: null })).toBe(false);
});
});
describe('isEnterpriseHost', () => {
it('should return true for enterprise host', () => {
expect(isEnterpriseHost('github.manos.im')).toBe(true);
Expand Down
4 changes: 4 additions & 0 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { openExternalLink } from '../utils/comms';
import { Constants } from './constants';
import { getCheckSuiteAttributes, getWorkflowRunAttributes } from './subject';

export function isGitHubLoggedIn(accounts: AuthState): boolean {
return accounts.token != null;
}

export function getTokenForHost(hostname: string, accounts: AuthState): string {
const isEnterprise = isEnterpriseHost(hostname);
const token = isEnterprise
Expand Down