Skip to content

Commit

Permalink
Add subject data to notes
Browse files Browse the repository at this point in the history
  • Loading branch information
sirbrillig committed Sep 8, 2024
1 parent 852aa71 commit 4def101
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/main/lib/github-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ export async function fetchNotificationsForAccount(

for (const notification of notificationsResponse.data) {
let commentAvatar;

let commentHtmlUrl;
if (notification.subject.latest_comment_url) {
try {
const commentUrl = new URL(notification.subject.latest_comment_url);
const commentUrlPath = commentUrl.pathname;
const comment = await octokit.request(`GET ${commentUrlPath}`, {});
commentAvatar = comment.data.user.avatar_url;
commentHtmlUrl = comment.data.html_url;
} catch (error) {
console.error(
`Failed to fetch comment for ${notification.subject.latest_comment_url}`
Expand All @@ -34,20 +35,40 @@ export async function fetchNotificationsForAccount(
}
}

let noteState;
let noteMerged;
let subjectHtmlUrl;
if (notification.subject.url) {
try {
const subjectUrl = new URL(notification.subject.url);
const subjectUrlPath = subjectUrl.pathname;
const subject = await octokit.request(`GET ${subjectUrlPath}`, {});
noteState = subject.data.state;
noteMerged = subject.data.merged;
subjectHtmlUrl = subject.data.html_url;
} catch (error) {
console.error(
`Failed to fetch subject for ${notification.subject.url}`
);
// This might fail but it's not that important so we will ignore it if
// that happens.
}
}

notes.push({
id: notification.id,
title: notification.subject.title,
unread: notification.unread,
repositoryFullName: notification.repository.full_name,
commentUrl: notification.subject.latest_comment_url,
commentUrl: commentHtmlUrl,
updatedAt: notification.updated_at,
repositoryName: notification.repository.name,
type: notification.subject.type,
subjectUrl: notification.subject.url,
subjectUrl: subjectHtmlUrl,
commentAvatar: commentAvatar ?? notification.repository.owner.avatar_url,
repositoryOwnerAvatar: notification.repository.owner.avatar_url,
api: {
subject: { state: undefined, merged: undefined }, // FIXME I think this comes from the subjectUrl
subject: { state: noteState, merged: noteMerged },
notification: { reason: notification.reason as NoteReason },
},
});
Expand Down

0 comments on commit 4def101

Please sign in to comment.