3
1

github.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. export const fetchReports = () => {
  2. const domain = `https://raw.githubusercontent.com/Joystream/community-repo/master/council-reports`
  3. const apiBase = `https://api.github.com/repos/joystream/community-repo/contents/council-reports`
  4. const urls: { [key: string]: string } = {
  5. alexandria: `${apiBase}/alexandria-testnet`,
  6. archive: `${apiBase}/archived-reports`,
  7. template: `${domain}/templates/council_report_template_v1.md`,
  8. }
  9. ;['alexandria', 'archive'].map((folder) => fetchGithubDir(urls[folder]))
  10. fetchGithubFile(urls.template)
  11. }
  12. const fetchGithubFile = async (url: string): Promise<string> => {
  13. const { data } = await axios.get(url)
  14. return data
  15. }
  16. const fetchGithubDir = async (url: string) => {
  17. const { data } = await axios.get(url)
  18. data.forEach(
  19. async (o: {
  20. name: string
  21. type: string
  22. url: string
  23. download_url: string
  24. }) => {
  25. const match = o.name.match(/^(.+)\.md$/)
  26. const name = match ? match[1] : o.name
  27. if (o.type === 'file') {
  28. const file = await fetchGithubFile(o.download_url)
  29. // TODO save file
  30. } else fetchGithubDir(o.url)
  31. }
  32. )
  33. }