Skip to content

Commit fe4a1c7

Browse files
authored
Git metrics (#2062)
* chore: add git metrics * chore: git branch operations metrics * fix: refersh git used to send git project metrics without project switch * chore: git commit metrics * chore: metrics for git next, prev change and history * chore: all git metrics done
1 parent ffe2fe2 commit fe4a1c7

File tree

13 files changed

+163
-46
lines changed

13 files changed

+163
-46
lines changed

src/extensions/default/Git/src/Branch.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ define(function (require, exports) {
1212
StringUtils = brackets.getModule("utils/StringUtils"),
1313
DocumentManager = brackets.getModule("document/DocumentManager"),
1414
Strings = brackets.getModule("strings"),
15+
Metrics = brackets.getModule("utils/Metrics"),
1516
MainViewManager = brackets.getModule("view/MainViewManager");
1617

1718
var Git = require("src/git/Git"),
1819
Events = require("src/Events"),
1920
EventEmitter = require("src/EventEmitter"),
2021
ErrorHandler = require("src/ErrorHandler"),
2122
Panel = require("src/Panel"),
22-
Setup = require("src/utils/Setup"),
23+
Setup = require("src/utils/Setup"),
2324
Preferences = require("src/Preferences"),
2425
ProgressDialog = require("src/dialogs/Progress"),
2526
Utils = require("src/Utils"),
@@ -105,22 +106,25 @@ define(function (require, exports) {
105106
if (useRebase) {
106107

107108
Git.rebaseInit(fromBranch).catch(function (err) {
109+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'rebase', "fail");
108110
throw ErrorHandler.showError(err, Strings.ERROR_REBASE_FAILED);
109111
}).then(function (stdout) {
112+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'rebase', "success");
110113
Utils.showOutput(stdout || Strings.GIT_REBASE_SUCCESS, Strings.REBASE_RESULT).finally(function () {
111114
EventEmitter.emit(Events.REFRESH_ALL);
112115
});
113-
114-
});
116+
}).catch(console.error);
115117
} else {
116118

117119
Git.mergeBranch(fromBranch, mergeMsg, useNoff).catch(function (err) {
120+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'merge', "fail");
118121
throw ErrorHandler.showError(err, Strings.ERROR_MERGE_FAILED);
119122
}).then(function (stdout) {
123+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'merge', "success");
120124
Utils.showOutput(stdout || Strings.GIT_MERGE_SUCCESS, Strings.MERGE_RESULT).finally(function () {
121125
EventEmitter.emit(Events.REFRESH_ALL);
122126
});
123-
});
127+
}).catch(console.error);
124128
}
125129
}
126130
});
@@ -218,8 +222,10 @@ define(function (require, exports) {
218222
track = !!isRemote;
219223

220224
Git.createBranch(branchName, originName, track).catch(function (err) {
225+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'branch', "createFail");
221226
throw ErrorHandler.showError(err, Strings.ERROR_CREATE_BRANCH);
222227
}).then(function () {
228+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'branch', "create");
223229
EventEmitter.emit(Events.REFRESH_ALL);
224230
});
225231
}
@@ -246,8 +252,10 @@ define(function (require, exports) {
246252
}).then(function (response) {
247253
if (response === true) {
248254
return Git.forceBranchDelete(branchName).then(function (output) {
255+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'branch', "delete");
249256
return Utils.showOutput(output || Strings.GIT_BRANCH_DELETE_SUCCESS);
250257
}).catch(function (err) {
258+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'branch', "deleteFail");
251259
ErrorHandler.showError(err, Strings.ERROR_BRANCH_DELETE_FORCED);
252260
});
253261
}
@@ -273,12 +281,15 @@ define(function (require, exports) {
273281

274282
Git.getCurrentBranchName().then(function (oldBranchName) {
275283
Git.checkout(newBranchName).then(function () {
284+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'branch', "switch");
276285
return closeNotExistingFiles(oldBranchName, newBranchName);
277286
}).catch(function (err) {
278-
throw ErrorHandler.showError(err, Strings.ERROR_SWITCHING_BRANCHES);
287+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'branch', "switchFail");
288+
ErrorHandler.showError(err, Strings.ERROR_SWITCHING_BRANCHES);
279289
});
280290
}).catch(function (err) {
281-
throw ErrorHandler.showError(err, Strings.ERROR_GETTING_CURRENT_BRANCH);
291+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'branch', "switchFail");
292+
ErrorHandler.showError(err, Strings.ERROR_GETTING_CURRENT_BRANCH);
282293
});
283294

284295
});
@@ -483,7 +494,7 @@ define(function (require, exports) {
483494
}
484495
});
485496
}).catch(function (err) {
486-
throw ErrorHandler.showError(err);
497+
ErrorHandler.showError(err);
487498
});
488499
}
489500

src/extensions/default/Git/src/ErrorHandler.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
define(function (require, exports) {
22

3-
var _ = brackets.getModule("thirdparty/lodash"),
4-
Dialogs = brackets.getModule("widgets/Dialogs"),
3+
const Dialogs = brackets.getModule("widgets/Dialogs"),
54
Mustache = brackets.getModule("thirdparty/mustache/mustache"),
6-
NativeApp = brackets.getModule("utils/NativeApp"),
5+
Metrics = brackets.getModule("utils/Metrics"),
76
Strings = brackets.getModule("strings"),
87
Utils = require("src/Utils"),
98
errorDialogTemplate = require("text!templates/git-error-dialog.html");
109

11-
var errorQueue = [];
12-
1310
function errorToString(err) {
1411
return Utils.encodeSensitiveInformation(err.toString());
1512
}
@@ -34,13 +31,21 @@ define(function (require, exports) {
3431
};
3532

3633
exports.logError = function (err) {
37-
var msg = err && err.stack ? err.stack : err;
34+
const msg = err && err.stack ? err.stack : err;
3835
Utils.consoleError("[brackets-git] " + msg);
39-
errorQueue.push(err);
4036
return err;
4137
};
4238

43-
exports.showError = function (err, title, dontStripError) {
39+
/**
40+
*
41+
* @param err
42+
* @param title
43+
* @param {dontStripError: boolean, errorMetric: string} options
44+
*/
45+
exports.showError = function (err, title, options = {}) {
46+
const dontStripError = options.dontStripError;
47+
const errorMetric = options.errorMetric;
48+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'dialogErr', errorMetric || "Show");
4449
if (err.__shown) { return err; }
4550

4651
exports.logError(err);

src/extensions/default/Git/src/EventEmitter.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
define(function (require, exports, module) {
2-
const EventDispatcher = brackets.getModule("utils/EventDispatcher");
2+
const EventDispatcher = brackets.getModule("utils/EventDispatcher"),
3+
Metrics = brackets.getModule("utils/Metrics");
34

45
const emInstance = {};
56
EventDispatcher.makeEventDispatcher(emInstance);
67

7-
function getEmitter(eventName) {
8+
function getEmitter(eventName, optionalMetricToLog) {
89
if (!eventName) {
910
throw new Error("no event has been passed to get the emittor!");
1011
}
1112
return function () {
1213
emit(eventName, ...arguments);
14+
if(optionalMetricToLog) {
15+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, optionalMetricToLog[0], optionalMetricToLog[1]);
16+
}
1317
};
1418
}
1519

src/extensions/default/Git/src/History.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ define(function (require) {
66
FileUtils = brackets.getModule("file/FileUtils"),
77
LocalizationUtils = brackets.getModule("utils/LocalizationUtils"),
88
Strings = brackets.getModule("strings"),
9+
Metrics = brackets.getModule("utils/Metrics"),
910
Mustache = brackets.getModule("thirdparty/mustache/mustache");
1011

1112
// Local modules
@@ -315,9 +316,11 @@ define(function (require) {
315316
});
316317
EventEmitter.on(Events.HISTORY_SHOW_FILE, function () {
317318
handleToggleHistory("FILE");
319+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'panel', "fileHistory");
318320
});
319321
EventEmitter.on(Events.HISTORY_SHOW_GLOBAL, function () {
320322
handleToggleHistory("GLOBAL");
323+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'panel', "history");
321324
});
322325
EventEmitter.on(Events.REFRESH_HISTORY, function () {
323326
handleToggleHistory("REFRESH");

src/extensions/default/Git/src/HistoryViewer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ define(function (require, exports) {
55
Mustache = brackets.getModule("thirdparty/mustache/mustache"),
66
WorkspaceManager = brackets.getModule("view/WorkspaceManager"),
77
Strings = brackets.getModule("strings"),
8+
Metrics = brackets.getModule("utils/Metrics"),
89
marked = brackets.getModule('thirdparty/marked.min').marked;
910

1011
const ErrorHandler = require("src/ErrorHandler"),
@@ -232,6 +233,7 @@ define(function (require, exports) {
232233
}
233234

234235
function show(commitInfo, doc, options) {
236+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'history', "detailView");
235237
initialize();
236238

237239
commit = commitInfo;

src/extensions/default/Git/src/Main.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ define(function (require, exports) {
66
Menus = brackets.getModule("command/Menus"),
77
FileSystem = brackets.getModule("filesystem/FileSystem"),
88
Mustache = brackets.getModule("thirdparty/mustache/mustache"),
9+
Metrics = brackets.getModule("utils/Metrics"),
910
ProjectManager = brackets.getModule("project/ProjectManager");
1011

1112
const Constants = require("src/Constants"),
@@ -418,9 +419,17 @@ define(function (require, exports) {
418419
$(window).focus(refreshOnFocusChange);
419420

420421
// Event handlers
422+
let projectSwitched = true;
423+
EventEmitter.on(Events.BRACKETS_PROJECT_CHANGE, function () {
424+
// pressing refresh button will raise GIT_ENABLED event and we only want one enabled metric
425+
// per project open.
426+
projectSwitched = true;
427+
});
421428
EventEmitter.on(Events.GIT_ENABLED, function () {
422429
_enableAllCommands(true);
423430
gitEnabled = true;
431+
projectSwitched && Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'enabled', "project");
432+
projectSwitched = false;
424433
});
425434
EventEmitter.on(Events.GIT_DISABLED, function () {
426435
_enableAllCommands(false);

src/extensions/default/Git/src/NoRepo.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
define(function (require) {
33

44
// Brackets modules
5-
const FileSystem = brackets.getModule("filesystem/FileSystem"),
5+
const FileSystem = brackets.getModule("filesystem/FileSystem"),
66
FileUtils = brackets.getModule("file/FileUtils"),
77
ProjectManager = brackets.getModule("project/ProjectManager"),
88
CommandManager = brackets.getModule("command/CommandManager"),
9-
StringUtils = brackets.getModule("utils/StringUtils");
9+
Metrics = brackets.getModule("utils/Metrics"),
10+
Strings = brackets.getModule("strings"),
11+
StringUtils = brackets.getModule("utils/StringUtils");
1012

1113
// Local modules
12-
const ErrorHandler = require("src/ErrorHandler"),
14+
const ErrorHandler = require("src/ErrorHandler"),
1315
Events = require("src/Events"),
1416
EventEmitter = require("src/EventEmitter"),
15-
Strings = brackets.getModule("strings"),
1617
ExpectedError = require("src/ExpectedError"),
1718
ProgressDialog = require("src/dialogs/Progress"),
1819
CloneDialog = require("src/dialogs/Clone"),
@@ -58,8 +59,8 @@ define(function (require) {
5859
EventEmitter.emit(Events.GIT_CHANGE_EMAIL, function () {
5960
Git.init().then(function (result) {
6061
resolve(result);
61-
}).catch(function (err) {
62-
reject(err);
62+
}).catch(function (error) {
63+
reject(error);
6364
});
6465
});
6566
});
@@ -70,9 +71,11 @@ define(function (require) {
7071
});
7172
});
7273
}).then(function () {
74+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'init', "success");
7375
return stageGitIgnore("Initial staging");
7476
}).catch(function (err) {
75-
ErrorHandler.showError(err, Strings.INIT_NEW_REPO_FAILED, true);
77+
ErrorHandler.showError(err, Strings.INIT_NEW_REPO_FAILED, {dontStripError: true});
78+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'init', "fail");
7679
}).then(function () {
7780
EventEmitter.emit(Events.REFRESH_ALL);
7881
});
@@ -99,7 +102,7 @@ define(function (require) {
99102
const clonePath = Phoenix.app.getDisplayPath(Utils.getProjectRoot());
100103
const err = new ExpectedError(
101104
StringUtils.format(Strings.GIT_CLONE_ERROR_EXPLAIN, clonePath));
102-
ErrorHandler.showError(err, Strings.GIT_CLONE_REMOTE_FAILED, true);
105+
ErrorHandler.showError(err, Strings.GIT_CLONE_REMOTE_FAILED, {dontStripError: true});
103106
return;
104107
}
105108
function _clone(cloneConfig) {
@@ -115,8 +118,11 @@ define(function (require) {
115118
const tracker = ProgressDialog.newProgressTracker();
116119
destPath = destPath ? fs.getTauriPlatformPath(destPath) : ".";
117120
return ProgressDialog.show(Git.clone(remoteUrl, destPath, tracker), tracker);
121+
}).then(()=>{
122+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'clone', "success");
118123
}).catch(function (err) {
119-
ErrorHandler.showError(err, Strings.GIT_CLONE_REMOTE_FAILED);
124+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'clone', "fail");
125+
ErrorHandler.showError(err, Strings.GIT_CLONE_REMOTE_FAILED, {errorMetric: "clone"});
120126
});
121127

122128
// restore original url if desired

0 commit comments

Comments
 (0)