Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

index.js 2.1 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  1. const fs = require('fs')
  2. const path = require('path')
  3. const { chain, get, groupBy } = require('lodash')
  4. const schemasPath = path.join(__dirname, 'static/decorated')
  5. const operations = {}
  6. fs.readdirSync(schemasPath)
  7. .forEach(filename => {
  8. const key = filename.replace('.json', '')
  9. const value = require(path.join(schemasPath, filename))
  10. operations[key] = value
  11. })
  12. const allVersions = require('../all-versions')
  13. const allVersionKeys = Object.keys(allVersions)
  14. let allCategories = []
  15. allVersionKeys.forEach(currentVersion => {
  16. // Translate the versions from the openapi to versions used in the docs
  17. const openApiVersion = allVersions[currentVersion].openApiVersionName
  18. // Check that the openApiVersion is configured in OpenAPI
  19. if (!operations[openApiVersion]) return
  20. operations[currentVersion] = operations[openApiVersion]
  21. delete operations[openApiVersion]
  22. // This list is generated for use in the tests,
  23. // so we can verify that the names of the markdown files
  24. // in content/rest/reference/*.md are congruous with the
  25. // set of REST resource names like activity, gists, repos, etc.
  26. allCategories = allCategories.concat(chain(operations[currentVersion]).map('category').sort().uniq().value())
  27. // Attach convenience properties to each operation that can't easily be created in Liquid
  28. operations[currentVersion].forEach(operation => {
  29. operation.hasRequiredPreviews = get(operation, 'x-github.previews', []).some(preview => preview.required)
  30. })
  31. })
  32. // Get the unique set of categories
  33. const categories = [...new Set(allCategories)]
  34. // This is a collection of operations that have `enabledForGitHubApps = true`
  35. // It's grouped by resource title to make rendering easier
  36. const operationsEnabledForGitHubApps = allVersionKeys.reduce((acc, currentVersion) => {
  37. acc[currentVersion] = chain(operations[currentVersion] || [])
  38. .filter(operation => operation['x-github'].enabledForGitHubApps)
  39. .orderBy('category')
  40. .value()
  41. acc[currentVersion] = groupBy(acc[currentVersion], 'category')
  42. return acc
  43. }, {})
  44. module.exports = {
  45. categories,
  46. operations,
  47. operationsEnabledForGitHubApps
  48. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...