generate-code-contributors.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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('By [Olivier Massain](https://twitter.com/omassain)\n')
  31. console.log('Icons from [Robbie Pearce](https://robbiepearce.com/softies/)')
  32. }
  33. }
  34. function get (url: string, headers: any = {}) {
  35. return doRequest({
  36. uri: url,
  37. json: true,
  38. headers: Object.assign(headers, {
  39. 'User-Agent': 'PeerTube-App'
  40. })
  41. }).then(res => res.body)
  42. }
  43. async function fetchGithub (url: string) {
  44. let next = url
  45. let allResult = []
  46. let i = 1
  47. // Hard limit
  48. while (i < 20) {
  49. const result = await get(next + '?page=' + i)
  50. if (result.length === 0) break
  51. allResult = allResult.concat(result)
  52. i++
  53. }
  54. return allResult
  55. }
  56. async function fetchZanata (zanataUsername: string, zanataPassword: string) {
  57. const today = new Date().toISOString().split('T')[0]
  58. const url = `https://trad.framasoft.org/zanata/rest/project/peertube/version/develop/contributors/2018-01-01..${today}`
  59. const headers = {
  60. 'X-Auth-User': zanataUsername,
  61. 'X-Auth-Token': zanataPassword
  62. }
  63. return get(url, headers)
  64. }