Skip to content

Commit

Permalink
refactor(electron-publish): breakout github if-asset-already-exists c…
Browse files Browse the repository at this point in the history
…heck into function
  • Loading branch information
baparham committed Jan 18, 2022
1 parent 31587cc commit 0f66b0f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/electron-publish/src/gitHubPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,7 @@ export class GitHubPublisher extends HttpPublisher {
requestProcessor
)
.catch(e => {
if (
e.statusCode === 422 &&
e.description &&
((e.description.includes("errors") && e.description.includes("already_exists")) ||
(e.description.errors && e.description.errors.length >= 1 && e.description.errors[0].code === "already_exists"))
) {
if (this.doesErrorMeanAlreadyExists(e)) {
return this.overwriteArtifact(fileName, release).then(() => this.doUploadFile(attemptNumber, parsedUrl, fileName, dataLength, requestProcessor, release))
}

Expand All @@ -220,6 +215,16 @@ export class GitHubPublisher extends HttpPublisher {
})
}

private doesErrorMeanAlreadyExists(e: any) {
if (!e.description) {
return false
}
const desc = e.description
const descIncludesAlreadyExists =
(desc.includes("errors") && desc.includes("already_exists")) || (desc.errors && desc.errors.length >= 1 && desc.errors[0].code === "already_exists")
return e.statusCode === 422 && descIncludesAlreadyExists
}

private createRelease() {
return this.githubRequest<Release>(`/repos/${this.info.owner}/${this.info.repo}/releases`, this.token, {
tag_name: this.tag,
Expand Down

0 comments on commit 0f66b0f

Please sign in to comment.