Page 1 of 1

Custom code after Git/commit

Posted: Wed Nov 25, 2020 7:02 pm
by Patrik
Hi,

I want to add some custom javascript code after a git-commit-actions has completed successfully.

I already managed to execute some code (console.log() for testing) after the action. But how do I check if the commit was successful? Currently it is also executed when the user aborts in the commit dialog.

My current code looks like this (also checking for the document to be valid before the commit):

Code: Select all

	goog.events.listenOnce(e.editor, sync.api.Editor.EventTypes.ACTIONS_LOADED, function(e) {
		var commitAction = editor.getActionsManager().getActionById('Git/Commit');
		var oldActionPerformed = commitAction.actionPerformed;
		
		commitAction.actionPerformed = function(callback) {
			editor.getActionsManager().invokeOperation(
				'com.gdvdl.webauth.IsDocumentValid', 
				{}, // no parameters
				function (err, result) {
					console.log('Git/Commit - isValid: ' + result);
					if (result == 'true') {
						console.log('Git/Commit - valid');
						oldActionPerformed.call(commitAction, function(callback) {
							console.log('Git/Commit - Done!');
							// TODO: check for successfull commit and perform some post-commit-action
						});
					} else {
						[...] (error message)
					}
				},
				null,
				true // This is a background operation - it does not update the document
			);
			
		};
	});

Thanks and regards,
Patrik

Re: Custom code after Git/commit

Posted: Thu Nov 26, 2020 12:10 am
by cristi_talau
Hello,

Yes. The action callback is called after the action is executed regardless of its "successfulness" - in general, it is hard to say what success means for an action, although for commit it is pretty clear.

One option would be to check if the editor is dirty: https://www.oxygenxml.com/maven/com/oxy ... ml#isDirty .

Best,
Cristian

Re: Custom code after Git/commit

Posted: Thu Nov 26, 2020 4:51 pm
by Patrik
Thanks for the idea. I also added some check to only enable a commit of dirty documents. This way I know for sure that a non-dirty document after commit has been commited.

Regards,
Patrik