diff --git a/docs/Publishing Artifacts.md b/docs/Publishing Artifacts.md index 47abcbb5cd5..1a8109bfcd5 100644 --- a/docs/Publishing Artifacts.md +++ b/docs/Publishing Artifacts.md @@ -110,6 +110,8 @@ Amazon S3 — `https` must be used, so, if you use direct Amazon S3 endpoints, f | --- | --- | repo | The repository name. [Detected automatically](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts#github-repository). | vPrefixedTagName | Whether to use `v`-prefixed tag name. Defaults to `true`. +| host | The host (including the port if need). Defaults to `github.com`. +| protocol |

The protocol, one of https or http. Defaults to https.

GitHub Publisher supports only https.

### `publish` S3 diff --git a/packages/electron-builder-http/src/publishOptions.ts b/packages/electron-builder-http/src/publishOptions.ts index 0d4a7d830bb..db06d76584b 100644 --- a/packages/electron-builder-http/src/publishOptions.ts +++ b/packages/electron-builder-http/src/publishOptions.ts @@ -113,6 +113,22 @@ export interface GithubOptions extends PublishConfiguration { Whether to use `v`-prefixed tag name. Defaults to `true`. */ vPrefixedTagName?: boolean + + /* + The host (including the port if need). Defaults to `github.com`. + */ + host?: string | null + + /* + The protocol, one of `https` or `http`. Defaults to `https`. + + GitHub Publisher supports only `https`. + */ + protocol?: string | null +} + +export function githubUrl(options: GithubOptions) { + return `${options.protocol || "https"}://${options.host || "github.com"}` } /* diff --git a/packages/electron-builder-publisher/src/gitHubPublisher.ts b/packages/electron-builder-publisher/src/gitHubPublisher.ts index 76529abeb6a..664300482db 100644 --- a/packages/electron-builder-publisher/src/gitHubPublisher.ts +++ b/packages/electron-builder-publisher/src/gitHubPublisher.ts @@ -188,8 +188,8 @@ export class GitHubPublisher extends HttpPublisher { private githubRequest(path: string, token: string | null, data: {[name: string]: any; } | null = null, method?: "GET" | "DELETE" | "PUT"): Promise { return httpExecutor.request(configureRequestOptions({ - hostname: "api.github.com", - path: path, + host: this.info.host || "api.github.com", + path: (this.info.host != null && this.info.host !== "github.com") ? `/api/v3/${path}` : path, headers: {Accept: "application/vnd.github.v3+json"} }, token, method), this.context.cancellationToken, data) } diff --git a/packages/electron-builder/src/appInfo.ts b/packages/electron-builder/src/appInfo.ts index 2e9cf05a250..e9e3bc602b2 100644 --- a/packages/electron-builder/src/appInfo.ts +++ b/packages/electron-builder/src/appInfo.ts @@ -89,6 +89,6 @@ export class AppInfo { } const info = await this.info.repositoryInfo - return info == null ? null : `https://github.com/${info.user}/${info.project}` + return info == null || info.type !== "github" ? null : `https://${info.domain}/${info.user}/${info.project}` } } \ No newline at end of file diff --git a/packages/electron-builder/src/publish/PublishManager.ts b/packages/electron-builder/src/publish/PublishManager.ts index 99af515a324..e8c4684d07b 100644 --- a/packages/electron-builder/src/publish/PublishManager.ts +++ b/packages/electron-builder/src/publish/PublishManager.ts @@ -1,7 +1,7 @@ import BluebirdPromise from "bluebird-lst-c" import { createHash } from "crypto" import { Arch, Platform } from "electron-builder-core" -import { GenericServerOptions, GithubOptions, PublishConfiguration, S3Options, UpdateInfo, VersionInfo, s3Url } from "electron-builder-http/out/publishOptions" +import { GenericServerOptions, GithubOptions, PublishConfiguration, S3Options, UpdateInfo, VersionInfo, s3Url, githubUrl } from "electron-builder-http/out/publishOptions" import { asArray, debug, isEmptyOrSpaces } from "electron-builder-util" import { log } from "electron-builder-util/out/log" import { throwError } from "electron-builder-util/out/promise" @@ -298,7 +298,7 @@ export function computeDownloadUrl(publishConfig: PublishConfiguration, fileName } else { const gh = publishConfig - baseUrl = `https://github.com${`/${gh.owner}/${gh.repo}/releases`}/download/v${version}` + baseUrl = `${githubUrl(gh)}/${gh.owner}/${gh.repo}/releases/download/v${version}` } if (fileName == null) { diff --git a/packages/electron-updater/src/GitHubProvider.ts b/packages/electron-updater/src/GitHubProvider.ts index 60ef1af26cc..5d853f4af1e 100644 --- a/packages/electron-updater/src/GitHubProvider.ts +++ b/packages/electron-updater/src/GitHubProvider.ts @@ -1,5 +1,5 @@ import { Provider, FileInfo, getDefaultChannelName, getChannelFilename, getCurrentPlatform } from "./api" -import { VersionInfo, GithubOptions, UpdateInfo } from "electron-builder-http/out/publishOptions" +import { VersionInfo, GithubOptions, UpdateInfo, githubUrl } from "electron-builder-http/out/publishOptions" import { validateUpdateInfo } from "./GenericProvider" import * as path from "path" import { HttpError, request } from "electron-builder-http" @@ -15,11 +15,13 @@ export class GitHubProvider extends Provider { let version const cancellationToken = new CancellationToken() - + const host = this.options.host || "github.com" + const protocol = `${this.options.protocol || "https"}:` try { // do not use API to avoid limit const releaseInfo = (await request({ - hostname: "github.com", + protocol: protocol, + host: host, path: `${basePath}/latest`, headers: Object.assign({Accept: "application/json"}, this.requestHeaders) }, cancellationToken)) @@ -33,7 +35,7 @@ export class GitHubProvider extends Provider { const channelFile = getChannelFilename(getDefaultChannelName()) const channelFileUrlPath = `${basePath}/download/v${version}/${channelFile}` try { - result = await request({hostname: "github.com", path: channelFileUrlPath, headers: this.requestHeaders || undefined}, cancellationToken) + result = await request({protocol: protocol, host: host, path: channelFileUrlPath, headers: this.requestHeaders || undefined}, cancellationToken) } catch (e) { if (e instanceof HttpError && e.response.statusCode === 404) { @@ -44,7 +46,7 @@ export class GitHubProvider extends Provider { validateUpdateInfo(result) if (getCurrentPlatform() === "darwin") { - result.releaseJsonUrl = `https://github.com${channelFileUrlPath}` + result.releaseJsonUrl = `${githubUrl(this.options)}/${channelFileUrlPath}` } return result }