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 ed6497b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 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,20 @@ export class GitHubPublisher extends HttpPublisher {
})
}

private doesErrorMeanAlreadyExists(e: any) {
let doesErrorMeanAlreadyExists = true
doesErrorMeanAlreadyExists = doesErrorMeanAlreadyExists && e.statusCode === 422
if (e.description) {
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")
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 ed6497b

Please sign in to comment.