2018-07-16 06:34:42 +00:00
|
|
|
const axios = require('../axios.js')
|
|
|
|
|
|
|
|
module.exports = async function (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}`
|
2018-07-19 14:11:59 +00:00
|
|
|
const res = await Promise.all([
|
|
|
|
axios.get(com).then(({ data }) => data).catch(e => e),
|
|
|
|
axios.get(org).then(({ data }) => data).catch(e => e)
|
2018-07-16 06:34:42 +00:00
|
|
|
])
|
|
|
|
|
2018-07-19 14:11:59 +00:00
|
|
|
if (res[0].match(/passed|passing/) || res[1].match(/passed|passing/)) {
|
2018-07-16 06:34:42 +00:00
|
|
|
return {
|
2018-07-27 06:25:58 +00:00
|
|
|
subject: 'travis',
|
2018-07-16 06:34:42 +00:00
|
|
|
status: 'passing',
|
|
|
|
color: 'green'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-19 14:11:59 +00:00
|
|
|
if (res[0].match(/failed|failing/) || res[1].match(/failed|failing/)) {
|
2018-07-16 06:34:42 +00:00
|
|
|
return {
|
2018-07-27 06:25:58 +00:00
|
|
|
subject: 'travis',
|
2018-07-16 06:34:42 +00:00
|
|
|
status: 'failed',
|
|
|
|
color: 'red'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
subject: 'build',
|
|
|
|
status: 'unknown',
|
|
|
|
color: 'grey'
|
|
|
|
}
|
|
|
|
}
|