Skip to content
Permalink
Browse files

feat(publisher): add GitHub Enterprise/HTTP proxy support to the GitH…

…ub publisher

ISSUES CLOSED: #416
  • Loading branch information
malept committed Feb 5, 2018
1 parent e83832a commit 14151022f4b5860d6cc873a3c8f3b8027c732614
Showing with 38 additions and 10 deletions.
  1. +1 −1 README.md
  2. +1 −1 src/publishers/github.js
  3. +8 −7 src/util/github.js
  4. +28 −1 test/fast/github_spec.js
@@ -229,7 +229,7 @@ the JS file method mentioned above then you can use functions normally.

| Target Name | Description | Required Config |
|-------------|-------------|-----------------|
| GitHub Releases - `github` | Makes a new release for the current version (if required) and uploads the make artifacts as release assets | `process.env.GITHUB_TOKEN` - A personal access token with access to your releases <br />`forge.github_repository.owner` - The owner of the GitHub repository<br />`forge.github_repository.name` - The name of the GitHub repository <br />`forge.github_repository.draft` - Create the release as a draft, defaults to `true` <br />`forge.github_repository.prerelease` - Identify the release as a prerelease, defaults to `false` |
| GitHub Releases - `github` | Makes a new release for the current version (if required) and uploads the make artifacts as release assets | `process.env.GITHUB_TOKEN` - A personal access token with access to your releases <br />`forge.github_repository.owner` - The owner of the GitHub repository<br />`forge.github_repository.name` - The name of the GitHub repository <br />`forge.github_repository.draft` - Create the release as a draft, defaults to `true` <br />`forge.github_repository.prerelease` - Identify the release as a prerelease, defaults to `false` <br />`forge.github_repository.options` - An `Object` of [connection options](https://github.com/octokit/rest.js#usage), e.g., GitHub Enterprise settings or HTTP proxy URL |
| Amazon S3 - `s3` | Uploads your artifacts to the given S3 bucket | `process.env.ELECTRON_FORGE_S3_SECRET_ACCESS_KEY` - Your secret access token for your AWS account _(falls back to the standard `AWS_SECRET_ACCESS_KEY` environment variable)_<br />`forge.s3.accessKeyId` - Your access key for your AWS account _(falls back to the standard `AWS_ACCESS_KEY_ID` environment variable)_<br />`forge.s3.bucket` - The name of the S3 bucket to upload to<br />`forge.s3.folder` - The folder path to upload to inside your bucket, defaults to your application version<br />`forge.s3.public` - Whether to make the S3 upload public, defaults to `false` |
| [Electron Release Server](https://github.com/ArekSredzki/electron-release-server) - `electron-release-server` | Makes a new release for the current version and uploads the artifacts to the correct platform/arch in the given version. If the version already exists no upload will be performed. The channel is determined from the current version. | `forge.electronReleaseServer.baseUrl` - The base URL of your release server, no trailing slash<br />`forge.electronReleaseServer.username` - The username for the admin panel on your server<br />`forge.electronReleaseServer.password` - The password for the admin panel on your server |
| [Snapcraft](https://snapcraft.io/store/) - `snapStore` | Uploads generated Snaps to the Snap Store. | `forge.snapStore.release` - If specified, a comma-separated list of channels to release to. |
@@ -11,7 +11,7 @@ export default async ({ artifacts, packageJSON, forgeConfig, authToken, tag }) =
throw 'In order to publish to github you must set the "github_repository.owner" and "github_repository.name" properties in your forge config. See the docs for more info'; // eslint-disable-line
}

const github = new GitHub(authToken, true);
const github = new GitHub(authToken, true, forgeConfig.github_repository.options);

let release;
await asyncOra('Searching for target release', async () => {
@@ -1,7 +1,13 @@
import GitHubAPI from '@octokit/rest';
import merge from 'lodash.merge';

export default class GitHub {
constructor(authToken, requireAuth) {
constructor(authToken, requireAuth, options = {}) {
this.options = merge(
{ protocol: 'https' },
options,
{ headers: { 'user-agent': 'Electron Forge' } }
);
if (authToken) {
this.token = authToken;
} else if (process.env.GITHUB_TOKEN) {
@@ -12,12 +18,7 @@ export default class GitHub {
}

getGitHub() {
const github = new GitHubAPI({
protocol: 'https',
headers: {
'user-agent': 'Electron Forge',
},
});
const github = new GitHubAPI(this.options);
if (this.token) {
github.authenticate({
type: 'token',
@@ -12,8 +12,9 @@ describe('GitHub', () => {
gitHubSpy = sinon.spy();
gitHubAuthSpy = sinon.spy();
MockGitHub = class {
constructor() {
constructor(options) {
gitHubSpy();
this.options = options;
}

authenticate() {
@@ -43,6 +44,32 @@ describe('GitHub', () => {
expect(gitHubSpy.callCount).to.equal(1);
});

it('should be able to set the Enterprise URL settings', () => {
const gh = new GitHub('1234', true, {
host: 'github.example.com',
port: 8443,
pathPrefix: '/enterprise',
});
const api = gh.getGitHub();

expect(api.options).to.deep.equal({
protocol: 'https',
host: 'github.example.com',
port: 8443,
pathPrefix: '/enterprise',
headers: {
'user-agent': 'Electron Forge',
},
});
});

it('should not override the user agent', () => {
const gh = new GitHub('1234', true, { headers: { 'user-agent': 'Something' } });
const api = gh.getGitHub();

expect(api.options.headers['user-agent']).to.equal('Electron Forge');
});

it('should authenticate if a token is present', () => {
const gh = new GitHub('token');
expect(gitHubAuthSpy.callCount).to.equal(0);

0 comments on commit 1415102

Please sign in to comment.
You can’t perform that action at this time.