Skip to content

Commit

Permalink
fix(travis): retry 404 when activating repo
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfbecker committed Jul 3, 2019
1 parent 54ab744 commit 4f2c13a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 15 additions & 3 deletions src/travis.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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<void>(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')) {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4f2c13a

Please sign in to comment.