30
30
} ) ;
31
31
return elem ;
32
32
}
33
-
33
+
34
34
35
35
function main ( url ) {
36
36
while ( root . firstChild ) {
37
37
root . removeChild ( root . firstChild ) ;
38
38
}
39
39
40
40
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 = [ ] ;
42
45
let forkArray = [ ] ;
43
46
let languageArray = [ ] ;
44
47
let descriptionArray = [ ] ;
89
92
} //end removeNodes
90
93
91
94
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 ] } ) ;
94
97
createAndAppend ( 'li' , ul , { text : "Description: " + descriptionArray [ this . selectedIndex ] , class : 'descriptionInContainer' } ) ;
95
98
createAndAppend ( 'li' , ul , { text : "Number of Forks: " + forkArray [ this . selectedIndex ] , class : 'forksInContainer' } ) ;
96
99
createAndAppend ( 'li' , ul , { text : "Language: " + languageArray [ this . selectedIndex ] , class : 'languageInContainer' } ) ;
97
100
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
+
101
123
102
- /*
103
- fetchJSON( theContributors_URL, (err, data) => {
104
- let theContributorsUrl = [];
105
- for (let i = 0; i < data.length; i++){
106
- }
107
- });*/
124
+
108
125
}
109
126
110
127
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' ;
112
128
window . onload = ( ) => main ( HYF_REPOS_URL ) ;
113
- window . onload = ( ) => main ( theContributors_URL ) ;
129
+
114
130
}
0 commit comments