@@ -22,33 +22,80 @@ getProfile()
2222// Repositories
2323const getRepos = ( ) => {
2424 fetch ( REPOS_URL )
25- . then ( response => response . json ( ) )
26- . then ( json => {
27- console . log ( 'json:' , json )
28- const forkedRepos = json . filter ( repo => repo . fork && repo . name . startsWith ( 'project-' ) )
29- forkedRepos . forEach ( repo => projectsContainer . innerHTML +=
25+ . then ( res => res . json ( ) )
26+ . then ( data => {
27+ console . log ( 'json:' , data )
28+ const forkedRepos = data . filter (
29+ ( repo ) => repo . name . includes ( 'project-' ) && repo . fork
30+ )
31+
32+ forkedRepos . forEach ( ( repo ) => {
33+ projectsContainer . innerHTML +=
3034 `<div class="project-cards">
3135 <fieldset>
3236 <a href="${ repo . html_url } "><h3>${ repo . name } </h3></a>
3337 <p>Default branch: ${ repo . default_branch } </p>
34- <p>Latest push: ${ repo . pushed_at . slice ( 0 , 10 ) } - ${ repo . pushed_at . slice ( 11 , 16 ) } </p>
35- </fieldset>
38+ <p>Latest push: ${ new Date ( repo . pushed_at ) . toDateString ( ) } </p>
39+ <p id="commit-${ repo . name } ">Commits amount: </p>
40+ </fieldset>
3641 </div>
37- ` )
42+ ` } )
43+ fetchPullRequestsArray ( forkedRepos )
3844 drawChart ( forkedRepos . length )
3945 } )
4046}
47+
48+ const fetchPullRequestsArray = ( allRepositories ) => {
49+ allRepositories . forEach ( ( repo ) => {
50+ const PULL_URL = `https://api.github.com/repos/Technigo/${ repo . name } /pulls?per_page=100` ;
51+
52+ fetch ( PULL_URL )
53+ . then ( ( res ) => res . json ( ) )
54+ . then ( ( data ) => {
55+ const myPullRequest = data . find (
56+ ( pull ) => pull . user . login === repo . owner . login
57+ ) ;
58+
59+ // Detect if we have pull request or not.
60+ // If yes - call fetchCommits function
61+ // If no - inform user that no pull request was yet done
62+ if ( myPullRequest ) {
63+ fetchCommits ( myPullRequest . commits_url , repo . name ) ;
64+ } else {
65+ document . getElementById ( `commit-${ repo . name } ` ) . innerHTML =
66+ 'No pull request yet done :(' ;
67+ }
68+ } ) ;
69+ } ) ;
70+ } ;
71+
72+ const fetchCommits = ( myCommitsUrl , myRepoName ) => {
73+ fetch ( myCommitsUrl )
74+ . then ( ( res ) => res . json ( ) )
75+ . then ( ( data ) => {
76+ document . getElementById ( `commit-${ myRepoName } ` ) . innerHTML += data . length ;
77+ } ) ;
78+ } ;
79+
80+
4181getRepos ( )
4282
43- const getCommits = ( ) => {
44- fetch ( COMMITS_URL )
45- . then ( response => response . json ( ) )
46- . then ( json => {
47- console . log ( 'Commits:' , json . length )
48- const commitsNumber = json . filter ( repo => repo . fork && repo . name . startsWith ( 'project-' ) )
49- commitsNumber . forEach ( repo => projectsContainer . innerHTML +=
50- `
51- ` )
52- } )
53- }
54- getCommits ( )
83+
84+
85+
86+
87+
88+
89+
90+ // const getCommits = () => {
91+ // fetch(COMMITS_URL)
92+ // .then(response => response.json())
93+ // .then(json => {
94+ // console.log('Commits:',json.length)
95+ // const commitsNumber = json.
96+ // commitsNumber.forEach(repo => projectsContainer.innerHTML +=
97+ // `
98+ // `)
99+ // })
100+ // }
101+ // getCommits()
0 commit comments