|
3 | 3 | var showData = false |
4 | 4 | var contributors |
5 | 5 | if (document.getElementById('contributorList')) { |
6 | | - var contributorList = document.getElementById('contributorList') |
7 | | - var commitdateTag = document.getElementById('commitdate') |
8 | | - var otherContributor = document.getElementById('otherContributor') |
9 | | - var contributorListBox = document.querySelector('.contributor-list-box') |
10 | | - var apiURL = 'https://api.github.com' |
11 | | - var githubRepo = '/couchbase/docs-ui' |
12 | | - // var url = 'https://api.github.com/repos/couchbase/docs-ui/stats/contributors' |
13 | | - // var contributorEveryDayURL = 'repos/couchbase/docs-ui/stats/contributors' |
14 | | - // Call the fetch function passing the url of the API as a parameter |
15 | | - // eslint-disable-next-line no-undef |
16 | | - fetch(apiURL + '/repos' + githubRepo + '/stats/contributors') |
17 | | - .then(function (resp) { |
18 | | - var data = resp.json() |
19 | | - return data |
20 | | - }) |
21 | | - .then(function (data) { |
22 | | - showData = true |
23 | | - contributors = data |
24 | | - var otherContributorData = contributors.length - 5 |
25 | | - var maxCommitLength = contributors.length - 1 |
26 | | - var maxCommitAuthor = contributors[maxCommitLength] |
27 | | - // get last commit date |
28 | | - var totalWeek = maxCommitAuthor.weeks |
29 | | - var totaltWeekLength = totalWeek.length - 1 // array |
30 | | - var lastCommitWeek = totalWeek[totaltWeekLength] |
31 | | - var lastCommitTimeStamp = lastCommitWeek.w // object |
32 | | - var lastCommitDate = new Date(lastCommitTimeStamp * 1000) // convert timestamp to date |
33 | | - var getDate = lastCommitDate.getDate() |
34 | | - var getYear = lastCommitDate.getFullYear() |
35 | | - // eslint-disable-next-line no-array-constructor |
36 | | - var month = new Array() |
37 | | - month[0] = 'January' |
38 | | - month[1] = 'February' |
39 | | - month[2] = 'March' |
40 | | - month[3] = 'April' |
41 | | - month[4] = 'May' |
42 | | - month[5] = 'June' |
43 | | - month[6] = 'July' |
44 | | - month[7] = 'August' |
45 | | - month[8] = 'September' |
46 | | - month[9] = 'October' |
47 | | - month[10] = 'November' |
48 | | - month[11] = 'December' |
49 | | - var getMonth = month[lastCommitDate.getMonth()] |
50 | | - var latestCommitDate = getMonth + ' ' + getDate + ', ' + getYear |
51 | | - commitdateTag.append(latestCommitDate) |
52 | | - otherContributor.append(otherContributorData) |
| 6 | + var contributorList = document.getElementById('contributorList') |
| 7 | + var commitdateTag = document.getElementById('commitdate') |
| 8 | + var otherContributor = document.getElementById('otherContributor') |
| 9 | + var contributorListBox = document.querySelector('.contributor-list-box') |
| 10 | + var apiURL = 'https://api.github.com' |
| 11 | + var githubRepo = '/couchbase/docs-ui' |
| 12 | + // var url = 'https://api.github.com/repos/couchbase/docs-ui/stats/contributors' |
| 13 | + // var contributorEveryDayURL = 'repos/couchbase/docs-ui/stats/contributors' |
| 14 | + // Call the fetch function passing the url of the API as a parameter |
| 15 | + // eslint-disable-next-line no-undef |
| 16 | + fetch(apiURL + '/repos' + githubRepo + '/stats/contributors') |
| 17 | + .then(function (resp) { |
| 18 | + var data = resp.json() |
| 19 | + return data |
| 20 | + }) |
| 21 | + .then(function (data) { |
| 22 | + showData = true |
| 23 | + contributors = data |
| 24 | + var otherContributorData = contributors.length - 5 |
| 25 | + var maxCommitLength = contributors.length - 1 |
| 26 | + var maxCommitAuthor = contributors[maxCommitLength] |
| 27 | + // get last commit date |
| 28 | + var totalWeek = maxCommitAuthor.weeks |
| 29 | + var totaltWeekLength = totalWeek.length - 1 // array |
| 30 | + var lastCommitWeek = totalWeek[totaltWeekLength] |
| 31 | + var lastCommitTimeStamp = lastCommitWeek.w // object |
| 32 | + var lastCommitDate = new Date(lastCommitTimeStamp * 1000) // convert timestamp to date |
| 33 | + var getDate = lastCommitDate.getDate() |
| 34 | + var getYear = lastCommitDate.getFullYear() |
| 35 | + // eslint-disable-next-line no-array-constructor |
| 36 | + var month = new Array() |
| 37 | + month[0] = 'January' |
| 38 | + month[1] = 'February' |
| 39 | + month[2] = 'March' |
| 40 | + month[3] = 'April' |
| 41 | + month[4] = 'May' |
| 42 | + month[5] = 'June' |
| 43 | + month[6] = 'July' |
| 44 | + month[7] = 'August' |
| 45 | + month[8] = 'September' |
| 46 | + month[9] = 'October' |
| 47 | + month[10] = 'November' |
| 48 | + month[11] = 'December' |
| 49 | + var getMonth = month[lastCommitDate.getMonth()] |
| 50 | + var latestCommitDate = getMonth + ' ' + getDate + ', ' + getYear |
| 51 | + commitdateTag.append(latestCommitDate) |
| 52 | + otherContributor.append(otherContributorData) |
53 | 53 |
|
54 | | - // show html data |
55 | | - if (showData) { |
56 | | - contributorListBox.classList.add('show') |
57 | | - } |
58 | | - // map function |
| 54 | + // show html data |
| 55 | + if (showData) { |
| 56 | + contributorListBox.classList.add('show') |
| 57 | + } |
| 58 | + // map function |
59 | 59 |
|
60 | | - contributors |
61 | | - .slice(0) |
62 | | - .reverse() |
63 | | - .map(function (contributor, index, arrayobj) { |
64 | | - //show only top 5 contributor |
65 | | - if (index <= 4) { |
66 | | - var contributorAvtar = contributor.author.avatar_url |
67 | | - // var contributorTotalCommit = contributor.total |
68 | | - var authorURL = contributor.author.html_url |
69 | | - // append child in ul |
70 | | - var li = document.createElement('li') |
71 | | - var anchor = document.createElement('a') |
72 | | - var image = document.createElement('img') |
73 | | - image.setAttribute('src', contributorAvtar) |
74 | | - image.setAttribute('alt', '') |
75 | | - anchor.setAttribute('href', authorURL) |
76 | | - anchor.setAttribute('target', '_blank') |
77 | | - li.appendChild(anchor) |
78 | | - anchor.appendChild(image) |
79 | | - contributorList.appendChild(li) |
80 | | - } |
| 60 | + contributors |
| 61 | + .slice(0) |
| 62 | + .reverse() |
| 63 | + .map(function (contributor, index, arrayobj) { |
| 64 | + //show only top 5 contributor |
| 65 | + if (index <= 4) { |
| 66 | + var contributorAvtar = contributor.author.avatar_url |
| 67 | + // var contributorTotalCommit = contributor.total |
| 68 | + var authorURL = contributor.author.html_url |
| 69 | + // append child in ul |
| 70 | + var li = document.createElement('li') |
| 71 | + var anchor = document.createElement('a') |
| 72 | + var image = document.createElement('img') |
| 73 | + image.setAttribute('src', contributorAvtar) |
| 74 | + image.setAttribute('alt', '') |
| 75 | + anchor.setAttribute('href', authorURL) |
| 76 | + anchor.setAttribute('target', '_blank') |
| 77 | + li.appendChild(anchor) |
| 78 | + anchor.appendChild(image) |
| 79 | + contributorList.appendChild(li) |
| 80 | + } |
| 81 | + }) |
| 82 | + }) |
| 83 | + .catch(function (err) { |
| 84 | + console.log(err, 13) |
81 | 85 | }) |
82 | | - }) |
83 | | - .catch(function (err) { |
84 | | - console.log(err, 13) |
85 | | - }) |
86 | 86 | } |
87 | 87 | })() |
0 commit comments