Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix fetch failures #5

Merged
merged 7 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/witty-singers-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ryanatkn/fuz": patch
---

fix fetch failures
3 changes: 2 additions & 1 deletion src/lib/deployments.json
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,9 @@
"npm_url": "https://www.npmjs.com/package/@ryanatkn/fuz",
"changelog_url": "https://github.com/ryanatkn/fuz/blob/main/CHANGELOG.md",
"published": true,
"check_runs": {"status": "in_progress", "conclusion": null},
"check_runs": {"status": "completed", "conclusion": "success"},
"pull_requests": [
{"number": 5, "title": "fix fetch failures", "user": {"login": "ryanatkn"}, "draft": false},
{"number": 1, "title": "add colors to buttons", "user": {"login": "ryanatkn"}, "draft": true}
]
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {parse_package_meta} from '$lib/package_meta.js';
import type {Fetched_Deployment, Deployment, Unfetched_Deployment} from '$lib/fetch_deployments.js';

export interface Deployments {
deployment: Fetched_Deployment; // TODO this type is wrong because it may not be fetched, but should it even be here?
deployment: Fetched_Deployment;
deployments: Fetched_Deployment[];
unfetched_deployments: Unfetched_Deployment[];
}
Expand Down
96 changes: 53 additions & 43 deletions src/lib/fetch_deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
fetch_github_check_runs,
fetch_github_pull_requests,
Github_Check_Runs_Item,
Github_Pull_Requests,
type Github_Pull_Request,
} from '$lib/github.js';

Expand All @@ -32,7 +33,7 @@ export interface Unfetched_Deployment {

/* eslint-disable no-await-in-loop */

// TODO probably refactor to an object API
// TODO this is all very hacky
export const fetch_deployments = async (
homepage_urls: Url[],
token?: string,
Expand All @@ -57,70 +58,79 @@ export const fetch_deployments = async (
const deployments: Deployment[] = [];
for (const raw_homepage_url of homepage_urls) {
const homepage_url = ensure_end(raw_homepage_url, '/');
try {
let package_json: Package_Json;
let src_json: Src_Json;

// Handle the local package data, if available
if (homepage_url === local_homepage_url) {
log?.info('resolving data locally for', homepage_url);
package_json = local_package_json;
src_json = await create_src_json(
local_package_json,
log,
dir ? join(dir, 'src/lib') : undefined,
);
} else {
log?.info('fetching data for', homepage_url);

// `${base}/.well-known/package.json`
const fetched_package_json = await fetch_package_json(homepage_url, cache, log);
if (!fetched_package_json) throw Error('failed to load package_json: ' + homepage_url);
package_json = fetched_package_json;
await wait(delay);

// `${base}/.well-known/src.json`
const fetched_src_json = await fetch_src_json(homepage_url, cache, log);
if (!fetched_src_json) throw Error('failed to load src_json: ' + homepage_url);
src_json = fetched_src_json;
await wait(delay);
}
let package_json: Package_Json | null;
let src_json: Src_Json | null;
let pkg: Package_Meta | null;
let check_runs: Github_Check_Runs_Item | null;
let pull_requests: Github_Pull_Requests | null;

// Handle the local package data, if available
if (homepage_url === local_homepage_url) {
log?.info('resolving data locally for', homepage_url);
package_json = local_package_json;

src_json = await create_src_json(
local_package_json,
log,
dir ? join(dir, 'src/lib') : undefined,
);
if (!src_json) log?.error('failed to fetch src_json: ' + homepage_url);
} else {
// Fetch the remote package data
log?.info('fetching data for', homepage_url);

await wait(delay);
package_json = await fetch_package_json(homepage_url, cache, log);
if (!package_json) log?.error('failed to load package_json: ' + homepage_url);

const pkg = parse_package_meta(homepage_url, package_json, src_json);
await wait(delay);
src_json = await fetch_src_json(homepage_url, cache, log);
if (!src_json) log?.error('failed to load src_json: ' + homepage_url);
}

if (package_json && src_json) {
try {
pkg = parse_package_meta(homepage_url, package_json, src_json);
} catch (err) {
pkg = null;
log?.error('failed to parse package meta: ' + err);
}
} else {
pkg = null;
}

if (pkg) {
// CI status
const check_runs = await fetch_github_check_runs(
await wait(delay);
check_runs = await fetch_github_check_runs(
pkg,
cache,
log,
token,
github_api_version,
github_refs?.[raw_homepage_url],
);
if (!check_runs) throw Error('failed to fetch CI status: ' + homepage_url);
await wait(delay);
if (!check_runs) log?.error('failed to fetch CI status: ' + homepage_url);

// pull requests
const pull_requests = await fetch_github_pull_requests(
pkg,
cache,
log,
token,
github_api_version,
);
if (!pull_requests) throw Error('failed to fetch issues: ' + homepage_url);
await wait(delay);
pull_requests = await fetch_github_pull_requests(pkg, cache, log, token, github_api_version);
if (!pull_requests) log?.error('failed to fetch issues: ' + homepage_url);
} else {
check_runs = null;
pull_requests = null;
}

if (pkg) {
deployments.push({...pkg, check_runs, pull_requests});
} catch (err) {
} else {
deployments.push({
url: homepage_url,
package_json: null,
src_json: null,
check_runs: null,
pull_requests: null,
});
log?.error(err);
}
}
return deployments;
Expand Down
2 changes: 0 additions & 2 deletions src/lib/package_meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ export const parse_package_meta = (
): Package_Meta => {
const {name} = package_json;

// TODO think through with other presentations - Details, Summary, Card

// TODO hacky
const parse_repo = (r: string | null | undefined) => {
if (!r) return null;
Expand Down
Loading