Merge pull request #2763 from node-red/simple-git-setting

Allow project workflow to be configured via settings file
This commit is contained in:
Nick O'Leary 2021-01-08 15:20:11 +00:00 committed by GitHub
commit b0bc7ecacb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 10 deletions

View File

@ -43,9 +43,11 @@ RED.projects.userSettings = (function() {
function createWorkflowSection(pane) { function createWorkflowSection(pane) {
var defaultWorkflowMode = RED.settings.theme("projects.workflow.mode","manual");
var currentGitSettings = RED.settings.get('git') || {}; var currentGitSettings = RED.settings.get('git') || {};
currentGitSettings.workflow = currentGitSettings.workflow || {}; currentGitSettings.workflow = currentGitSettings.workflow || {};
currentGitSettings.workflow.mode = currentGitSettings.workflow.mode || "manual"; currentGitSettings.workflow.mode = currentGitSettings.workflow.mode || defaultWorkflowMode;
var title = $('<h3></h3>').text(RED._("editor:sidebar.project.userSettings.workflow")).appendTo(pane); var title = $('<h3></h3>').text(RED._("editor:sidebar.project.userSettings.workflow")).appendTo(pane);

View File

@ -294,7 +294,10 @@ RED.sidebar.versionControl = (function() {
// TODO: this is a full refresh of the files - should be able to // TODO: this is a full refresh of the files - should be able to
// just do an incremental refresh // just do an incremental refresh
var workflowMode = ((RED.settings.get('git') || {}).workflow || {}).mode || "manual"; // Get the default workflow mode from theme settings
var defaultWorkflowMode = RED.settings.theme("projects.workflow.mode","manual");
// Check for the user-defined choice of mode
var workflowMode = ((RED.settings.get('git') || {}).workflow || {}).mode || defaultWorkflowMode;
if (workflowMode === 'auto') { if (workflowMode === 'auto') {
refresh(true); refresh(true);
} else { } else {

View File

@ -421,7 +421,7 @@ Project.prototype.update = async function (user, data) {
} }
return Promise.all(promises).then(function(res) { return Promise.all(promises).then(function(res) {
var gitSettings = getUserGitSettings(user) || {}; var gitSettings = getUserGitSettings(user) || {};
var workflowMode = (gitSettings.workflow||{}).mode || "manual"; var workflowMode = (gitSettings.workflow||{}).mode || settings.editorTheme.projects.workflow.mode;
if (workflowMode === 'auto') { if (workflowMode === 'auto') {
return project.stageFile(modifiedFiles.map(f => project.paths[f])).then(() => { return project.stageFile(modifiedFiles.map(f => project.paths[f])).then(() => {
return project.commit(user,{message:"Update "+modifiedFiles.join(", ")}) return project.commit(user,{message:"Update "+modifiedFiles.join(", ")})

View File

@ -34,7 +34,7 @@ var projectsEnabled = false;
var projectLogMessages = []; var projectLogMessages = [];
var projectsDir; var projectsDir;
var activeProject var activeProject;
var globalGitUser = false; var globalGitUser = false;
@ -106,6 +106,10 @@ function init(_settings, _runtime) {
} catch(err) { } catch(err) {
} }
} else { } else {
// Ensure there's a default workflow mode set
settings.editorTheme.projects.workflow = {
mode: (settings.editorTheme.projects.workflow || {}).mode || "manual"
}
globalGitUser = gitConfig.user; globalGitUser = gitConfig.user;
Projects.init(settings,runtime); Projects.init(settings,runtime);
sshTools.init(settings); sshTools.init(settings);
@ -574,11 +578,13 @@ async function saveFlows(flows, user) {
} }
return util.writeFile(flowsFullPath, flowData, flowsFileBackup).then(() => { return util.writeFile(flowsFullPath, flowData, flowsFileBackup).then(() => {
var gitSettings = getUserGitSettings(user) || {}; var gitSettings = getUserGitSettings(user) || {};
var workflowMode = (gitSettings.workflow||{}).mode || "manual"; if (activeProject) {
if (activeProject && workflowMode === 'auto') { var workflowMode = (gitSettings.workflow||{}).mode || settings.editorTheme.projects.workflow.mode;
return activeProject.stageFile([flowsFullPath, credentialsFile]).then(() => { if (workflowMode === 'auto') {
return activeProject.commit(user,{message:"Update flow files"}) return activeProject.stageFile([flowsFullPath, credentialsFile]).then(() => {
}) return activeProject.commit(user,{message:"Update flow files"})
})
}
} }
}); });
} }

View File

@ -292,7 +292,15 @@ module.exports = {
editorTheme: { editorTheme: {
projects: { projects: {
// To enable the Projects feature, set this value to true // To enable the Projects feature, set this value to true
enabled: false enabled: false,
workflow: {
// Set the default projects workflow mode.
// - manual - you must manually commit changes
// - auto - changes are automatically committed
// This can be overridden per-user from the 'Git config'
// section of 'User Settings' within the editor
mode: "manual"
}
} }
} }
} }