Skip to content

Commit

Permalink
chore: all git metrics done
Browse files Browse the repository at this point in the history
  • Loading branch information
abose committed Jan 16, 2025
1 parent 805aa90 commit a983720
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 25 deletions.
12 changes: 10 additions & 2 deletions src/extensions/default/Git/src/ErrorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ define(function (require, exports) {
return err;
};

exports.showError = function (err, title, dontStripError) {
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'dialog', "errorShow");
/**
*
* @param err
* @param title
* @param {dontStripError: boolean, errorMetric: string} options
*/
exports.showError = function (err, title, options = {}) {
const dontStripError = options.dontStripError;
const errorMetric = options.errorMetric;
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'dialogErr', errorMetric || "Show");
if (err.__shown) { return err; }

exports.logError(err);
Expand Down
8 changes: 6 additions & 2 deletions src/extensions/default/Git/src/EventEmitter.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
define(function (require, exports, module) {
const EventDispatcher = brackets.getModule("utils/EventDispatcher");
const EventDispatcher = brackets.getModule("utils/EventDispatcher"),
Metrics = brackets.getModule("utils/Metrics");

const emInstance = {};
EventDispatcher.makeEventDispatcher(emInstance);

function getEmitter(eventName) {
function getEmitter(eventName, optionalMetricToLog) {
if (!eventName) {
throw new Error("no event has been passed to get the emittor!");
}
return function () {
emit(eventName, ...arguments);
if(optionalMetricToLog) {
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, optionalMetricToLog[0], optionalMetricToLog[1]);
}
};
}

Expand Down
18 changes: 9 additions & 9 deletions src/extensions/default/Git/src/NoRepo.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ define(function (require) {
EventEmitter.emit(Events.GIT_CHANGE_EMAIL, function () {
Git.init().then(function (result) {
resolve(result);
}).catch(function (err) {
reject(err);
}).catch(function (error) {
reject(error);
});
});
});
Expand All @@ -71,13 +71,13 @@ define(function (require) {
});
});
}).then(function () {
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'init', "success");
return stageGitIgnore("Initial staging");
}).catch(function (err) {
ErrorHandler.showError(err, Strings.INIT_NEW_REPO_FAILED, true);
ErrorHandler.showError(err, Strings.INIT_NEW_REPO_FAILED, {dontStripError: true});
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'init', "fail");
}).then(function () {
EventEmitter.emit(Events.REFRESH_ALL);
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'init', "success");
});
}

Expand All @@ -102,7 +102,7 @@ define(function (require) {
const clonePath = Phoenix.app.getDisplayPath(Utils.getProjectRoot());
const err = new ExpectedError(
StringUtils.format(Strings.GIT_CLONE_ERROR_EXPLAIN, clonePath));
ErrorHandler.showError(err, Strings.GIT_CLONE_REMOTE_FAILED, true);
ErrorHandler.showError(err, Strings.GIT_CLONE_REMOTE_FAILED, {dontStripError: true});
return;
}
function _clone(cloneConfig) {
Expand All @@ -118,8 +118,11 @@ define(function (require) {
const tracker = ProgressDialog.newProgressTracker();
destPath = destPath ? fs.getTauriPlatformPath(destPath) : ".";
return ProgressDialog.show(Git.clone(remoteUrl, destPath, tracker), tracker);
}).then(()=>{
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'clone', "success");
}).catch(function (err) {
ErrorHandler.showError(err, Strings.GIT_CLONE_REMOTE_FAILED);
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'clone', "fail");
ErrorHandler.showError(err, Strings.GIT_CLONE_REMOTE_FAILED, {errorMetric: "clone"});
});

// restore original url if desired
Expand All @@ -143,11 +146,8 @@ define(function (require) {
// when dialog is cancelled, there's no error
if (err) { ErrorHandler.showError(err, Strings.GIT_CLONE_REMOTE_FAILED); }
});
}).then(()=>{
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'clone', "success");
}).catch(function (err) {
ErrorHandler.showError(err);
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'clone', "fail");
}).finally(function () {
$cloneButton.prop("disabled", false);
});
Expand Down
20 changes: 12 additions & 8 deletions src/extensions/default/Git/src/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ define(function (require, exports) {
} else {
throw new ExpectedError(Strings.ERROR_MODIFIED_DIALOG_FILES);
}
}).then(()=>{
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'commit', "success");
}).catch(function (err) {
if (ErrorHandler.contains(err, "Please tell me who you are")) {
return new Promise((resolve)=>{
Expand All @@ -352,11 +354,10 @@ define(function (require, exports) {
});
}

ErrorHandler.showError(err, Strings.ERROR_GIT_COMMIT_FAILED);
ErrorHandler.showError(err, Strings.ERROR_GIT_COMMIT_FAILED, {errorMetric: "commit"});
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'commit', "fail");

}).finally(function () {
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'commit', "success");
EventEmitter.emit(Events.GIT_COMMITED);
refresh();
});
Expand Down Expand Up @@ -1236,7 +1237,7 @@ define(function (require, exports) {
});
}
})
.on("click", ".git-refresh", EventEmitter.getEmitter(Events.REFRESH_ALL))
.on("click", ".git-refresh", EventEmitter.getEmitter(Events.REFRESH_ALL, ["panel", "refreshBtn"]))
.on("click", ".git-commit", EventEmitter.getEmitter(Events.HANDLE_GIT_COMMIT))
.on("click", ".git-rebase-continue", function (e) { handleRebase("continue", e); })
.on("click", ".git-rebase-skip", function (e) { handleRebase("skip", e); })
Expand All @@ -1254,22 +1255,24 @@ define(function (require, exports) {
})
.on("click", ".git-file-history", EventEmitter.getEmitter(Events.HISTORY_SHOW_FILE))
.on("click", ".git-history-toggle", EventEmitter.getEmitter(Events.HISTORY_SHOW_GLOBAL))
.on("click", ".git-fetch", EventEmitter.getEmitter(Events.HANDLE_FETCH))
.on("click", ".git-fetch", EventEmitter.getEmitter(Events.HANDLE_FETCH, ["panel", "fetchBtn"]))
.on("click", ".git-push", function () {
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'panel', "pushBtn");
var typeOfRemote = $(this).attr("x-selected-remote-type");
if (typeOfRemote === "git") {
EventEmitter.emit(Events.HANDLE_PUSH);
}
})
.on("click", ".git-pull", EventEmitter.getEmitter(Events.HANDLE_PULL))
.on("click", ".git-pull", EventEmitter.getEmitter(Events.HANDLE_PULL, ["panel", "pullBtn"]))
.on("click", ".git-init", EventEmitter.getEmitter(Events.HANDLE_GIT_INIT))
.on("click", ".git-clone", EventEmitter.getEmitter(Events.HANDLE_GIT_CLONE))
.on("click", ".change-remote", EventEmitter.getEmitter(Events.HANDLE_REMOTE_PICK))
.on("click", ".remove-remote", EventEmitter.getEmitter(Events.HANDLE_REMOTE_DELETE))
.on("click", ".git-remote-new", EventEmitter.getEmitter(Events.HANDLE_REMOTE_CREATE))
.on("click", ".change-remote", EventEmitter.getEmitter(Events.HANDLE_REMOTE_PICK, ["panel", "changeRemote"]))
.on("click", ".remove-remote", EventEmitter.getEmitter(Events.HANDLE_REMOTE_DELETE, ["panel", "removeRemote"]))
.on("click", ".git-remote-new", EventEmitter.getEmitter(Events.HANDLE_REMOTE_CREATE, ["panel", "newRemote"]))
.on("contextmenu", "tr", function (e) {
const $this = $(this);
if ($this.hasClass("history-commit")) {
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'cmenu', "history");
if(!$this.hasClass("selected")){
$this.click();
}
Expand All @@ -1279,6 +1282,7 @@ define(function (require, exports) {

$this.click();
setTimeout(function () {
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'cmenu', "filechanges");
Menus.getContextMenu(Constants.GIT_PANEL_CHANGES_CMENU).open(e);
}, 1);
});
Expand Down
17 changes: 13 additions & 4 deletions src/extensions/default/Git/src/Remotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ define(function (require) {
DefaultDialogs = brackets.getModule("widgets/DefaultDialogs"),
Dialogs = brackets.getModule("widgets/Dialogs"),
Mustache = brackets.getModule("thirdparty/mustache/mustache"),
Metrics = brackets.getModule("utils/Metrics"),
Strings = brackets.getModule("strings"),
StringUtils = brackets.getModule("utils/StringUtils");

// Local modules
Expand All @@ -16,7 +18,6 @@ define(function (require) {
ProgressDialog = require("src/dialogs/Progress"),
PullDialog = require("src/dialogs/Pull"),
PushDialog = require("src/dialogs/Push"),
Strings = brackets.getModule("strings"),
Utils = require("src/Utils");

// Templates
Expand Down Expand Up @@ -237,11 +238,13 @@ define(function (require) {
return ProgressDialog.show(op, progressTracker)
.then(function (result) {
return ProgressDialog.waitForClose().then(function () {
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'push', "success");
showPushResult(result);
});
})
.catch(function (err) {
ErrorHandler.showError(err, Strings.ERROR_PUSHING_REMOTE);
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'push', "fail");
ErrorHandler.showError(err, Strings.ERROR_PUSHING_REMOTE, {errorMetric: "push"});
});
});
// restore original url if desired
Expand Down Expand Up @@ -315,12 +318,14 @@ define(function (require) {
// leaving the result as empty in stdout.
// If we reach this point, the command has succeeded,
// so we display a success message if `result` is "".
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'pull', "success");
return Utils.showOutput(result || Strings.GIT_PULL_SUCCESS,
Strings.GIT_PULL_RESPONSE);
});
})
.catch(function (err) {
ErrorHandler.showError(err, Strings.ERROR_PULLING_REMOTE);
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'pull', "fail");
ErrorHandler.showError(err, Strings.ERROR_PULLING_REMOTE, {errorMetric: "pull"});
});
});
// restore original url if desired
Expand All @@ -347,8 +352,12 @@ define(function (require) {

const tracker = ProgressDialog.newProgressTracker();
return ProgressDialog.show(Git.fetchAllRemotes(tracker), tracker)
.then(()=>{
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'fetch', "success");
})
.catch(function (err) {
ErrorHandler.showError(err);
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'fetch', "fail");
ErrorHandler.showError(err, undefined, {errorMetric: "fetch"});
})
.then(ProgressDialog.waitForClose)
.finally(function () {
Expand Down

0 comments on commit a983720

Please sign in to comment.