Skip to content

Commit 4f2c13a

Browse files
committed
fix(travis): retry 404 when activating repo
1 parent 54ab744 commit 4f2c13a

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
},
4747
"dependencies": {
4848
"chalk": "^2.4.1",
49+
"delay": "^4.3.0",
4950
"execa": "^1.0.0",
5051
"got": "^9.6.0",
5152
"inquirer": "^6.3.1",

src/travis.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import delay from 'delay'
12
import got, { GotInstance, GotJSONFn } from 'got'
23
import * as yaml from 'js-yaml'
34
import { exists } from 'mz/fs'
@@ -114,11 +115,22 @@ export async function initTravis({
114115
await travisClient.post(`user/${travisUser.id}/sync`)
115116
while ((await getCurrentTravisUser({ travisClient })).is_syncing) {
116117
console.log('Waiting for sync to finish...')
117-
await new Promise<void>(resolve => setTimeout(resolve, 1000))
118+
await delay(1000)
118119
}
119120

120-
console.log(`Activating repository at https://travis-ci.org/sourcegraph/${repoName}`)
121-
await travisClient.post(`/repo/sourcegraph%2F${repoName}/activate`)
121+
// Retry activating while repository is not found (404)
122+
while (true) {
123+
try {
124+
await delay(1000)
125+
console.log(`Activating repository at https://travis-ci.org/sourcegraph/${repoName}`)
126+
await travisClient.post(`/repo/sourcegraph%2F${repoName}/activate`)
127+
break
128+
} catch (err) {
129+
if (err.status !== 404) {
130+
throw err
131+
}
132+
}
133+
}
122134

123135
const envVars = (await travisClient.get(`/repo/sourcegraph%2F${repoName}/env_vars`)).body
124136
if (envVars.env_vars.some((envVar: any) => envVar.name === 'NPM_TOKEN')) {

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,6 +1563,11 @@ define-property@^2.0.2:
15631563
is-descriptor "^1.0.2"
15641564
isobject "^3.0.1"
15651565

1566+
delay@^4.3.0:
1567+
version "4.3.0"
1568+
resolved "https://registry.npmjs.org/delay/-/delay-4.3.0.tgz#efeebfb8f545579cb396b3a722443ec96d14c50e"
1569+
integrity sha512-Lwaf3zVFDMBop1yDuFZ19F9WyGcZcGacsbdlZtWjQmM50tOcMntm1njF/Nb/Vjij3KaSvCF+sEYGKrrjObu2NA==
1570+
15661571
delayed-stream@~1.0.0:
15671572
version "1.0.0"
15681573
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"

0 commit comments

Comments
 (0)