Skip to content

Commit a983720

Browse files
committed
chore: all git metrics done
1 parent 805aa90 commit a983720

File tree

5 files changed

+50
-25
lines changed

5 files changed

+50
-25
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,16 @@ define(function (require, exports) {
3636
return err;
3737
};
3838

39-
exports.showError = function (err, title, dontStripError) {
40-
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'dialog', "errorShow");
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");
4149
if (err.__shown) { return err; }
4250

4351
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/NoRepo.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ define(function (require) {
5959
EventEmitter.emit(Events.GIT_CHANGE_EMAIL, function () {
6060
Git.init().then(function (result) {
6161
resolve(result);
62-
}).catch(function (err) {
63-
reject(err);
62+
}).catch(function (error) {
63+
reject(error);
6464
});
6565
});
6666
});
@@ -71,13 +71,13 @@ define(function (require) {
7171
});
7272
});
7373
}).then(function () {
74+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'init', "success");
7475
return stageGitIgnore("Initial staging");
7576
}).catch(function (err) {
76-
ErrorHandler.showError(err, Strings.INIT_NEW_REPO_FAILED, true);
77+
ErrorHandler.showError(err, Strings.INIT_NEW_REPO_FAILED, {dontStripError: true});
7778
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'init', "fail");
7879
}).then(function () {
7980
EventEmitter.emit(Events.REFRESH_ALL);
80-
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'init', "success");
8181
});
8282
}
8383

@@ -102,7 +102,7 @@ define(function (require) {
102102
const clonePath = Phoenix.app.getDisplayPath(Utils.getProjectRoot());
103103
const err = new ExpectedError(
104104
StringUtils.format(Strings.GIT_CLONE_ERROR_EXPLAIN, clonePath));
105-
ErrorHandler.showError(err, Strings.GIT_CLONE_REMOTE_FAILED, true);
105+
ErrorHandler.showError(err, Strings.GIT_CLONE_REMOTE_FAILED, {dontStripError: true});
106106
return;
107107
}
108108
function _clone(cloneConfig) {
@@ -118,8 +118,11 @@ define(function (require) {
118118
const tracker = ProgressDialog.newProgressTracker();
119119
destPath = destPath ? fs.getTauriPlatformPath(destPath) : ".";
120120
return ProgressDialog.show(Git.clone(remoteUrl, destPath, tracker), tracker);
121+
}).then(()=>{
122+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'clone', "success");
121123
}).catch(function (err) {
122-
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"});
123126
});
124127

125128
// restore original url if desired
@@ -143,11 +146,8 @@ define(function (require) {
143146
// when dialog is cancelled, there's no error
144147
if (err) { ErrorHandler.showError(err, Strings.GIT_CLONE_REMOTE_FAILED); }
145148
});
146-
}).then(()=>{
147-
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'clone', "success");
148149
}).catch(function (err) {
149150
ErrorHandler.showError(err);
150-
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'clone', "fail");
151151
}).finally(function () {
152152
$cloneButton.prop("disabled", false);
153153
});

src/extensions/default/Git/src/Panel.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ define(function (require, exports) {
341341
} else {
342342
throw new ExpectedError(Strings.ERROR_MODIFIED_DIALOG_FILES);
343343
}
344+
}).then(()=>{
345+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'commit', "success");
344346
}).catch(function (err) {
345347
if (ErrorHandler.contains(err, "Please tell me who you are")) {
346348
return new Promise((resolve)=>{
@@ -352,11 +354,10 @@ define(function (require, exports) {
352354
});
353355
}
354356

355-
ErrorHandler.showError(err, Strings.ERROR_GIT_COMMIT_FAILED);
357+
ErrorHandler.showError(err, Strings.ERROR_GIT_COMMIT_FAILED, {errorMetric: "commit"});
356358
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'commit', "fail");
357359

358360
}).finally(function () {
359-
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'commit', "success");
360361
EventEmitter.emit(Events.GIT_COMMITED);
361362
refresh();
362363
});
@@ -1236,7 +1237,7 @@ define(function (require, exports) {
12361237
});
12371238
}
12381239
})
1239-
.on("click", ".git-refresh", EventEmitter.getEmitter(Events.REFRESH_ALL))
1240+
.on("click", ".git-refresh", EventEmitter.getEmitter(Events.REFRESH_ALL, ["panel", "refreshBtn"]))
12401241
.on("click", ".git-commit", EventEmitter.getEmitter(Events.HANDLE_GIT_COMMIT))
12411242
.on("click", ".git-rebase-continue", function (e) { handleRebase("continue", e); })
12421243
.on("click", ".git-rebase-skip", function (e) { handleRebase("skip", e); })
@@ -1254,22 +1255,24 @@ define(function (require, exports) {
12541255
})
12551256
.on("click", ".git-file-history", EventEmitter.getEmitter(Events.HISTORY_SHOW_FILE))
12561257
.on("click", ".git-history-toggle", EventEmitter.getEmitter(Events.HISTORY_SHOW_GLOBAL))
1257-
.on("click", ".git-fetch", EventEmitter.getEmitter(Events.HANDLE_FETCH))
1258+
.on("click", ".git-fetch", EventEmitter.getEmitter(Events.HANDLE_FETCH, ["panel", "fetchBtn"]))
12581259
.on("click", ".git-push", function () {
1260+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'panel', "pushBtn");
12591261
var typeOfRemote = $(this).attr("x-selected-remote-type");
12601262
if (typeOfRemote === "git") {
12611263
EventEmitter.emit(Events.HANDLE_PUSH);
12621264
}
12631265
})
1264-
.on("click", ".git-pull", EventEmitter.getEmitter(Events.HANDLE_PULL))
1266+
.on("click", ".git-pull", EventEmitter.getEmitter(Events.HANDLE_PULL, ["panel", "pullBtn"]))
12651267
.on("click", ".git-init", EventEmitter.getEmitter(Events.HANDLE_GIT_INIT))
12661268
.on("click", ".git-clone", EventEmitter.getEmitter(Events.HANDLE_GIT_CLONE))
1267-
.on("click", ".change-remote", EventEmitter.getEmitter(Events.HANDLE_REMOTE_PICK))
1268-
.on("click", ".remove-remote", EventEmitter.getEmitter(Events.HANDLE_REMOTE_DELETE))
1269-
.on("click", ".git-remote-new", EventEmitter.getEmitter(Events.HANDLE_REMOTE_CREATE))
1269+
.on("click", ".change-remote", EventEmitter.getEmitter(Events.HANDLE_REMOTE_PICK, ["panel", "changeRemote"]))
1270+
.on("click", ".remove-remote", EventEmitter.getEmitter(Events.HANDLE_REMOTE_DELETE, ["panel", "removeRemote"]))
1271+
.on("click", ".git-remote-new", EventEmitter.getEmitter(Events.HANDLE_REMOTE_CREATE, ["panel", "newRemote"]))
12701272
.on("contextmenu", "tr", function (e) {
12711273
const $this = $(this);
12721274
if ($this.hasClass("history-commit")) {
1275+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'cmenu', "history");
12731276
if(!$this.hasClass("selected")){
12741277
$this.click();
12751278
}
@@ -1279,6 +1282,7 @@ define(function (require, exports) {
12791282

12801283
$this.click();
12811284
setTimeout(function () {
1285+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'cmenu', "filechanges");
12821286
Menus.getContextMenu(Constants.GIT_PANEL_CHANGES_CMENU).open(e);
12831287
}, 1);
12841288
});

src/extensions/default/Git/src/Remotes.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ define(function (require) {
55
DefaultDialogs = brackets.getModule("widgets/DefaultDialogs"),
66
Dialogs = brackets.getModule("widgets/Dialogs"),
77
Mustache = brackets.getModule("thirdparty/mustache/mustache"),
8+
Metrics = brackets.getModule("utils/Metrics"),
9+
Strings = brackets.getModule("strings"),
810
StringUtils = brackets.getModule("utils/StringUtils");
911

1012
// Local modules
@@ -16,7 +18,6 @@ define(function (require) {
1618
ProgressDialog = require("src/dialogs/Progress"),
1719
PullDialog = require("src/dialogs/Pull"),
1820
PushDialog = require("src/dialogs/Push"),
19-
Strings = brackets.getModule("strings"),
2021
Utils = require("src/Utils");
2122

2223
// Templates
@@ -237,11 +238,13 @@ define(function (require) {
237238
return ProgressDialog.show(op, progressTracker)
238239
.then(function (result) {
239240
return ProgressDialog.waitForClose().then(function () {
241+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'push', "success");
240242
showPushResult(result);
241243
});
242244
})
243245
.catch(function (err) {
244-
ErrorHandler.showError(err, Strings.ERROR_PUSHING_REMOTE);
246+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'push', "fail");
247+
ErrorHandler.showError(err, Strings.ERROR_PUSHING_REMOTE, {errorMetric: "push"});
245248
});
246249
});
247250
// restore original url if desired
@@ -315,12 +318,14 @@ define(function (require) {
315318
// leaving the result as empty in stdout.
316319
// If we reach this point, the command has succeeded,
317320
// so we display a success message if `result` is "".
321+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'pull', "success");
318322
return Utils.showOutput(result || Strings.GIT_PULL_SUCCESS,
319323
Strings.GIT_PULL_RESPONSE);
320324
});
321325
})
322326
.catch(function (err) {
323-
ErrorHandler.showError(err, Strings.ERROR_PULLING_REMOTE);
327+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'pull', "fail");
328+
ErrorHandler.showError(err, Strings.ERROR_PULLING_REMOTE, {errorMetric: "pull"});
324329
});
325330
});
326331
// restore original url if desired
@@ -347,8 +352,12 @@ define(function (require) {
347352

348353
const tracker = ProgressDialog.newProgressTracker();
349354
return ProgressDialog.show(Git.fetchAllRemotes(tracker), tracker)
355+
.then(()=>{
356+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'fetch', "success");
357+
})
350358
.catch(function (err) {
351-
ErrorHandler.showError(err);
359+
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'fetch', "fail");
360+
ErrorHandler.showError(err, undefined, {errorMetric: "fetch"});
352361
})
353362
.then(ProgressDialog.waitForClose)
354363
.finally(function () {

0 commit comments

Comments
 (0)