Skip to content

Commit

Permalink
fix(electron-updater): Electron-updater does not support enterprise G…
Browse files Browse the repository at this point in the history
…ithub

Close #1903
  • Loading branch information
develar committed Sep 1, 2017
1 parent a7ea361 commit c3c613b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/electron-builder-http/src/publishOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export interface GithubOptions extends PublishConfiguration {
}

/** @private */
export function githubUrl(options: GithubOptions) {
return `${options.protocol || "https"}://${options.host || "github.com"}`
export function githubUrl(options: GithubOptions, defaultHost: string = "github.com") {
return `${options.protocol || "https"}://${options.host || defaultHost}`
}

/**
Expand Down
10 changes: 7 additions & 3 deletions packages/electron-updater/src/GitHubProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export abstract class BaseGitHubProvider<T extends UpdateInfo> extends Provider<
// so, we don't need to parse port (because node http doesn't support host as url does)
protected readonly baseUrl: RequestOptions

constructor(protected readonly options: GithubOptions, baseHost: string) {
constructor(protected readonly options: GithubOptions, defaultHost: string) {
super()

const baseUrl = parseUrl(`${options.protocol || "https"}://${options.host || baseHost}`)
const baseUrl = parseUrl(githubUrl(options, defaultHost))
this.baseUrl = {
protocol: baseUrl.protocol,
hostname: baseUrl.hostname,
Expand Down Expand Up @@ -120,7 +120,10 @@ export class GitHubProvider extends BaseGitHubProvider<UpdateInfo> {
}

private get basePath() {
return `/${this.options.owner}/${this.options.repo}/releases`
const result = `/${this.options.owner}/${this.options.repo}/releases`
// https://github.com/electron-userland/electron-builder/issues/1903#issuecomment-320881211
const host = this.options.host
return host != null && host !== "github.com" && host !== "api.github.com" ? `/api/v3${result}` : result
}

async getUpdateFile(versionInfo: UpdateInfo): Promise<FileInfo> {
Expand All @@ -130,6 +133,7 @@ export class GitHubProvider extends BaseGitHubProvider<UpdateInfo> {

// space is not supported on GitHub
const name = versionInfo.githubArtifactName || path.posix.basename(versionInfo.path).replace(/ /g, "-")
// noinspection JSDeprecatedSymbols
return {
name,
url: formatUrl({path: this.getBaseDownloadPath(versionInfo.version, name), ...this.baseUrl} as any),
Expand Down

0 comments on commit c3c613b

Please sign in to comment.