3030 } ) ;
3131 return elem ;
3232 }
33-
33+
3434
3535 function main ( url ) {
3636 while ( root . firstChild ) {
3737 root . removeChild ( root . firstChild ) ;
3838 }
3939
4040 fetchJSON ( HYF_REPOS_URL , ( err , data ) => {
41- let newArray = [ ] ;
41+ if ( err ) {
42+ createAndAppend ( 'div' , root , { text : err . message , class : 'alert-error' } ) ;
43+ }
44+ const newArray = [ ] ;
4245 let forkArray = [ ] ;
4346 let languageArray = [ ] ;
4447 let descriptionArray = [ ] ;
8992 } //end removeNodes
9093
9194 selectList . onchange = function ( selectedIndex ) {
92- let RepoName = createAndAppend ( 'li' , ul , { text : "Repository: " , class : 'nameInContainer' , function : removeNodes ( ) } ) ;
93- createAndAppend ( 'a' , RepoName , { text : newArray [ this . selectedIndex ] , id : 'linkInContainer' , target : "_blank" , href : htmlArray [ this . selectedIndex ] } ) ;
95+ let repoName = createAndAppend ( 'li' , ul , { text : "Repository: " , class : 'nameInContainer' , function : removeNodes ( ) } ) ;
96+ createAndAppend ( 'a' , repoName , { text : newArray [ this . selectedIndex ] , id : 'linkInContainer' , target : "_blank" , href : htmlArray [ this . selectedIndex ] } ) ;
9497 createAndAppend ( 'li' , ul , { text : "Description: " + descriptionArray [ this . selectedIndex ] , class : 'descriptionInContainer' } ) ;
9598 createAndAppend ( 'li' , ul , { text : "Number of Forks: " + forkArray [ this . selectedIndex ] , class : 'forksInContainer' } ) ;
9699 createAndAppend ( 'li' , ul , { text : "Language: " + languageArray [ this . selectedIndex ] , class : 'languageInContainer' } ) ;
97100 createAndAppend ( 'li' , ul , { text : "Updated at: " + updatedAt [ this . selectedIndex ] , id : 'updatedAtInContainer' } )
98- createAndAppend ( 'li' , contributorsUl , { text : contributorsArray [ this . selectedIndex ] , class : 'contributorsInContainer' } ) ;
99- }
100- } ) ;
101+ fetchJSON ( 'https://api.github.com/repos/HackYourFuture/' + newArray [ this . selectedIndex ] + '/contributors' , ( err , data ) => {
102+ let getName = [ ] ;
103+ let getLink = [ ] ;
104+ let getBadge = [ ] ;
105+ for ( let i = 0 ; i < data . length ; i ++ ) {
106+ getName . push ( data [ i ] . avatar_url ) ;
107+ getLink . push ( data [ i ] . html_url ) ;
108+ getBadge . push ( data [ i ] . contributions ) ;
109+
110+ let imageLink = createAndAppend ( 'li' , contributorsUl , { } )
111+ let contributorName = createAndAppend ( 'img' , imageLink , { src : data [ i ] . avatar_url } ) ;
112+ let contributorLink = createAndAppend ( 'a' , imageLink , { text : "click here to go to this contributor " , target : "_blank" , href : data [ i ] . html_url , id : 'link' } ) ;
113+ let contributorBadge = createAndAppend ( 'li' , imageLink , { text :"Contributions: " + data [ i ] . contributions , class : 'badge' } ) ;
114+ } //end for
115+ data . forEach ( ( repo ) => {
116+ } ) ; //end for each
117+ } ) ; //end fetchJSON
118+
119+ } // end of onchange
120+ } ) ; //end of Fetch
121+
122+
101123
102- /*
103- fetchJSON( theContributors_URL, (err, data) => {
104- let theContributorsUrl = [];
105- for (let i = 0; i < data.length; i++){
106- }
107- });*/
124+
108125 }
109126
110127 const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100' ;
111- const theContributors_URL = 'https://api.github.com/repos/HackYourFuture/contributors' ;
112128 window . onload = ( ) => main ( HYF_REPOS_URL ) ;
113- window . onload = ( ) => main ( theContributors_URL ) ;
129+
114130}
0 commit comments