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 token = process.env.GH_TOKEN
|
||||
|
||||
// https://developer.github.com/v3/repos/
|
||||
|
||||
|
@ -18,8 +19,10 @@ module.exports = async function (topic, ...args) {
|
|||
}
|
||||
|
||||
async function release (user, repo, channel) {
|
||||
const endpoint = `https://api.github.com/repos/${user}/${repo}/releases`
|
||||
const logs = await axios.get(endpoint).then(res => res.data)
|
||||
const url = `https://api.github.com/repos/${user}/${repo}/releases`
|
||||
const headers = token && { 'Authorization': `token ${token}` }
|
||||
|
||||
const logs = await axios({ url, headers }).then(res => res.data)
|
||||
|
||||
const [latest] = logs
|
||||
const stable = logs.find(log => !log.prerelease)
|
||||
|
|
|
@ -5,8 +5,15 @@ module.exports = async function (req, res) {
|
|||
const [
|
||||
githubRateLimit
|
||||
] = await Promise.all([
|
||||
axios('https://api.github.com/rate_limit').then(res => res.data.resources)
|
||||
getGithubRateLimit()
|
||||
])
|
||||
|
||||
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",
|
||||
"libs"
|
||||
],
|
||||
"env": {
|
||||
"GH_TOKEN": "@badgen-gh-token"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^10.0.0"
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue