Skip to content

Commit

Permalink
fix: errors with official type
Browse files Browse the repository at this point in the history
  • Loading branch information
devpanther committed Mar 5, 2024
1 parent 6f21593 commit 0c0ee91
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 66 deletions.
1 change: 1 addition & 0 deletions src/home/fetch-github/fetch-and-display-previews.ts
Expand Up @@ -48,6 +48,7 @@ export async function fetchAvatars() {
const urlPattern = /https:\/\/github\.com\/(?<org>[^/]+)\/(?<repo>[^/]+)\/issues\/(?<issue_number>\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) {
Expand Down
8 changes: 4 additions & 4 deletions src/home/fetch-github/fetch-issues-preview.ts
Expand Up @@ -11,12 +11,12 @@ async function checkPrivateRepoAccess(): Promise<boolean> {

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;
}
Expand Down
64 changes: 2 additions & 62 deletions 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;
Expand Down Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions src/home/rendering/render-github-issues.ts
Expand Up @@ -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];

Expand Down Expand Up @@ -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], "");
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0c0ee91

Please sign in to comment.