diff --git a/package.json b/package.json index 50211d25b6d..27244eed2d1 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ "babel-plugin-array-includes": "^2.0.3", "babel-plugin-transform-es2015-parameters": "^6.7.0", "electron-download": "^2.0.0", - "eslint": "^2.3.0", + "eslint": "^2.4.0", "eslint-plugin-ava": "sindresorhus/eslint-plugin-ava", "ghooks": "^1.0.3", "json-parse-helpfulerror": "^1.0.3", diff --git a/src/gitHubPublisher.ts b/src/gitHubPublisher.ts index 42813f0d881..806faa3a60f 100644 --- a/src/gitHubPublisher.ts +++ b/src/gitHubPublisher.ts @@ -42,7 +42,7 @@ export class GitHubPublisher implements Publisher { private async init(): Promise { // we don't use "Get a release by tag name" because "tag name" means existing git tag, but we draft release and don't create git tag - let releases = await gitHubRequest>(`/repos/${this.owner}/${this.repo}/releases`, this.token) + const releases = await gitHubRequest>(`/repos/${this.owner}/${this.repo}/releases`, this.token) for (let release of releases) { if (release.tag_name === this.tag) { if (!release.draft) { @@ -75,6 +75,7 @@ export class GitHubPublisher implements Publisher { const parsedUrl = parseUrl(release.upload_url.substring(0, release.upload_url.indexOf("{")) + "?name=" + fileName) const fileStat = await stat(path) + let badGatewayCount = 0 uploadAttempt: for (let i = 0; i < 3; i++) { const progressBar = (process.stdin).isTTY ? new ProgressBar(`Uploading ${fileName} [:bar] :percent :etas`, { total: fileStat.size, @@ -107,8 +108,7 @@ export class GitHubPublisher implements Publisher { } catch (e) { if (e instanceof HttpError) { - const httpError = e - if (httpError.response.statusCode === 422 && httpError.description != null && httpError.description.errors != null && httpError.description.errors[0].code === "already_exists") { + if (e.response.statusCode === 422 && e.description != null && e.description.errors != null && e.description.errors[0].code === "already_exists") { // delete old artifact and re-upload log("Artifact %s already exists, overwrite one", fileName) const assets = await gitHubRequest>(`/repos/${this.owner}/${this.repo}/releases/${release.id}/assets`, this.token) @@ -122,6 +122,9 @@ export class GitHubPublisher implements Publisher { log("Artifact %s not found, trying to upload again", fileName) continue } + else if (e.response.statusCode === 502 && badGatewayCount++ < 3) { + continue + } } throw e diff --git a/test/src/ArtifactPublisherTest.ts b/test/src/ArtifactPublisherTest.ts index adccee0b508..2ab0e33174d 100644 --- a/test/src/ArtifactPublisherTest.ts +++ b/test/src/ArtifactPublisherTest.ts @@ -1,4 +1,4 @@ -import test from "ava-tf" +import test from "./helpers/avaEx" import { GitHubPublisher } from "out/gitHubPublisher" import { HttpError } from "out/gitHubRequest" import { join } from "path"