-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move note fetching from gitnews to octokit in main process
- Loading branch information
1 parent
573d759
commit e3a1f08
Showing
6 changed files
with
120 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { AccountInfo, Note, NoteReason } from '../../shared-types'; | ||
import { Octokit } from '@octokit/rest'; | ||
|
||
export async function fetchNotificationsForAccount( | ||
account: AccountInfo | ||
): Promise<Note[]> { | ||
const octokit = new Octokit({ | ||
auth: account.apiKey, | ||
baseUrl: account.serverUrl, | ||
userAgent: 'gitnews-menubar', | ||
}); | ||
const notifications = | ||
await octokit.rest.activity.listNotificationsForAuthenticatedUser({ | ||
all: false, | ||
}); | ||
return notifications.data.map((notification) => { | ||
return { | ||
id: notification.id, | ||
title: notification.subject.title, | ||
unread: notification.unread, | ||
repositoryFullName: notification.repository.full_name, | ||
commentUrl: notification.subject.latest_comment_url, | ||
updatedAt: notification.updated_at, | ||
repositoryName: notification.repository.name, | ||
type: notification.subject.type, | ||
subjectUrl: notification.subject.url, | ||
commentAvatar: notification.repository.owner.avatar_url, // FIXME I think this comes from the commentUrl | ||
repositoryOwnerAvatar: notification.repository.owner.avatar_url, | ||
api: { | ||
subject: { state: undefined, merged: undefined }, // FIXME I think this comes from the subjectUrl | ||
notification: { reason: notification.reason as NoteReason }, | ||
}, | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
export type NoteReason = | ||
| 'assign' | ||
| 'author' | ||
| 'ci_activity' | ||
| 'comment' | ||
| 'manual' | ||
| 'mention' | ||
| 'push' | ||
| 'review_requested' | ||
| 'security_alert' | ||
| 'state_change' | ||
| 'subscribed' | ||
| 'team_mention' | ||
| 'your_activity'; | ||
|
||
export interface NoteApi { | ||
subject?: { state?: string; merged?: boolean }; | ||
notification?: { reason?: NoteReason }; | ||
} | ||
|
||
export interface Note { | ||
id: string; | ||
title: string; | ||
unread: boolean; | ||
repositoryFullName: string; | ||
gitnewsMarkedUnread?: boolean; | ||
gitnewsSeen?: boolean; | ||
|
||
/** | ||
* Number of milliseconds since the epoc (what Date.now() returns). | ||
*/ | ||
gitnewsSeenAt?: number; | ||
|
||
api: NoteApi; | ||
commentUrl: string; | ||
|
||
/** | ||
* ISO 8601 formatted date string like `2017-08-23T18:20:00Z`. | ||
*/ | ||
updatedAt: string; | ||
|
||
repositoryName: string; | ||
type: string; | ||
subjectUrl: string; | ||
commentAvatar?: string; | ||
repositoryOwnerAvatar?: string; | ||
} | ||
|
||
export interface AccountInfo { | ||
id: string; | ||
apiKey: string; | ||
serverUrl: string; | ||
} |