Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/atom-items/issueish-pane-item.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Emitter} from 'atom';
import {Emitter} from 'event-kit';

import url from 'url';

Expand Down
2 changes: 1 addition & 1 deletion lib/controllers/editor-conflict-controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CompositeDisposable} from 'atom';
import {CompositeDisposable} from 'event-kit';
import React from 'react';
import {autobind} from 'core-decorators';
import compareSets from 'compare-sets';
Expand Down
3 changes: 2 additions & 1 deletion lib/controllers/file-patch-controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';

import {Point, Emitter} from 'atom';
import {Point} from 'atom';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, this import still works? I thought you'd meant that none of the Atom imports would work properly when bundled. Does it just have to do with the timing of when Emitter and CompositeDisposable are installed in the Atom global?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use Point after activation, so it works fine. We had to bring in event-kit for Emitter and friends in other places, so it made sense to replace it package-wide.

import {Emitter} from 'event-kit';
import {autobind} from 'core-decorators';

import Switchboard from '../switchboard';
Expand Down
22 changes: 1 addition & 21 deletions lib/controllers/pr-info-controller.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
import React from 'react';
import Relay from 'react-relay';

import {RemotePropType} from '../prop-types';
import RelayRootContainer from '../containers/relay-root-container';
import PrListContainer from '../containers/pr-list-container';
import GithubLoginView from '../views/github-login-view';
import PrInfoByBranchRoute from '../routes/pr-info-by-branch-route';
import RelayNetworkLayerManager from '../relay-network-layer-manager';
import {UNAUTHENTICATED} from '../models/github-login-model';

class PrInfoByBranchRoute extends Relay.Route {
static routeName = 'pr-info-route'

static queries = {
query: (Component, variables) => Relay.QL`
query {
relay {
${Component.getFragment('query', variables)}
}
}
`,
}

static paramDefinitions = {
repoOwner: {required: true},
repoName: {required: true},
branchName: {required: true},
}
}

export default class PrInfoController extends React.Component {
static propTypes = {
token: React.PropTypes.oneOfType([
Expand Down
2 changes: 1 addition & 1 deletion lib/controllers/repository-conflict-controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import React from 'react';
import yubikiri from 'yubikiri';
import {CompositeDisposable} from 'atom';
import {CompositeDisposable} from 'event-kit';

import ObserveModelDecorator from '../decorators/observe-model';
import ResolutionProgress from '../models/conflicts/resolution-progress';
Expand Down
3 changes: 2 additions & 1 deletion lib/controllers/root-controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import fs from 'fs';
import path from 'path';

import {CompositeDisposable, Disposable, File} from 'atom';
import {File} from 'atom';
import {CompositeDisposable, Disposable} from 'event-kit';

import React from 'react';
import {autobind} from 'core-decorators';
Expand Down
6 changes: 3 additions & 3 deletions lib/git-prompt-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import net from 'net';
import path from 'path';
import os from 'os';

import {Emitter} from 'atom';
import {Emitter} from 'event-kit';

import {deleteFileOrFolder, getTempDir, copyFile} from './helpers';
import {getPackageRoot, deleteFileOrFolder, getTempDir, copyFile} from './helpers';

function getAtomHelperPath() {
if (process.platform === 'darwin') {
Expand Down Expand Up @@ -41,7 +41,7 @@ export default class GitPromptServer {

await Promise.all(
Object.keys(sourceFiles).map(filename => copyFile(
path.resolve(__dirname, '..', 'bin', filename),
path.resolve(getPackageRoot(), 'bin', filename),
path.join(this.tmpFolderPath, filename),
).then(sourceFiles[filename])),
);
Expand Down
11 changes: 5 additions & 6 deletions lib/git-shell-out-strategy.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import path from 'path';
import os from 'os';

import {CompositeDisposable} from 'atom';
import {CompositeDisposable} from 'event-kit';

import {GitProcess} from 'git-kitchen-sink';
import {GitProcess} from 'dugite';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks for getting this upgrade in here 😄

import {parse as parseDiff} from 'what-the-diff';

import GitPromptServer from './git-prompt-server';
import AsyncQueue from './async-queue';
import {readFile, fileExists, writeFile, isFileExecutable} from './helpers';
import {getPackageRoot, getDugitePath, readFile, fileExists, writeFile, isFileExecutable} from './helpers';
import GitTimingsView from './views/git-timings-view';

const LINE_ENDING_REGEX = /\r?\n/;

const GPG_HELPER_PATH = path.resolve(__dirname, '..', 'bin', 'gpg-no-tty.sh');
const DUGITE_PATH = require.resolve('git-kitchen-sink');
const GPG_HELPER_PATH = path.resolve(getPackageRoot(), 'bin', 'gpg-no-tty.sh');

export class GitError extends Error {
constructor(message) {
Expand Down Expand Up @@ -100,7 +99,7 @@ export default class GitShellOutStrategy {
env.ATOM_GITHUB_SOCK_PATH = normalizePath(socket);

env.ATOM_GITHUB_WORKDIR_PATH = this.workingDir;
env.ATOM_GITHUB_DUGITE_PATH = DUGITE_PATH;
env.ATOM_GITHUB_DUGITE_PATH = path.join(getDugitePath(), 'git', 'bin', 'git');

// "ssh" won't respect SSH_ASKPASS unless:
// (a) it's running without a tty
Expand Down
3 changes: 2 additions & 1 deletion lib/github-package.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {CompositeDisposable, Disposable, File} from 'atom';
import {File} from 'atom';
import {CompositeDisposable, Disposable} from 'event-kit';

import path from 'path';

Expand Down
38 changes: 36 additions & 2 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
import path from 'path';
import fs from 'fs-extra';
import {ncp} from 'ncp';

export function getPackageRoot() {
const {resourcePath} = atom.getLoadSettings();
const currentFileWasRequiredFromSnapshot = !path.isAbsolute(__dirname);
if (currentFileWasRequiredFromSnapshot) {
return path.join(resourcePath, 'node_modules', 'github');
} else {
const packageRoot = path.resolve(__dirname, '..');
if (path.extname(resourcePath) === '.asar') {
if (packageRoot.indexOf(resourcePath) === 0) {
return path.join(`${resourcePath}.unpacked`, 'node_modules', 'github');
}
}
return packageRoot;
}
}

let DUGITE_PATH;
export function getDugitePath() {
if (!DUGITE_PATH) {
DUGITE_PATH = require.resolve('dugite');
if (!path.isAbsolute(DUGITE_PATH)) {
// Assume we're snapshotted
const {resourcePath} = atom.getLoadSettings();
if (path.extname(resourcePath) === '.asar') {
DUGITE_PATH = path.join(`${resourcePath}.unpacked`, 'node_modules', 'dugite');
} else {
DUGITE_PATH = path.join(resourcePath, 'node_modules', 'dugite');
}
}
}

return DUGITE_PATH;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 cool, cool


function descriptorsFromProto(proto) {
return Object.getOwnPropertyNames(proto).reduce((acc, name) => {
Expand Down Expand Up @@ -99,9 +133,9 @@ export function writeFile(absoluteFilePath, contents) {
});
}

export function deleteFileOrFolder(path) {
export function deleteFileOrFolder(fileOrFolder) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆 I always do this. "path" is such a natural name to use as a variable...

return new Promise((resolve, reject) => {
fs.remove(path, err => {
fs.remove(fileOrFolder, err => {
if (err) { return reject(err); } else { return resolve(); }
});
});
Expand Down
61 changes: 21 additions & 40 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,26 @@
/* eslint-disable no-var */
import GithubPackage from './github-package';

var semver = require('semver');
let pack;
const entry = {
activate(...args) {
pack.activate(...args);
},

var v = semver.parse(atom.appVersion);
var atomVersion = [v.major, v.minor, v.patch].join('.');
var requiredVersion = '>=1.13.0';
initialize() {
pack = new GithubPackage(
atom.workspace, atom.project, atom.commands, atom.notifications, atom.tooltips,
atom.styles, atom.config, atom.confirm.bind(atom),
);
},
};

if (atom.inDevMode() || atom.inSpecMode() || semver.satisfies(atomVersion, requiredVersion)) {
module.exports = startPackage();
} else {
module.exports = versionMismatch();
}

function versionMismatch() {
return {
activate: () => {
atom.notifications.addWarning('Incompatible Atom Version', {
description: 'The GitHub packages requires Atom ' + requiredVersion +
'. You are running ' + atomVersion + '. Please check for updates and try again.',
dismissable: true,
});
},
[
'serialize', 'deserialize', 'deactivate', 'consumeStatusBar',
'createGitTimingsView', 'createIssueishPaneItem',
].forEach(method => {
entry[method] = (...args) => {
return pack[method](...args);
};
}

function startPackage() {
var GithubPackage = require('./github-package').default;

if (atom.inDevMode()) {
// Let's install some devTools
try {
const electronDevtoolsInstaller = require('electron-devtools-installer');
const installExtension = electronDevtoolsInstaller.default;
installExtension(electronDevtoolsInstaller.REACT_DEVELOPER_TOOLS);
} catch (_e) {
// Nothing
}
}
});

return new GithubPackage(
atom.workspace, atom.project, atom.commands, atom.notifications, atom.tooltips,
atom.styles, atom.config, atom.confirm.bind(atom),
);
}
module.exports = entry;
2 changes: 1 addition & 1 deletion lib/models/conflicts/resolution-progress.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Emitter} from 'atom';
import {Emitter} from 'event-kit';

export default class ResolutionProgress {
static empty() {
Expand Down
2 changes: 1 addition & 1 deletion lib/models/file-system-change-observer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Emitter} from 'atom';
import {Emitter} from 'event-kit';
import nsfw from 'nsfw';

import path from 'path';
Expand Down
20 changes: 15 additions & 5 deletions lib/models/github-login-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {execFile} from 'child_process';

import keytar from 'keytar';

import {Emitter} from 'atom';
import {Emitter} from 'event-kit';

export const UNAUTHENTICATED = Symbol('UNAUTHENTICATED');

Expand Down Expand Up @@ -107,12 +107,22 @@ export default class GithubLoginModel {
return instance;
}

constructor(Strategy = strategies.find(strat => strat.isValid())) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this check to the first time we actually try to use the strategy saves around ~100ms on the package's initial render (called from activate).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option might be to default to the real Keytar strategy and toggle to the shelling-out one with an environment variable or a (hidden?) config setting. Annoying for those of us who run master, but it'd keep us from paying any performance penalty for the common case of being bundled in a proper Atom distro.

constructor(Strategy) {
this._Strategy = Strategy;
this._strategy = null;
this.emitter = new Emitter();
if (!Strategy) {
throw new Error('None of the listed GithubLoginModel strategies returned true for `isValid`');
}

get strategy() {
if (!this._strategy) {
const Strategy = this._Strategy || strategies.find(strat => strat.isValid());
if (!Strategy) {
throw new Error('None of the listed GithubLoginModel strategies returned true for `isValid`');
}
this._strategy = new Strategy();
}
this.strategy = new Strategy();

return this._strategy;
}

async getToken(account) {
Expand Down
2 changes: 1 addition & 1 deletion lib/models/repository.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs-extra';
import path from 'path';

import {Emitter, Disposable} from 'atom';
import {Emitter, Disposable} from 'event-kit';
import {autobind} from 'core-decorators';

import CompositeGitStrategy from '../composite-git-strategy';
Expand Down
2 changes: 1 addition & 1 deletion lib/models/style-calculator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CompositeDisposable} from 'atom';
import {CompositeDisposable} from 'event-kit';

import {autobind} from 'core-decorators';

Expand Down
2 changes: 1 addition & 1 deletion lib/models/workspace-change-observer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CompositeDisposable, Disposable, Emitter} from 'atom';
import {CompositeDisposable, Disposable, Emitter} from 'event-kit';

import nsfw from 'nsfw';
import {autobind} from 'core-decorators';
Expand Down
21 changes: 21 additions & 0 deletions lib/routes/pr-info-by-branch-route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Relay from 'react-relay';

export default class PrInfoByBranchRoute extends Relay.Route {
static routeName = 'pr-info-route'

static queries = {
query: (Component, variables) => Relay.QL`
query {
relay {
${Component.getFragment('query', variables)}
}
}
`,
}

static paramDefinitions = {
repoOwner: {required: true},
repoName: {required: true},
branchName: {required: true},
}
}
2 changes: 1 addition & 1 deletion lib/views/clone-dialog.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import {autobind} from 'core-decorators';
import {CompositeDisposable} from 'atom';
import {CompositeDisposable} from 'event-kit';
import url from 'url';
import path from 'path';

Expand Down
5 changes: 3 additions & 2 deletions lib/views/commit-view.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/** @jsx etch.dom */
/* eslint react/no-unknown-property: "off" */

import {CompositeDisposable, TextEditor} from 'atom';
import {TextEditor} from 'atom';
import {CompositeDisposable} from 'event-kit';

import etch from 'etch';
import {autobind} from 'core-decorators';
Expand Down Expand Up @@ -119,7 +120,7 @@ export default class CommitView {
return '∞';
}
} else {
return this.props.maximumCharacterLimit;
return this.props.maximumCharacterLimit || '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/views/decoration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {CompositeDisposable} from 'atom';
import {CompositeDisposable} from 'event-kit';

import Portal from './portal';

Expand Down
2 changes: 1 addition & 1 deletion lib/views/file-patch-view.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import {CompositeDisposable, Disposable} from 'atom';
import {CompositeDisposable, Disposable} from 'event-kit';
import cx from 'classnames';
import {autobind} from 'core-decorators';

Expand Down
2 changes: 1 addition & 1 deletion lib/views/git-tab-view.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @jsx etch.dom */
/* eslint react/no-unknown-property: "off" */

import {Disposable, CompositeDisposable} from 'atom';
import {Disposable, CompositeDisposable} from 'event-kit';

import etch from 'etch';
import {autobind} from 'core-decorators';
Expand Down
Loading