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gBAAgB,EAAtD,CAAhB;AACA,WAAO,qCAAU,iCAAa,OAAb,CAAqB,mDAAwB;AAC5D,MAAA,QAAQ,EAAE,OAAO,CAAC,QAD0C;AAE5D,MAAA,IAAI,EAAE,OAAO,CAAC,IAF8C;AAG5D,MAAA,IAAI,EAAG,KAAK,IAAL,CAAU,IAAV,IAAkB,IAAlB,IAA0B,KAAK,IAAL,CAAU,IAAV,KAAmB,YAA9C,GAA8D,UAAU,IAAI,CAAC,UAAL,CAAgB,GAAhB,IAAuB,IAAvB,GAA8B,IAAI,IAAI,EAAE,EAAhH,GAAqH,IAH/D;AAI5D,MAAA,OAAO,EAAE;AAAC,QAAA,MAAM,EAAE;AAAT;AAJmD,KAAxB,EAKnC,KALmC,EAK5B,MAL4B,CAArB,EAKE,KAAK,OAAL,CAAa,iBALf,EAKkC,IALlC,CAAV,CAAP;AAMD;;AAED,EAAA,QAAQ,GAAA;AACN,WAAO,kBAAkB,KAAK,IAAL,CAAU,KAAK,cAAc,KAAK,IAAL,CAAU,IAAI,cAAc,KAAK,OAAO,GAA9F;AACD;;AA3O+C,C","sourcesContent":["import { Arch, InvalidConfigurationError, isEmptyOrSpaces, isEnvTrue, isTokenCharValid, log } from \"builder-util\"\nimport { configureRequestOptions, GithubOptions, HttpError, parseJson } from \"builder-util-runtime\"\nimport { Fields } from \"builder-util/out/log\"\nimport { httpExecutor } from \"builder-util/out/nodeHttpExecutor\"\nimport { ClientRequest } from \"http\"\nimport { Lazy } from \"lazy-val\"\nimport mime from \"mime\"\nimport { parse as parseUrl, UrlWithStringQuery } from \"url\"\nimport { getCiTag, HttpPublisher, PublishContext, PublishOptions } from \"./publisher\"\n\nexport interface Release {\n id: number\n tag_name: string\n\n draft: boolean\n prerelease: boolean\n\n published_at: string\n\n upload_url: string\n}\n\ninterface Asset {\n id: number\n name: string\n}\n\nexport class GitHubPublisher extends HttpPublisher {\n private readonly tag: string\n readonly _release = new Lazy(() => this.token === \"__test__\" ? Promise.resolve(null as any) : this.getOrCreateRelease())\n\n private readonly token: string\n\n readonly providerName = \"GitHub\"\n\n private readonly releaseType: \"draft\" | \"prerelease\" | \"release\"\n\n private releaseLogFields: Fields | null = null\n\n constructor(context: PublishContext, private readonly info: GithubOptions, private readonly version: string, private readonly options: PublishOptions = {}) {\n super(context, true)\n\n let token = info.token\n if (isEmptyOrSpaces(token)) {\n token = process.env.GH_TOKEN || process.env.GITHUB_TOKEN\n if (isEmptyOrSpaces(token)) {\n throw new InvalidConfigurationError(`GitHub Personal Access Token is not set, neither programmatically, nor using env \"GH_TOKEN\"`)\n }\n\n token = token.trim()\n\n if (!isTokenCharValid(token)) {\n throw new InvalidConfigurationError(`GitHub Personal Access Token (${JSON.stringify(token)}) contains invalid characters, please check env \"GH_TOKEN\"`)\n }\n }\n\n this.token = token!\n\n if (version.startsWith(\"v\")) {\n throw new InvalidConfigurationError(`Version must not start with \"v\": ${version}`)\n }\n\n this.tag = info.vPrefixedTagName === false ? version : `v${version}`\n\n if (isEnvTrue(process.env.EP_DRAFT)) {\n this.releaseType = \"draft\"\n log.info({reason: \"env EP_DRAFT is set to true\"}, \"GitHub provider release type is set to draft\")\n }\n else if (isEnvTrue(process.env.EP_PRE_RELEASE) || isEnvTrue(process.env.EP_PRELEASE) /* https://github.com/electron-userland/electron-builder/issues/2878 */) {\n this.releaseType = \"prerelease\"\n log.info({reason: \"env EP_PRE_RELEASE is set to true\"}, \"GitHub provider release type is set to prerelease\")\n }\n else if (info.releaseType != null) {\n this.releaseType = info.releaseType\n }\n else if ((options as any).prerelease) {\n this.releaseType = \"prerelease\"\n }\n else {\n this.releaseType = (options as any).draft === false ? \"release\" : \"draft\"\n }\n }\n\n private async getOrCreateRelease(): Promise {\n const logFields = {\n tag: this.tag,\n version: this.version,\n }\n\n // 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\n const releases = await this.githubRequest>(`/repos/${this.info.owner}/${this.info.repo}/releases`, this.token)\n for (const release of releases) {\n if (!(release.tag_name === this.tag || release.tag_name === this.version)) {\n continue\n }\n\n if (release.draft) {\n return release\n }\n\n // https://github.com/electron-userland/electron-builder/issues/1197\n // https://github.com/electron-userland/electron-builder/issues/2072\n if (this.releaseType === \"draft\") {\n this.releaseLogFields = {\n reason: \"existing type not compatible with publishing type\",\n ...logFields,\n existingType: release.prerelease ? \"pre-release\" : \"release\",\n publishingType: this.releaseType,\n }\n log.warn(this.releaseLogFields, \"GitHub release not created\")\n return null\n }\n\n // https://github.com/electron-userland/electron-builder/issues/1133\n // https://github.com/electron-userland/electron-builder/issues/2074\n // if release created < 2 hours — allow to upload\n const publishedAt = release.published_at == null ? null : Date.parse(release.published_at)\n if (publishedAt != null && (Date.now() - publishedAt) > (2 * 3600 * 1000)) {\n // https://github.com/electron-userland/electron-builder/issues/1183#issuecomment-275867187\n this.releaseLogFields = {\n reason: \"existing release published more than 2 hours ago\",\n ...logFields,\n date: new Date(publishedAt).toString(),\n }\n log.warn(this.releaseLogFields, \"GitHub release not created\")\n return null\n }\n return release\n }\n\n // https://github.com/electron-userland/electron-builder/issues/1835\n if (this.options.publish === \"always\" || getCiTag() != null) {\n log.info({\n reason: \"release doesn't exist\",\n ...logFields,\n }, `creating GitHub release`)\n return this.createRelease()\n }\n\n this.releaseLogFields = {\n reason: \"release doesn't exist and not created because \\\"publish\\\" is not \\\"always\\\" and build is not on tag\",\n ...logFields,\n }\n return null\n }\n\n private async overwriteArtifact(fileName: string, release: Release) {\n // delete old artifact and re-upload\n log.warn({file: fileName, reason: \"already exists on GitHub\"}, \"overwrite published file\")\n\n const assets = await this.githubRequest>(`/repos/${this.info.owner}/${this.info.repo}/releases/${release.id}/assets`, this.token, null)\n for (const asset of assets) {\n if (asset!.name === fileName) {\n await this.githubRequest(`/repos/${this.info.owner}/${this.info.repo}/releases/assets/${asset!.id}`, this.token, null, \"DELETE\")\n return\n }\n }\n\n log.debug({file: fileName, reason: \"not found on GitHub\"}, \"trying to upload again\")\n }\n\n protected async doUpload(fileName: string, arch: Arch, dataLength: number, requestProcessor: (request: ClientRequest, reject: (error: Error) => void) => void): Promise {\n const release = await this._release.value\n if (release == null) {\n log.warn({file: fileName, ...this.releaseLogFields}, \"skipped publishing\")\n return\n }\n\n const parsedUrl = parseUrl(release.upload_url.substring(0, release.upload_url.indexOf(\"{\")) + \"?name=\" + fileName)\n return await this.doUploadFile(0, parsedUrl, fileName, dataLength, requestProcessor, release)\n }\n\n private doUploadFile(attemptNumber: number, parsedUrl: UrlWithStringQuery, fileName: string, dataLength: number, requestProcessor: (request: ClientRequest, reject: (error: Error) => void) => void, release: any): Promise {\n return httpExecutor.doApiRequest(configureRequestOptions({\n hostname: parsedUrl.hostname,\n path: parsedUrl.path,\n method: \"POST\",\n headers: {\n accept: \"application/vnd.github.v3+json\",\n \"Content-Type\": mime.getType(fileName) || \"application/octet-stream\",\n \"Content-Length\": dataLength\n }\n }, this.token), this.context.cancellationToken, requestProcessor)\n .catch(e => {\n if ((e as any).statusCode === 422 && e.description != null && e.description.errors != null && e.description.errors[0].code === \"already_exists\") {\n return this.overwriteArtifact(fileName, release)\n .then(() => this.doUploadFile(attemptNumber, parsedUrl, fileName, dataLength, requestProcessor, release))\n }\n\n if (attemptNumber > 3) {\n return Promise.reject(e)\n }\n else {\n return new Promise((resolve, reject) => {\n const newAttemptNumber = attemptNumber + 1\n setTimeout(() => {\n this.doUploadFile(newAttemptNumber, parsedUrl, fileName, dataLength, requestProcessor, release)\n .then(resolve)\n .catch(reject)\n }, newAttemptNumber * 2000)\n })\n }\n })\n }\n\n private createRelease() {\n return this.githubRequest(`/repos/${this.info.owner}/${this.info.repo}/releases`, this.token, {\n tag_name: this.tag,\n name: this.version,\n draft: this.releaseType === \"draft\",\n prerelease: this.releaseType === \"prerelease\",\n })\n }\n\n // test only\n //noinspection JSUnusedGlobalSymbols\n async getRelease(): Promise {\n return this.githubRequest(`/repos/${this.info.owner}/${this.info.repo}/releases/${(await this._release.value)!.id}`, this.token)\n }\n\n //noinspection JSUnusedGlobalSymbols\n async deleteRelease(): Promise {\n if (!this._release.hasValue) {\n return\n }\n\n const release = await this._release.value\n for (let i = 0; i < 3; i++) {\n try {\n return await this.githubRequest(`/repos/${this.info.owner}/${this.info.repo}/releases/${release.id}`, this.token, null, \"DELETE\")\n }\n catch (e) {\n if (e instanceof HttpError) {\n if (e.statusCode === 404) {\n log.warn({releaseId: release.id, reason: \"doesn't exist\"}, \"cannot delete release\")\n return\n }\n else if (e.statusCode === 405 || e.statusCode === 502) {\n continue\n }\n }\n\n throw e\n }\n }\n\n log.warn({releaseId: release.id}, \"cannot delete release\")\n }\n\n private githubRequest(path: string, token: string | null, data: {[name: string]: any; } | null = null, method?: \"GET\" | \"DELETE\" | \"PUT\"): Promise {\n // host can contains port, but node http doesn't support host as url does\n const baseUrl = parseUrl(`https://${this.info.host || \"api.github.com\"}`)\n return parseJson(httpExecutor.request(configureRequestOptions({\n hostname: baseUrl.hostname,\n port: baseUrl.port as any,\n path: (this.info.host != null && this.info.host !== \"github.com\") ? `/api/v3${path.startsWith(\"/\") ? path : `/${path}`}` : path,\n headers: {accept: \"application/vnd.github.v3+json\"}\n }, token, method), this.context.cancellationToken, data))\n }\n\n toString() {\n return `Github (owner: ${this.info.owner}, project: ${this.info.repo}, version: ${this.version})`\n }\n}\n"],"sourceRoot":""}