2
1

generate-code-contributors.ts 2.5 KB

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