@@ -25,33 +25,30 @@ const headers: RequestInit =
2525 } ;
2626
2727const repo : string = "PaperMC/docs" ;
28- const cache : Map < string , GitHubAccount > = new Map ( ) ;
28+ const emailCache : Map < string , GitHubAccount > = new Map ( ) ;
2929
3030// Git
3131export async function getGitHubAccountFromFile ( filePath : string ) : Promise < GitHubAccount | null > {
32- const displayName = execSync ( `git log -1 --pretty="format:%an" -- "${ filePath } "` ) . toString ( ) ;
3332 const email = execSync ( `git log -1 --pretty="format:%ae" -- "${ filePath } "` ) . toString ( ) ;
34-
35- const cached = cache . get ( email ) ;
33+ const cached = emailCache . get ( email ) ;
3634 if ( cached != null ) {
37- cached . displayName = displayName ;
3835 return cached ;
3936 }
4037
38+ const displayName = execSync ( `git log -1 --pretty="format:%an" -- "${ filePath } "` ) . toString ( ) ;
39+ const hash = execSync ( `git log -1 --pretty="format:%H" -- "${ filePath } "` ) . toString ( ) ;
40+
4141 // As the email seems to not be directly linked to an account, we instead use the GitHub API
42- const url = new URL ( `https://api.github.com/repos/${ repo } /commits` ) ;
43- url . searchParams . set ( "path" , filePath ) ;
42+ const url = new URL ( `https://api.github.com/repos/${ repo } /commits/${ hash } ` ) ;
4443 url . searchParams . set ( "per_page" , "1" ) ;
4544
46- // It is **KNOWN** that if a commit is not pushed to GitHub, the link will be of the person who last edited the page remotely.
47- // This is only a bug in local dev or other branch environments, and not in production.
48- const commit = ( await fetch ( url , headers ) . then ( ( response ) => response . json ( ) ) ) [ 0 ] ;
45+ let commit = await fetch ( url , headers ) . then ( ( response ) => response . json ( ) ) ;
4946 let acc : GitHubAccount = {
50- displayName : displayName ,
47+ displayName : commit . commit ?. author ?. name ?? displayName ,
5148 email : email ,
5249 accountLink : commit ?. author ?. html_url ,
5350 } ;
5451
55- cache . set ( email , acc ) ;
52+ emailCache . set ( email , acc ) ;
5653 return acc ;
5754}
0 commit comments