Skip to content

Commit

Permalink
feat: GitHub Enterprise support
Browse files Browse the repository at this point in the history
Close #1225
  • Loading branch information
develar committed Feb 9, 2017
1 parent d5c48be commit 7cae06a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
2 changes: 2 additions & 0 deletions docs/Publishing Artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ Amazon S3 — `https` must be used, so, if you use direct Amazon S3 endpoints, f
| --- | ---
| repo | <a name="GithubOptions-repo"></a>The repository name. [Detected automatically](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts#github-repository).
| vPrefixedTagName | <a name="GithubOptions-vPrefixedTagName"></a>Whether to use `v`-prefixed tag name. Defaults to `true`.
| host | <a name="GithubOptions-host"></a>The host (including the port if need). Defaults to `github.com`.
| protocol | <a name="GithubOptions-protocol"></a><p>The protocol, one of <code>https</code> or <code>http</code>. Defaults to <code>https</code>.</p> <p>GitHub Publisher supports only <code>https</code>.</p>

<a name="S3Options"></a>
### `publish` S3
Expand Down
16 changes: 16 additions & 0 deletions packages/electron-builder-http/src/publishOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"}`
}

/*
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder-publisher/src/gitHubPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ export class GitHubPublisher extends HttpPublisher {

private githubRequest<T>(path: string, token: string | null, data: {[name: string]: any; } | null = null, method?: "GET" | "DELETE" | "PUT"): Promise<T> {
return httpExecutor.request<T>(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)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/appInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
}
}
4 changes: 2 additions & 2 deletions packages/electron-builder/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -298,7 +298,7 @@ export function computeDownloadUrl(publishConfig: PublishConfiguration, fileName
}
else {
const gh = <GithubOptions>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) {
Expand Down
12 changes: 7 additions & 5 deletions packages/electron-updater/src/GitHubProvider.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -15,11 +15,13 @@ export class GitHubProvider extends Provider<VersionInfo> {
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<GithubReleaseInfo>({
hostname: "github.com",
protocol: protocol,
host: host,
path: `${basePath}/latest`,
headers: Object.assign({Accept: "application/json"}, this.requestHeaders)
}, cancellationToken))
Expand All @@ -33,7 +35,7 @@ export class GitHubProvider extends Provider<VersionInfo> {
const channelFile = getChannelFilename(getDefaultChannelName())
const channelFileUrlPath = `${basePath}/download/v${version}/${channelFile}`
try {
result = await request<UpdateInfo>({hostname: "github.com", path: channelFileUrlPath, headers: this.requestHeaders || undefined}, cancellationToken)
result = await request<UpdateInfo>({protocol: protocol, host: host, path: channelFileUrlPath, headers: this.requestHeaders || undefined}, cancellationToken)
}
catch (e) {
if (e instanceof HttpError && e.response.statusCode === 404) {
Expand All @@ -44,7 +46,7 @@ export class GitHubProvider extends Provider<VersionInfo> {

validateUpdateInfo(result)
if (getCurrentPlatform() === "darwin") {
result.releaseJsonUrl = `https://github.com${channelFileUrlPath}`
result.releaseJsonUrl = `${githubUrl(this.options)}/${channelFileUrlPath}`
}
return result
}
Expand Down

0 comments on commit 7cae06a

Please sign in to comment.