generated from ubiquity/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from 0x4007/enhancement/cached-issues
Enhancement/cached issues
- Loading branch information
Showing
26 changed files
with
206 additions
and
456 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
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 |
---|---|---|
@@ -1,49 +1,8 @@ | ||
import { Octokit } from "@octokit/rest"; | ||
import { getGitHubAccessToken } from "../getters/get-github-access-token"; | ||
import { GitHubIssue } from "../github-types"; | ||
import { taskWithFullTest } from "./fetch-and-display-previews"; | ||
import { fetchAvatar } from "./fetch-avatar"; | ||
import { TaskMaybeFull, TaskWithFull } from "./preview-to-full-mapping"; | ||
|
||
export const organizationImageCache = new Map<string, Blob | null>(); | ||
|
||
export async function fetchIssuesFull(taskPreviews: TaskMaybeFull[]): Promise<TaskWithFull[]> { | ||
const octokit = new Octokit({ auth: await getGitHubAccessToken() }); | ||
const urlPattern = /https:\/\/github\.com\/(?<org>[^/]+)\/(?<repo>[^/]+)\/issues\/(?<issue_number>\d+)/; | ||
|
||
const fullTaskPromises = taskPreviews.map(async (task) => { | ||
const match = task.preview.body.match(urlPattern); | ||
|
||
if (!match || !match.groups) { | ||
console.error("Invalid issue body URL format"); | ||
return Promise.resolve(null); | ||
} | ||
|
||
const { org, repo, issue_number } = match.groups; | ||
|
||
const { data: response } = await octokit.request("GET /repos/{org}/{repo}/issues/{issue_number}", { issue_number, repo, org }); | ||
|
||
task.full = response as GitHubIssue; | ||
|
||
const urlMatch = task.full.html_url.match(urlPattern); | ||
const orgName = urlMatch?.groups?.org; | ||
if (orgName) { | ||
await fetchAvatar(orgName); | ||
} | ||
const isTaskWithFull = taskWithFullTest(task); | ||
|
||
if (isTaskWithFull) { | ||
return task; | ||
} else { | ||
throw new Error("Task is not a TaskWithFull"); | ||
} | ||
}); | ||
|
||
const settled = await Promise.allSettled(fullTaskPromises); | ||
const fullTasks = settled | ||
.filter((result): result is PromiseFulfilledResult<TaskWithFull> => result.status === "fulfilled") | ||
.map((result) => result.value) | ||
.filter((issue): issue is TaskWithFull => issue !== null); | ||
|
||
return fullTasks; | ||
export async function fetchIssuesFull(): Promise<GitHubIssue[]> { | ||
const response = await fetch("https://raw.githubusercontent.com/ubiquity/devpool-directory/refs/heads/development/devpool-issues.json"); | ||
const jsonData = await response.json(); | ||
return jsonData; | ||
} |
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
Oops, something went wrong.