From 0c0ee91f89eff7e323de8eaf3c7c667b77b81f01 Mon Sep 17 00:00:00 2001 From: DevPanther Date: Tue, 5 Mar 2024 13:18:44 +0100 Subject: [PATCH] fix: errors with official type --- .../fetch-and-display-previews.ts | 1 + src/home/fetch-github/fetch-issues-preview.ts | 8 +-- src/home/github-types.ts | 64 +------------------ src/home/rendering/render-github-issues.ts | 21 ++++++ 4 files changed, 28 insertions(+), 66 deletions(-) diff --git a/src/home/fetch-github/fetch-and-display-previews.ts b/src/home/fetch-github/fetch-and-display-previews.ts index db958b7..c2c714c 100644 --- a/src/home/fetch-github/fetch-and-display-previews.ts +++ b/src/home/fetch-github/fetch-and-display-previews.ts @@ -48,6 +48,7 @@ export async function fetchAvatars() { const urlPattern = /https:\/\/github\.com\/(?[^/]+)\/(?[^/]+)\/issues\/(?\d+)/; const avatarPromises = cachedTasks.map(async (task) => { + if (!task.preview.body) return; const match = task.preview.body.match(urlPattern); const orgName = match?.groups?.org; if (orgName) { diff --git a/src/home/fetch-github/fetch-issues-preview.ts b/src/home/fetch-github/fetch-issues-preview.ts index 78ad89f..5b67d4c 100644 --- a/src/home/fetch-github/fetch-issues-preview.ts +++ b/src/home/fetch-github/fetch-issues-preview.ts @@ -11,12 +11,12 @@ async function checkPrivateRepoAccess(): Promise { try { const response = await octokit.repos.checkCollaborator({ - owner: 'ubiquity', - repo: 'devpool-directory-private', + owner: "ubiquity", + repo: "devpool-directory-private", username, - }) + }); - if(response.status === 204) { + if (response.status === 204) { // If the response is successful, it means the user has access to the private repository return true; } diff --git a/src/home/github-types.ts b/src/home/github-types.ts index 09a3360..11f7276 100644 --- a/src/home/github-types.ts +++ b/src/home/github-types.ts @@ -1,4 +1,5 @@ import { TaskNoState } from "./fetch-github/preview-to-full-mapping"; +import { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods"; export interface GitHubUser { avatar_url: string; bio: string; @@ -54,68 +55,7 @@ export interface GitHubUserResponse { data: GitHubUser; } -interface GitHubLabel { - id: number; - node_id: string; - url: string; - name: string; - description: string; - color: string; - default: boolean; -} - -interface GitHubMilestone { - url: string; - html_url: string; - labels_url: string; - id: number; - node_id: string; - number: number; - state: string; - title: string; - description: string; - creator: GitHubUser; - open_issues: number; - closed_issues: number; - created_at: string; - updated_at: string; - closed_at: string | null; - due_on: string | null; -} - -export interface GitHubIssue { - id: number; - node_id: string; - url: string; - repository_url: string; - labels_url: string; - comments_url: string; - events_url: string; - html_url: string; - number: number; - state: string; - title: string; - body: string; - user: GitHubUser; - labels: GitHubLabel[]; - assignee: GitHubUser | null; - assignees: GitHubUser[]; - milestone: GitHubMilestone | null; - locked: boolean; - active_lock_reason: string | null; - comments: number; - pull_request?: { - url: string; - html_url: string; - diff_url: string; - patch_url: string; - }; - closed_at: string | null; - created_at: string; - updated_at: string; - closed_by?: GitHubUser; - private?: boolean; -} +export type GitHubIssue = RestEndpointMethodTypes["issues"]["get"]["response"]["data"]; export interface AvatarCache { [organization: string]: string | null; diff --git a/src/home/rendering/render-github-issues.ts b/src/home/rendering/render-github-issues.ts index de1584b..4db61d9 100644 --- a/src/home/rendering/render-github-issues.ts +++ b/src/home/rendering/render-github-issues.ts @@ -45,6 +45,10 @@ function everyNewIssue({ taskPreview, container }: { taskPreview: TaskMaybeFull; } const urlPattern = /https:\/\/github\.com\/([^/]+)\/([^/]+)\//; + if (!taskPreview.preview.body) { + console.warn(`No body found for issue ${taskPreview.preview.id}.`); + return; + } const match = taskPreview.preview.body.match(urlPattern); const organizationName = match?.[1]; @@ -112,6 +116,22 @@ function parseAndGenerateLabels(task: TaskMaybeFull) { const { labels, otherLabels } = task.preview.labels.reduce( (acc, label) => { + // check if label is a single string + if (typeof label === "string") { + return { + labels: [], + otherLabels: [], + }; + } + + // check if label.name exists + if (!label.name) { + return { + labels: [], + otherLabels: [], + }; + } + const match = label.name.match(/^(Pricing|Time|Priority): /); if (match) { const name = label.name.replace(match[0], ""); @@ -156,6 +176,7 @@ export function viewIssueDetails(full: GitHubIssue) { // Update the title and body for the new issue titleHeader.textContent = full.title; titleAnchor.href = full.html_url; + if (!full.body) return; previewBodyInner.innerHTML = marked(full.body) as string; // Show the preview