Amio
6 years ago
1 changed files with 24 additions and 15 deletions
@ -1,32 +1,41 @@ |
|||
const axios = require('../axios.js') |
|||
|
|||
const statuses = [ |
|||
['passed', 'green'], |
|||
['passing', 'green'], |
|||
['failed', 'orange'], |
|||
['failing', 'orange'], |
|||
['error', 'red'], |
|||
['errored', 'red'], |
|||
['pending', 'yellow'], |
|||
['fixed', 'yellow'], |
|||
['broken', 'red'], |
|||
['canceled', 'grey'] |
|||
] |
|||
|
|||
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}` |
|||
const res = await Promise.all([ |
|||
const [svg1, svg2] = await Promise.all([ |
|||
axios.get(com).then(({ data }) => data).catch(e => e), |
|||
axios.get(org).then(({ data }) => data).catch(e => e) |
|||
]) |
|||
|
|||
if (res[0].match(/passed|passing/) || res[1].match(/passed|passing/)) { |
|||
const result = statuses.find(st => { |
|||
return svg1.includes(st[0]) || svg2.includes(st[0]) |
|||
}) |
|||
|
|||
if (result) { |
|||
return { |
|||
subject: 'travis', |
|||
status: 'passing', |
|||
color: 'green' |
|||
status: result[0], |
|||
color: result[1] |
|||
} |
|||
} |
|||
|
|||
if (res[0].match(/failed|failing/) || res[1].match(/failed|failing/)) { |
|||
} else { |
|||
return { |
|||
subject: 'travis', |
|||
status: 'failed', |
|||
color: 'red' |
|||
status: 'unknown', |
|||
color: 'grey' |
|||
} |
|||
} |
|||
|
|||
return { |
|||
subject: 'build', |
|||
status: 'unknown', |
|||
color: 'grey' |
|||
} |
|||
} |
|||
|
Loading…
Reference in new issue