Add simplified git workflow to auto-commit changes

This commit is contained in:
Nick O'Leary
2019-01-21 15:20:56 +00:00
parent e6ffa3d143
commit 69d60ffb24
11 changed files with 125 additions and 57 deletions

View File

@@ -82,7 +82,7 @@ var storageModuleInterface = {
})
});
},
saveFlows: function(config) {
saveFlows: function(config, user) {
var flows = config.flows;
var credentials = config.credentials;
var credentialSavePromise;
@@ -94,7 +94,7 @@ var storageModuleInterface = {
delete config.credentialsDirty;
return credentialSavePromise.then(function() {
return storageModule.saveFlows(flows).then(function() {
return storageModule.saveFlows(flows, user).then(function() {
return crypto.createHash('md5').update(JSON.stringify(config.flows)).digest("hex");
})
});

View File

@@ -40,16 +40,22 @@ function getSSHKeyUsername(userObj) {
}
return username;
}
function getGitUser(user) {
function getUserGitSettings(user) {
var username;
if (!user) {
username = "_";
} else {
username = user.username;
}
var userSettings = settings.getUserSettings(username);
if (userSettings && userSettings.git) {
return userSettings.git.user;
var userSettings = settings.getUserSettings(username)||{};
return userSettings.git;
}
function getGitUser(user) {
var gitSettings = getUserGitSettings(user);
if (gitSettings) {
return gitSettings.user;
}
return null;
}
@@ -172,7 +178,7 @@ Project.prototype.initialise = function(user,data) {
}
}
return when.all(promises).then(function() {
return Promise.all(promises).then(function() {
return gitTools.stageFile(project.path,files);
}).then(function() {
return gitTools.commit(project.path,"Create project files",getGitUser(user));
@@ -390,11 +396,15 @@ Project.prototype.update = function (user, data) {
if (saveSettings) {
promises.push(settings.set("projects",globalProjectSettings));
}
var modifiedFiles = [];
if (saveREADME) {
promises.push(util.writeFile(fspath.join(this.path,this.paths['README.md']), this.description));
modifiedFiles.push('README.md');
}
if (savePackage) {
promises.push(fs.readFile(fspath.join(project.path,project.paths['package.json']),"utf8").then(content => {
promises.push(fs.readFile(fspath.join(this.path,this.paths['package.json']),"utf8").then(content => {
var currentPackage = {};
try {
currentPackage = util.parseJSON(content);
@@ -403,12 +413,22 @@ Project.prototype.update = function (user, data) {
this.package = Object.assign(currentPackage,this.package);
return util.writeFile(fspath.join(project.path,this.paths['package.json']), JSON.stringify(this.package,"",4));
}));
modifiedFiles.push('package.json');
}
return when.settle(promises).then(res => {
return when.settle(promises).then(function(res) {
var gitSettings = getUserGitSettings(user) || {};
var workflowMode = (gitSettings.workflow||{}).mode || "manual";
if (workflowMode === 'auto') {
return project.stageFile(modifiedFiles.map(f => project.paths[f])).then(() => {
return project.commit(user,{message:"Update "+modifiedFiles.join(", ")})
})
}
}).then(res => {
if (reloadProject) {
return this.load()
}
}).then(() => { return {
}).then(function() {
return {
flowFilesChanged: flowFilesChanged,
credentialSecretChanged: credentialSecretChanged
}})
@@ -910,7 +930,7 @@ function createDefaultProject(user, project) {
}
}
return when.all(promises).then(function() {
return Promise.all(promises).then(function() {
return gitTools.stageFile(projectPath,files);
}).then(function() {
return gitTools.commit(projectPath,"Create project",getGitUser(user));

View File

@@ -190,7 +190,13 @@ function listProjects() {
}
function getUserGitSettings(user) {
var userSettings = settings.getUserSettings(user)||{};
var username;
if (!user) {
username = "_";
} else {
username = user.username;
}
var userSettings = settings.getUserSettings(username)||{};
return userSettings.git;
}
@@ -362,7 +368,6 @@ function reloadActiveProject(action) {
});
}
function createProject(user, metadata) {
// var userSettings = getUserGitSettings(user);
if (metadata.files && metadata.migrateFiles) {
// We expect there to be no active project in this scenario
if (activeProject) {
@@ -549,7 +554,7 @@ function getFlows() {
});
}
function saveFlows(flows) {
function saveFlows(flows, user) {
if (settings.readOnly) {
return when.resolve();
}
@@ -569,7 +574,15 @@ function saveFlows(flows) {
} else {
flowData = JSON.stringify(flows);
}
return util.writeFile(flowsFullPath, flowData, flowsFileBackup);
return util.writeFile(flowsFullPath, flowData, flowsFileBackup).then(() => {
var gitSettings = getUserGitSettings(user) || {};
var workflowMode = (gitSettings.workflow||{}).mode || "manual";
if (activeProject && workflowMode === 'auto') {
return activeProject.stageFile([flowsFullPath, credentialsFile]).then(() => {
return activeProject.commit(user,{message:"Update flow files"})
})
}
});
}
function getCredentials() {