@@ -74,41 +74,44 @@ const octokit = new Octokit({
7474 auth : ESLINT_GITHUB_TOKEN ,
7575} ) ;
7676
77- async function fetchUserProfile ( username ) {
78- // check cache first
79- if ( users . has ( username ) ) {
80- return users . get ( username ) ;
77+ function fetchUserProfile ( username ) {
78+ async function doFetch ( ) {
79+ const { data : profile } = await octokit . users . getByUsername ( {
80+ username,
81+ } ) ;
82+ const { data : social } = await octokit . request (
83+ "GET /users/{username}/social_accounts" ,
84+ { username } ,
85+ ) ;
86+ const avatarURL = `https://avatars.githubusercontent.com/u/${ profile . id } ` ;
87+
88+ return {
89+ username : profile . login ,
90+ name : profile . name ,
91+ title : "Guest Author" ,
92+ // eslint-disable-next-line no-nested-ternary -- add https if missing
93+ website : profile . blog . match ( / h t t p ( s ) ? : \/ \/ / u)
94+ ? profile . blog
95+ : profile . blog
96+ ? `https://${ profile . blog } `
97+ : profile . blog ,
98+ avatar_url : avatarURL ,
99+ bio : profile . bio ,
100+ twitter_username : profile . twitter_username ,
101+ github_username : profile . login ,
102+ mastodon_url : social . find (
103+ account => account . provider === "mastodon" ,
104+ ) ?. url ,
105+ location : profile . location ,
106+ } ;
81107 }
82108
83- const { data : profile } = await octokit . users . getByUsername ( { username } ) ;
84- const { data : social } = await octokit . request (
85- "GET /users/{username}/social_accounts" ,
86- { username } ,
87- ) ;
88- const avatarURL = `https://avatars.githubusercontent.com/u/${ profile . id } ` ;
89-
90- const result = {
91- username : profile . login ,
92- name : profile . name ,
93- title : "Guest Author" ,
94- // eslint-disable-next-line no-nested-ternary -- add https if missing
95- website : profile . blog . match ( / h t t p ( s ) ? : \/ \/ / u)
96- ? profile . blog
97- : profile . blog
98- ? `https://${ profile . blog } `
99- : profile . blog ,
100- avatar_url : avatarURL ,
101- bio : profile . bio ,
102- twitter_username : profile . twitter_username ,
103- github_username : profile . login ,
104- mastodon_url : social . find ( account => account . provider === "mastodon" )
105- ?. url ,
106- location : profile . location ,
107- } ;
109+ // Immediately store Promise in the cache to avoid race conditions
110+ if ( ! users . has ( username ) ) {
111+ users . set ( username , doFetch ( ) ) ;
112+ }
108113
109- // cache the result
110- users . set ( username , result ) ;
111- return result ;
114+ return users . get ( username ) ;
112115}
113116
114117async function fetchTeamMembers ( ) {
0 commit comments