diff --git a/package.json b/package.json index bc4fe4c1..5c7137ea 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ }, "dependencies": { "chalk": "^2.4.1", + "delay": "^4.3.0", "execa": "^1.0.0", "got": "^9.6.0", "inquirer": "^6.3.1", diff --git a/src/travis.ts b/src/travis.ts index 784bd9e7..5edfe5dd 100644 --- a/src/travis.ts +++ b/src/travis.ts @@ -1,3 +1,4 @@ +import delay from 'delay' import got, { GotInstance, GotJSONFn } from 'got' import * as yaml from 'js-yaml' import { exists } from 'mz/fs' @@ -114,11 +115,22 @@ export async function initTravis({ await travisClient.post(`user/${travisUser.id}/sync`) while ((await getCurrentTravisUser({ travisClient })).is_syncing) { console.log('Waiting for sync to finish...') - await new Promise(resolve => setTimeout(resolve, 1000)) + await delay(1000) } - console.log(`Activating repository at https://travis-ci.org/sourcegraph/${repoName}`) - await travisClient.post(`/repo/sourcegraph%2F${repoName}/activate`) + // Retry activating while repository is not found (404) + while (true) { + try { + await delay(1000) + console.log(`Activating repository at https://travis-ci.org/sourcegraph/${repoName}`) + await travisClient.post(`/repo/sourcegraph%2F${repoName}/activate`) + break + } catch (err) { + if (err.status !== 404) { + throw err + } + } + } const envVars = (await travisClient.get(`/repo/sourcegraph%2F${repoName}/env_vars`)).body if (envVars.env_vars.some((envVar: any) => envVar.name === 'NPM_TOKEN')) { diff --git a/yarn.lock b/yarn.lock index 63e685b2..d1518067 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1563,6 +1563,11 @@ define-property@^2.0.2: is-descriptor "^1.0.2" isobject "^3.0.1" +delay@^4.3.0: + version "4.3.0" + resolved "https://registry.npmjs.org/delay/-/delay-4.3.0.tgz#efeebfb8f545579cb396b3a722443ec96d14c50e" + integrity sha512-Lwaf3zVFDMBop1yDuFZ19F9WyGcZcGacsbdlZtWjQmM50tOcMntm1njF/Nb/Vjij3KaSvCF+sEYGKrrjObu2NA== + delayed-stream@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"