Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Merge ceb99a3 into 51dac31
Browse files Browse the repository at this point in the history
  • Loading branch information
kuychaco committed Sep 11, 2018
2 parents 51dac31 + ceb99a3 commit 98b67af
Show file tree
Hide file tree
Showing 6 changed files with 289 additions and 141 deletions.
2 changes: 2 additions & 0 deletions lib/controllers/commit-controller.js
Expand Up @@ -9,6 +9,7 @@ import CommitView from '../views/commit-view';
import RefHolder from '../models/ref-holder';
import {AuthorPropType, UserStorePropType} from '../prop-types';
import {autobind} from '../helpers';
import {addEvent} from '../reporter-proxy';

export const COMMIT_GRAMMAR_SCOPE = 'text.git-commit';

Expand Down Expand Up @@ -219,6 +220,7 @@ export default class CommitController extends React.Component {
async openCommitMessageEditor(messageFromBox) {
await fs.writeFile(this.getCommitMessagePath(), messageFromBox, 'utf8');
const commitEditor = await this.props.workspace.open(this.getCommitMessagePath());
addEvent('open-commit-message-editor', {package: 'github'});

const grammar = this.props.grammars.grammarForScopeName(COMMIT_GRAMMAR_SCOPE);
if (grammar) {
Expand Down
39 changes: 26 additions & 13 deletions lib/models/repository-states/present.js
Expand Up @@ -17,6 +17,7 @@ import Remote from '../remote';
import RemoteSet from '../remote-set';
import Commit from '../commit';
import OperationStates from '../operation-states';
import {addEvent} from '../../reporter-proxy';

/**
* State used when the working directory contains a valid git repository and can be interacted with. Performs
Expand Down Expand Up @@ -233,17 +234,28 @@ export default class Present extends State {
Keys.branches,
],
// eslint-disable-next-line no-shadow
() => this.executePipelineAction('COMMIT', (message, options) => {
const opts = (!options || !options.coAuthors)
? options
: {
...options,
coAuthors: options.coAuthors.map(author => {
return {email: author.getEmail(), name: author.getFullName()};
}),
};
() => this.executePipelineAction('COMMIT', async (message, options = {}) => {
const coAuthors = options.coAuthors;
const opts = !coAuthors ? options : {
...options,
coAuthors: coAuthors.map(author => {
return {email: author.getEmail(), name: author.getFullName()};
}),
};

return this.git().commit(message, opts);
await this.git().commit(message, opts);

// Collect commit metadata metrics
// note: in GitShellOutStrategy we have counters for all git commands, including `commit`, but here we have
// access to additional metadata (unstaged file count) so it makes sense to collect commit events here
const {unstagedFiles, mergeConflictFiles} = await this.getStatusesForChangedFiles();
const unstagedCount = Object.keys({...unstagedFiles, ...mergeConflictFiles}).length;
addEvent('commit', {
package: 'github',
partial: unstagedCount > 0,
amend: !!options.amend,
coAuthorCount: coAuthors ? coAuthors.length : 0,
});
}, message, options),
);
}
Expand Down Expand Up @@ -344,6 +356,7 @@ export default class Present extends State {
async () => {
try {
await this.git().reset('soft', 'HEAD~');
addEvent('undo-last-commit', {package: 'github'});
} catch (e) {
if (/unknown revision/.test(e.stdErr)) {
// Initial commit
Expand Down Expand Up @@ -528,9 +541,9 @@ export default class Present extends State {
this.transitionTo('TooLarge');
return {
branch: {},
stagedFiles: [],
unstagedFiles: [],
mergeConflictFiles: [],
stagedFiles: {},
unstagedFiles: {},
mergeConflictFiles: {},
};
} else {
throw err;
Expand Down

0 comments on commit 98b67af

Please sign in to comment.