hypertrons / hypertrons-crx

A browser extension for insights into GitHub, Gitee projects and developers.
https://hypercrx.cn
Apache License 2.0
357 stars 102 forks source link

[Refactor] a strategy to cache configuration in .github/hypertrons.json #402

Closed tyn1998 closed 1 year ago

tyn1998 commented 2 years ago

Description

image

.github/hypertrons.json is a configuration file for Hypercrx. But not all repo has this file (<10), so we get NOT_FOUND after requesting the file. Currently no error handling is involved, which might scare users happen to open devtools to see the console.

And it pollutes the extension error page:

image

tyn1998 commented 2 years ago

Actually there is an error handler already:

https://github.com/hypertrons/hypertrons-crx/blob/4376a1bc3b13c466cb717df6997dad8ca2c908a9/src/api/github.ts#L12-L23

I think the problem is that we should not regard "hypertrons.json NOT FOUND" as an error since only a few repos have this configuration file. Rather, we think it as another normal case.

tyn1998 commented 2 years ago

/self-assign

tyn1998 commented 2 years ago

I have tried:

image

But got:

image

It seems that octokit.request() catchs and handles fetch error so we cannot handle it ourselves. In another word, the red 404 error is inevitable if .github/hypertrons.json doesn't exist :(

I have read GitHub APIs and octokit APIs and found no API to check if a file exist. We must try to get a file to know if it exists.

Since everytime mainInject() runs, this.loadSettings() will try to get .github/hypertrons.json, which is wasteful and unnecessary. Maybe we can refactor it with a strategy that can cache the file existence status to avoid requesting the file repeatedly.

tyn1998 commented 2 years ago

I know how these errors occur when I was tackling this issue:

image

It is necessary to refactor this part of code, I think.

tyn1998 commented 1 year ago

After v1.9.0, features related to hypertrons were removed, so for now hypercrx doesn't fetch .github/hypertrons.json anymore.

This issue is closed.