1 | const urlJoin = require('url-join');
|
2 | const got = require('got');
|
3 | const pRetry = require('p-retry');
|
4 | const getTravisUrl = require('./get-travis-url');
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | module.exports = async (travisOpts, travisToken, buildId, retryOpts) => {
|
18 | try {
|
19 | return (await pRetry(
|
20 | () =>
|
21 | got(urlJoin(getTravisUrl(travisOpts), `builds/${buildId}`), {
|
22 | json: true,
|
23 | headers: {
|
24 | 'user-agent': 'Travis',
|
25 | accept: 'application/vnd.travis-ci.2+json',
|
26 | authorization: `token ${travisToken}`,
|
27 | },
|
28 | }),
|
29 | Object.assign({retries: 5, factor: 2, minTimeout: 1000}, retryOpts)
|
30 | )).body.jobs;
|
31 | } catch (err) {
|
32 |
|
33 |
|
34 | if (err.response && err.response.body && err.response.body.file === 'not found') {
|
35 | throw new Error(
|
36 | 'The GitHub user of the "GH_TOKEN" has not authenticated Travis CI yet. Go to https://travis-ci.com/, login with the GitHub user of this token and then restart this job.'
|
37 | );
|
38 | }
|
39 | throw err;
|
40 | }
|
41 | };
|