11import { GitHubPageType } from "../types/GitHubPageType" ;
2- import { fetchMainBranch , fetchPlainCss } from "./FetchData" ;
2+ import { fetchPlainCss , tryFetchFromAllCommonBranches } from "./FetchData" ;
33
44export async function fetchGitHubCss ( ) : Promise < string | null > {
55 let css : string | null = null ;
@@ -25,7 +25,7 @@ export async function fetchGitHubCss(): Promise<string | null> {
2525 return css ;
2626}
2727
28- function getGitHubPageType ( ) : { type : GitHubPageType | null , id : string | null } {
28+ export function getGitHubPageType ( ) : { type : GitHubPageType | null , id : string | null } {
2929 const metaOrganization = document . querySelector ( 'meta[content^="organization:"]' ) ?. getAttribute ( "content" ) ?. split ( ":" ) . pop ( ) || null ;
3030 const metaRepository = document . querySelector ( 'meta[content^="repository:"]' ) ?. getAttribute ( "content" ) ?. split ( ":" ) . pop ( ) || null ;
3131 const metaUser = document . querySelector ( 'meta[name="octolytics-dimension-user_id"]' ) ?. getAttribute ( "content" ) || null ;
@@ -44,8 +44,10 @@ async function getGitHubCssPath(pageType: GitHubPageType): Promise<string | null
4444 const repo = pathSegments [ 1 ] || "" ;
4545
4646 try {
47- let cssPath : string | null = null ;
48- const mainBranch = await fetchMainBranch ( owner , pageType === GitHubPageType . Organization ? ".github" : repo || owner ) ;
47+ let cssPath : string | null ;
48+
49+ // fetching the main branch without auth causes ip wide rate limits pretty quickly, we probably need to cache this or store the css on our end
50+ /*const mainBranch = await fetchMainBranch(owner, pageType === GitHubPageType.Organization ? ".github" : repo || owner);
4951
5052 if (!mainBranch) {
5153 return null;
@@ -61,7 +63,10 @@ async function getGitHubCssPath(pageType: GitHubPageType): Promise<string | null
6163 case GitHubPageType.User:
6264 cssPath = `${basePath}/${owner}/${owner}/${mainBranch}/user.css`;
6365 break;
64- }
66+ }*/
67+
68+ // temporary "fix"
69+ cssPath = await tryFetchFromAllCommonBranches ( basePath , pageType , owner , repo ) ;
6570
6671 return cssPath ;
6772 } catch ( error ) {
0 commit comments