Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git metrics #2062

Merged
merged 6 commits into from
Jan 16, 2025
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
25 changes: 18 additions & 7 deletions src/extensions/default/Git/src/Branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ define(function (require, exports) {
StringUtils = brackets.getModule("utils/StringUtils"),
DocumentManager = brackets.getModule("document/DocumentManager"),
Strings = brackets.getModule("strings"),
Metrics = brackets.getModule("utils/Metrics"),
MainViewManager = brackets.getModule("view/MainViewManager");

var Git = require("src/git/Git"),
Events = require("src/Events"),
EventEmitter = require("src/EventEmitter"),
ErrorHandler = require("src/ErrorHandler"),
Panel = require("src/Panel"),
Setup = require("src/utils/Setup"),
Setup = require("src/utils/Setup"),
Preferences = require("src/Preferences"),
ProgressDialog = require("src/dialogs/Progress"),
Utils = require("src/Utils"),
Expand Down Expand Up @@ -105,22 +106,25 @@ define(function (require, exports) {
if (useRebase) {

Git.rebaseInit(fromBranch).catch(function (err) {
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'rebase', "fail");
throw ErrorHandler.showError(err, Strings.ERROR_REBASE_FAILED);
}).then(function (stdout) {
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'rebase', "success");
Utils.showOutput(stdout || Strings.GIT_REBASE_SUCCESS, Strings.REBASE_RESULT).finally(function () {
EventEmitter.emit(Events.REFRESH_ALL);
});

});
}).catch(console.error);
} else {

Git.mergeBranch(fromBranch, mergeMsg, useNoff).catch(function (err) {
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'merge', "fail");
throw ErrorHandler.showError(err, Strings.ERROR_MERGE_FAILED);
}).then(function (stdout) {
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'merge', "success");
Utils.showOutput(stdout || Strings.GIT_MERGE_SUCCESS, Strings.MERGE_RESULT).finally(function () {
EventEmitter.emit(Events.REFRESH_ALL);
});
});
}).catch(console.error);
}
}
});
Expand Down Expand Up @@ -218,8 +222,10 @@ define(function (require, exports) {
track = !!isRemote;

Git.createBranch(branchName, originName, track).catch(function (err) {
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'branch', "createFail");
throw ErrorHandler.showError(err, Strings.ERROR_CREATE_BRANCH);
}).then(function () {
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'branch', "create");
EventEmitter.emit(Events.REFRESH_ALL);
});
}
Expand All @@ -246,8 +252,10 @@ define(function (require, exports) {
}).then(function (response) {
if (response === true) {
return Git.forceBranchDelete(branchName).then(function (output) {
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'branch', "delete");
return Utils.showOutput(output || Strings.GIT_BRANCH_DELETE_SUCCESS);
}).catch(function (err) {
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'branch', "deleteFail");
ErrorHandler.showError(err, Strings.ERROR_BRANCH_DELETE_FORCED);
});
}
Expand All @@ -273,12 +281,15 @@ define(function (require, exports) {

Git.getCurrentBranchName().then(function (oldBranchName) {
Git.checkout(newBranchName).then(function () {
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'branch', "switch");
return closeNotExistingFiles(oldBranchName, newBranchName);
}).catch(function (err) {
throw ErrorHandler.showError(err, Strings.ERROR_SWITCHING_BRANCHES);
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'branch', "switchFail");
ErrorHandler.showError(err, Strings.ERROR_SWITCHING_BRANCHES);
});
}).catch(function (err) {
throw ErrorHandler.showError(err, Strings.ERROR_GETTING_CURRENT_BRANCH);
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'branch', "switchFail");
ErrorHandler.showError(err, Strings.ERROR_GETTING_CURRENT_BRANCH);
});

});
Expand Down Expand Up @@ -483,7 +494,7 @@ define(function (require, exports) {
}
});
}).catch(function (err) {
throw ErrorHandler.showError(err);
ErrorHandler.showError(err);
});
}

Expand Down
21 changes: 13 additions & 8 deletions src/extensions/default/Git/src/ErrorHandler.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
define(function (require, exports) {

var _ = brackets.getModule("thirdparty/lodash"),
Dialogs = brackets.getModule("widgets/Dialogs"),
const Dialogs = brackets.getModule("widgets/Dialogs"),
Mustache = brackets.getModule("thirdparty/mustache/mustache"),
NativeApp = brackets.getModule("utils/NativeApp"),
Metrics = brackets.getModule("utils/Metrics"),
Strings = brackets.getModule("strings"),
Utils = require("src/Utils"),
errorDialogTemplate = require("text!templates/git-error-dialog.html");

var errorQueue = [];

function errorToString(err) {
return Utils.encodeSensitiveInformation(err.toString());
}
Expand All @@ -34,13 +31,21 @@ define(function (require, exports) {
};

exports.logError = function (err) {
var msg = err && err.stack ? err.stack : err;
const msg = err && err.stack ? err.stack : err;
Utils.consoleError("[brackets-git] " + msg);
errorQueue.push(err);
return err;
};

exports.showError = function (err, title, dontStripError) {
/**
*
* @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
3 changes: 3 additions & 0 deletions src/extensions/default/Git/src/History.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ define(function (require) {
FileUtils = brackets.getModule("file/FileUtils"),
LocalizationUtils = brackets.getModule("utils/LocalizationUtils"),
Strings = brackets.getModule("strings"),
Metrics = brackets.getModule("utils/Metrics"),
Mustache = brackets.getModule("thirdparty/mustache/mustache");

// Local modules
Expand Down Expand Up @@ -315,9 +316,11 @@ define(function (require) {
});
EventEmitter.on(Events.HISTORY_SHOW_FILE, function () {
handleToggleHistory("FILE");
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'panel', "fileHistory");
});
EventEmitter.on(Events.HISTORY_SHOW_GLOBAL, function () {
handleToggleHistory("GLOBAL");
Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'panel', "history");
});
EventEmitter.on(Events.REFRESH_HISTORY, function () {
handleToggleHistory("REFRESH");
Expand Down
2 changes: 2 additions & 0 deletions src/extensions/default/Git/src/HistoryViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ define(function (require, exports) {
Mustache = brackets.getModule("thirdparty/mustache/mustache"),
WorkspaceManager = brackets.getModule("view/WorkspaceManager"),
Strings = brackets.getModule("strings"),
Metrics = brackets.getModule("utils/Metrics"),
marked = brackets.getModule('thirdparty/marked.min').marked;

const ErrorHandler = require("src/ErrorHandler"),
Expand Down Expand Up @@ -232,6 +233,7 @@ define(function (require, exports) {
}

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

commit = commitInfo;
Expand Down
9 changes: 9 additions & 0 deletions src/extensions/default/Git/src/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ define(function (require, exports) {
Menus = brackets.getModule("command/Menus"),
FileSystem = brackets.getModule("filesystem/FileSystem"),
Mustache = brackets.getModule("thirdparty/mustache/mustache"),
Metrics = brackets.getModule("utils/Metrics"),
ProjectManager = brackets.getModule("project/ProjectManager");

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

// Event handlers
let projectSwitched = true;
EventEmitter.on(Events.BRACKETS_PROJECT_CHANGE, function () {
// pressing refresh button will raise GIT_ENABLED event and we only want one enabled metric
// per project open.
projectSwitched = true;
});
EventEmitter.on(Events.GIT_ENABLED, function () {
_enableAllCommands(true);
gitEnabled = true;
projectSwitched && Metrics.countEvent(Metrics.EVENT_TYPE.GIT, 'enabled', "project");
projectSwitched = false;
});
EventEmitter.on(Events.GIT_DISABLED, function () {
_enableAllCommands(false);
Expand Down
24 changes: 15 additions & 9 deletions src/extensions/default/Git/src/NoRepo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
define(function (require) {

// Brackets modules
const FileSystem = brackets.getModule("filesystem/FileSystem"),
const FileSystem = brackets.getModule("filesystem/FileSystem"),
FileUtils = brackets.getModule("file/FileUtils"),
ProjectManager = brackets.getModule("project/ProjectManager"),
CommandManager = brackets.getModule("command/CommandManager"),
StringUtils = brackets.getModule("utils/StringUtils");
Metrics = brackets.getModule("utils/Metrics"),
Strings = brackets.getModule("strings"),
StringUtils = brackets.getModule("utils/StringUtils");

// Local modules
const ErrorHandler = require("src/ErrorHandler"),
const ErrorHandler = require("src/ErrorHandler"),
Events = require("src/Events"),
EventEmitter = require("src/EventEmitter"),
Strings = brackets.getModule("strings"),
ExpectedError = require("src/ExpectedError"),
ProgressDialog = require("src/dialogs/Progress"),
CloneDialog = require("src/dialogs/Clone"),
Expand Down Expand Up @@ -58,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 @@ -70,9 +71,11 @@ 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);
});
Expand All @@ -99,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 @@ -115,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 Down
Loading
Loading