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

webhooks.js 1.3 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
  1. const path = require('path')
  2. const { defaults } = require('lodash')
  3. const webhookPayloads = require(path.join(process.cwd(), 'lib/webhooks'))
  4. const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
  5. const allVersions = require('../../lib/all-versions')
  6. module.exports = function webhooksContext (req, res, next) {
  7. const currentVersionObj = allVersions[req.context.currentVersion]
  8. // ignore requests to non-webhook reference paths
  9. // and to versions that don't exist
  10. if (!req.path.includes('webhook') || !currentVersionObj) {
  11. return next()
  12. }
  13. // Get the name of the dir under lib/webhooks/static
  14. // For example, free-pro-team@latest corresponds to dotcom,
  15. // enterprise-server@2.22 corresponds to ghes-2.22,
  16. // and github-ae@latest corresponds to ghae
  17. const webhookPayloadDir = currentVersionObj.miscVersionName
  18. const webhookPayloadsForCurrentVersion = webhookPayloads[webhookPayloadDir]
  19. // if current version is non-dotcom, include dotcom payloads in object so we can fall back to them if needed
  20. req.context.webhookPayloadsForCurrentVersion = req.context.currentVersion === nonEnterpriseDefaultVersion
  21. ? webhookPayloadsForCurrentVersion
  22. : defaults(webhookPayloadsForCurrentVersion, webhookPayloads[allVersions[nonEnterpriseDefaultVersion].miscVersionName])
  23. return next()
  24. }
Tip!

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

Comments

Loading...