Browse Source

refactor: use got in travis

master
Amio 6 years ago
parent
commit
2f2b3876eb
  1. 4
      libs/got.js
  2. 5
      libs/live-fetcher.js
  3. 6
      libs/live-fns/travis.js

4
libs/got.js

@ -1,5 +1,7 @@
const got = require('got')
module.exports = got.extend({
json: true
json: true,
timeout: 3200,
retry: 0
})

5
libs/live-fetcher.js

@ -3,10 +3,11 @@ const pool = require('./live-pool.js')
const raven = require('./raven.js')
module.exports = async (service, fn, paramsPath) => {
const fetchStart = new Date()
const fetchKey = `#${service}/${paramsPath}`
if (pool.has(fetchKey)) return pool.get(fetchKey)
const fetchStart = new Date()
const fetcher = fn(...paramsPath.split('/')).then(
result => {
console.log(timeSince(fetchStart), fetchKey)
@ -14,9 +15,9 @@ module.exports = async (service, fn, paramsPath) => {
},
err => errorHandler(service, paramsPath, err)
).finally(() => {
console.log(timeSince(fetchStart), fetchKey)
pool.delete(fetchKey)
})
pool.set(fetchKey, fetcher)
return fetcher

6
libs/live-fns/travis.js

@ -1,4 +1,4 @@
const axios = require('../axios.js')
const got = require('../got.js')
const statuses = [
['passed', 'green'],
@ -17,8 +17,8 @@ module.exports = async (user, repo, branch = 'master') => {
const com = `https://api.travis-ci.com/${user}/${repo}.svg?branch=${branch}`
const org = `https://api.travis-ci.org/${user}/${repo}.svg?branch=${branch}`
const [svg1, svg2] = await Promise.all([
axios(com).then(({ data }) => data).catch(e => undefined),
axios(org).then(({ data }) => data).catch(e => undefined)
got(com, { json: false }).then(({ body }) => body),
got(org, { json: false }).then(({ body }) => body)
])
const result = statuses.find(st => {

Loading…
Cancel
Save