Browse Source

Merge branch 'master' into 2.0

docker-size
amio 6 years ago
parent
commit
fe2aa7b9b5
  1. 10
      libs/live-fns/github.js
  2. 13
      now.json

10
libs/live-fns/github.js

@ -5,7 +5,6 @@ const got = require('../got.js')
const v = require('../utils/version-formatter.js') const v = require('../utils/version-formatter.js')
const { GH_TOKEN } = process.env const { GH_TOKEN } = process.env
const authHeader = GH_TOKEN && `token ${GH_TOKEN}`
module.exports = async (topic, ...args) => { module.exports = async (topic, ...args) => {
if (args.length < 2) { if (args.length < 2) {
@ -50,10 +49,15 @@ module.exports = async (topic, ...args) => {
} }
} }
const pickGithubToken = () => {
const tokens = GH_TOKEN.split(',')
return tokens[Math.floor(Math.random() * tokens.length)]
}
// request github api v3 (rest) // request github api v3 (rest)
const restGithub = path => got.get(`https://api.github.com/${path}`, { const restGithub = path => got.get(`https://api.github.com/${path}`, {
headers: { headers: {
Authorization: authHeader, Authorization: `token ${pickGithubToken()}`,
Accept: 'application/vnd.github.hellcat-preview+json' Accept: 'application/vnd.github.hellcat-preview+json'
} }
}).then(res => res.body) }).then(res => res.body)
@ -63,7 +67,7 @@ const queryGithub = query => {
return got.post('https://api.github.com/graphql', { return got.post('https://api.github.com/graphql', {
body: { query }, body: { query },
headers: { headers: {
Authorization: authHeader, Authorization: `token ${pickGithubToken()}`,
Accept: 'application/vnd.github.hawkgirl-preview+json' Accept: 'application/vnd.github.hawkgirl-preview+json'
} }
}).then(res => res.body) }).then(res => res.body)

13
now.json

@ -1,9 +1,20 @@
{ {
"version": 2, "version": 2,
"alias": [
"v2.badgen.net"
],
"builds": [ "builds": [
{ "src": "endpoints/*.ts", "use": "@now/node" } { "src": "endpoints/*.ts", "use": "@now/node" }
], ],
"routes": [ "routes": [
{ "src": "/(?<name>\\w+)/.*", "dest": "/endpoints/$name.ts" } { "src": "/(?<name>\\w+)/.*", "dest": "/endpoints/$name.ts" }
] ],
"env": {
"GH_TOKEN": "@badgen-gh-tokens",
"SENTRY_URI": "@badgen-sentry-uri",
"TRACKING_GA": "@badgen-tracking-ga"
},
"github": {
"autoAlias": false
}
} }

Loading…
Cancel
Save