Custom code after Git/commit

Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
Patrik
Posts: 280
Joined: Thu Nov 28, 2013 9:32 am
Location: Hamburg/Germany
Contact:

Custom code after Git/commit

Post 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
cristi_talau
Posts: 496
Joined: Thu Sep 04, 2014 4:22 pm

Re: Custom code after Git/commit

Post 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
Patrik
Posts: 280
Joined: Thu Nov 28, 2013 9:32 am
Location: Hamburg/Germany
Contact:

Re: Custom code after Git/commit

Post 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
Post Reply