From ebf783c8189713cfb91901947cfb5fc5003bb18e Mon Sep 17 00:00:00 2001 From: develar Date: Sun, 13 Mar 2016 09:30:42 +0100 Subject: [PATCH] fix: delete release again if failed with "405 Not Allowed" (3 times) --- src/gitHubPublisher.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/gitHubPublisher.ts b/src/gitHubPublisher.ts index 806faa3a60f..b8ee6ba8761 100644 --- a/src/gitHubPublisher.ts +++ b/src/gitHubPublisher.ts @@ -141,12 +141,25 @@ export class GitHubPublisher implements Publisher { } //noinspection JSUnusedGlobalSymbols - deleteRelease(): BluebirdPromise { - if (this._releasePromise.isFulfilled()) { - return gitHubRequest(`/repos/${this.owner}/${this.repo}/releases/${this._releasePromise.value().id}`, this.token, null, "DELETE") - } - else { + async deleteRelease(): Promise { + if (!this._releasePromise.isFulfilled()) { return BluebirdPromise.resolve() } + + for (let i = 0; i < 3; i++) { + try { + return await + gitHubRequest(`/repos/${this.owner}/${this.repo}/releases/${this._releasePromise.value().id}`, this.token, null, "DELETE") + } + catch (e) { + if (e instanceof HttpError && (e.response.statusCode === 405 || e.response.statusCode === 502)) { + continue + } + + throw e + } + } + + log("WARN: Cannot delete release " + this._releasePromise.value().id) } } \ No newline at end of file