@@ -10,31 +10,28 @@ export interface CommitInfo {
1010 committer : CommitterInfo ;
1111}
1212
13- const token = process . env . GITHUB_TOKEN ;
14-
15- const options : RequestInit = token
13+ export const GITHUB_OPTIONS : RequestInit = process . env . GITHUB_TOKEN
1614 ? {
1715 headers : {
1816 Accept : "application/vnd.github+json" ,
19- "User-Agent" : "papermc- docs/author " ,
20- Authorization : `Bearer ${ token } ` ,
17+ "User-Agent" : "PaperMC/ docs (https://docs.papermc.io) " ,
18+ Authorization : `Bearer ${ process . env . GITHUB_TOKEN } ` ,
2119 } ,
2220 }
2321 : {
2422 headers : {
2523 Accept : "application/vnd.github+json" ,
26- "User-Agent" : "papermc- docs/author " ,
24+ "User-Agent" : "PaperMC/ docs (https://docs.papermc.io) " ,
2725 } ,
2826 } ;
2927
3028export const REPO = "PaperMC/docs" ;
3129const cache = new Map < string , CommitterInfo > ( ) ;
3230
3331export const getCommitInfo = async ( filePath : string ) : Promise < CommitInfo | null > => {
34- let email : string , hash : string ;
32+ let hash : string , email : string , name : string ;
3533 try {
36- email = execSync ( `git log -1 --pretty="format:%ae" -- "${ filePath } "` ) . toString ( ) ;
37- hash = execSync ( `git log -1 --pretty="format:%H" -- "${ filePath } "` ) . toString ( ) ;
34+ [ hash , email , name ] = execSync ( `git log -1 --format="%H,%ae,%an" -- "${ filePath } "` ) . toString ( ) . trim ( ) . split ( "," , 3 ) ;
3835 } catch ( e ) {
3936 return null ;
4037 }
@@ -44,16 +41,9 @@ export const getCommitInfo = async (filePath: string): Promise<CommitInfo | null
4441 return { hash, committer : cached } ;
4542 }
4643
47- let name : string ;
48- try {
49- name = execSync ( `git log -1 --pretty="format:%an" -- "${ filePath } "` ) . toString ( ) ;
50- } catch ( e ) {
51- return null ;
52- }
53-
5444 const info : CommitterInfo = { name, href : `mailto:${ email } ` } ;
5545
56- const res = await fetch ( `https://api.github.com/repos/${ REPO } /commits/${ hash } ` , options ) ;
46+ const res = await fetch ( `https://api.github.com/repos/${ REPO } /commits/${ hash } ` , GITHUB_OPTIONS ) ;
5747 if ( res . ok ) {
5848 const commit = await res . json ( ) ;
5949 info . href = commit . author . html_url ;
0 commit comments