]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - scripts/generate-code-contributors.ts
8cc3dc5b454b49783334811cfd5014c29944fe5b
[github/Chocobozzz/PeerTube.git] / scripts / generate-code-contributors.ts
1 import { registerTSPaths } from '../server/helpers/register-ts-paths'
2
3 registerTSPaths()
4
5 import { doRequest } from '../server/helpers/requests'
6 import { readFileSync } from 'fs-extra'
7 import { uniqBy } from 'lodash'
8
9 run()
10 .then(() => process.exit(0))
11 .catch(err => {
12 console.error(err)
13 process.exit(-1)
14 })
15
16 async function run () {
17
18 {
19 const contributors = await fetchGithub('https://api.github.com/repos/chocobozzz/peertube/contributors')
20
21 console.log('# Code contributors\n')
22 for (const contributor of contributors) {
23 const contributorUrl = contributor.url.replace('api.github.com/users', 'github.com')
24 console.log(` * [${contributor.login}](${contributorUrl})`)
25 }
26 }
27
28 {
29 const zanataConfig = readFileSync(require('os').homedir() + '/.config/zanata.ini').toString()
30 const zanataUsername = zanataConfig.match('.username=([^\n]+)')[1]
31 const zanataToken = zanataConfig.match('.key=([^\n]+)')[1]
32
33 const translators = await fetchZanata(zanataUsername, zanataToken)
34
35 console.log('\n\n# Translation contributors\n')
36 for (const translator of translators) {
37 console.log(` * [${translator.username}](https://trad.framasoft.org/zanata/profile/view/${translator.username})`)
38 }
39 }
40
41 {
42 console.log('\n\n# Design\n')
43 console.log(' * [Olivier Massain](https://twitter.com/omassain)')
44
45 console.log('\n\n# Icons\n')
46 console.log(' * [Robbie Pearce](https://robbiepearce.com/softies/)')
47 console.log(' * [Fork-Awesome](https://github.com/ForkAwesome/Fork-Awesome)')
48 console.log(' * playlist add by Google')
49 }
50 }
51
52 function get (url: string, headers: any = {}) {
53 return doRequest<any>({
54 uri: url,
55 json: true,
56 headers: Object.assign(headers, {
57 'User-Agent': 'PeerTube-App'
58 })
59 }).then(res => res.body)
60 }
61
62 async function fetchGithub (url: string) {
63 let next = url
64 let allResult = []
65
66 let i = 1
67
68 // Hard limit
69 while (i < 20) {
70 const result = await get(next + '?page=' + i)
71 if (result.length === 0) break
72
73 allResult = allResult.concat(result)
74 i++
75 }
76
77 return allResult
78 }
79
80 async function fetchZanata (zanataUsername: string, zanataPassword: string) {
81 const today = new Date().toISOString().split('T')[0]
82 const year2018 = `https://trad.framasoft.org/zanata/rest/project/peertube/version/develop/contributors/2018-01-01..2019-01-01`
83 const year2019 = `https://trad.framasoft.org/zanata/rest/project/peertube/version/develop/contributors/2019-01-01..${today}`
84
85 const headers = {
86 'X-Auth-User': zanataUsername,
87 'X-Auth-Token': zanataPassword
88 }
89 const [ results2018, results2019 ] = await Promise.all([
90 get(year2018, headers),
91 get(year2019, headers)
92 ])
93
94 return uniqBy((results2018.concat(results2019)), 'username')
95 }