live-fns: request github with auth #68

pull/75/head
Amio 2018-08-05 11:52:58 +08:00
rodzic 98f1109ec9
commit d894bd18c3
3 zmienionych plików z 16 dodań i 3 usunięć

Wyświetl plik

@ -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)

Wyświetl plik

@ -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)
}

Wyświetl plik

@ -10,6 +10,9 @@
"service.js",
"libs"
],
"env": {
"GH_TOKEN": "@badgen-gh-token"
},
"engines": {
"node": "^10.0.0"
}