kopia lustrzana https://github.com/badgen/badgen.net
live-fns: request github with auth #68
rodzic
98f1109ec9
commit
d894bd18c3
|
@ -1,4 +1,5 @@
|
||||||
const axios = require('../axios.js')
|
const axios = require('../axios.js')
|
||||||
|
const token = process.env.GH_TOKEN
|
||||||
|
|
||||||
// https://developer.github.com/v3/repos/
|
// https://developer.github.com/v3/repos/
|
||||||
|
|
||||||
|
@ -18,8 +19,10 @@ module.exports = async function (topic, ...args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function release (user, repo, channel) {
|
async function release (user, repo, channel) {
|
||||||
const endpoint = `https://api.github.com/repos/${user}/${repo}/releases`
|
const url = `https://api.github.com/repos/${user}/${repo}/releases`
|
||||||
const logs = await axios.get(endpoint).then(res => res.data)
|
const headers = token && { 'Authorization': `token ${token}` }
|
||||||
|
|
||||||
|
const logs = await axios({ url, headers }).then(res => res.data)
|
||||||
|
|
||||||
const [latest] = logs
|
const [latest] = logs
|
||||||
const stable = logs.find(log => !log.prerelease)
|
const stable = logs.find(log => !log.prerelease)
|
||||||
|
|
|
@ -5,8 +5,15 @@ module.exports = async function (req, res) {
|
||||||
const [
|
const [
|
||||||
githubRateLimit
|
githubRateLimit
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
axios('https://api.github.com/rate_limit').then(res => res.data.resources)
|
getGithubRateLimit()
|
||||||
])
|
])
|
||||||
|
|
||||||
send(res, 200, { githubRateLimit })
|
send(res, 200, { githubRateLimit })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getGithubRateLimit () {
|
||||||
|
const url = 'https://api.github.com/rate_limit'
|
||||||
|
const token = process.env.GH_TOKEN
|
||||||
|
const headers = token && { 'Authorization': `token ${token}` }
|
||||||
|
return axios({ url, headers }).then(res => res.data.resources)
|
||||||
|
}
|
||||||
|
|
3
now.json
3
now.json
|
@ -10,6 +10,9 @@
|
||||||
"service.js",
|
"service.js",
|
||||||
"libs"
|
"libs"
|
||||||
],
|
],
|
||||||
|
"env": {
|
||||||
|
"GH_TOKEN": "@badgen-gh-token"
|
||||||
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^10.0.0"
|
"node": "^10.0.0"
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue