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 542bc35 commit e4caeca
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/electron-publish/src/gitHubPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ export class GitHubPublisher extends HttpPublisher {
requestProcessor
)
.catch(e => {
if (e.statusCode === 422 && e.description != null && ((e.description.includes('errors') && e.description.includes("already_exists"))
|| (e.description.errors != null && 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 @@ -216,6 +215,19 @@ export class GitHubPublisher extends HttpPublisher {
})
}

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

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 e4caeca

Please sign in to comment.