Commit 0f0b09bd authored by mercury233's avatar mercury233 Committed by GitHub

update util: make log since commit

parent 575a2076
...@@ -158,12 +158,16 @@ var fetchDatas = function() { ...@@ -158,12 +158,16 @@ var fetchDatas = function() {
}); });
} }
var updateChangelogs = function(message) { var updateChangelogs = function(dir, message) {
message = message.split("!换行符!").join("\n"); message = message.split("!换行符!").join("\n");
change_log = {}; change_log = {};
change_log.title = "服务器更新"; change_log.title = "服务器更新";
change_log.date = moment().format("YYYY-MM-DD"); change_log.date = moment().format("YYYY-MM-DD");
change_log.text = message; change_log.text = message;
var prc_git_rev = spawnSync("git", [ "rev-parse", "HEAD" ], { "cwd" : dir });
if (prc_git_rev.stdout) {
change_log.commit = prc_git_rev.stdout.toString().split(/\n/)[0];
}
changelog.unshift(change_log); changelog.unshift(change_log);
fileContent = JSON.stringify({ changelog: changelog }, null, 2); fileContent = JSON.stringify({ changelog: changelog }, null, 2);
fs.writeFileSync(config.html_path + config.changelog_filename, fileContent); fs.writeFileSync(config.html_path + config.changelog_filename, fileContent);
...@@ -173,7 +177,7 @@ var updateChangelogs = function(message) { ...@@ -173,7 +177,7 @@ var updateChangelogs = function(message) {
var pushHTMLs = function() { var pushHTMLs = function() {
try { try {
execSync('git add ' + config.changelog_filename, { cwd: config.git_html_path, env: process.env }); execSync('git add ' + config.changelog_filename, { cwd: config.git_html_path, env: process.env });
//execSync('git commit -m update-auto', { cwd: config.git_html_path, env: process.env }); execSync('git commit -m update-auto', { cwd: config.git_html_path, env: process.env });
} catch (error) { } catch (error) {
sendResponse("git error: "+error.stdout); sendResponse("git error: "+error.stdout);
} }
...@@ -242,7 +246,8 @@ http.createServer(function (req, res) { ...@@ -242,7 +246,8 @@ http.createServer(function (req, res) {
res.writeHead(200); res.writeHead(200);
var date = moment(changelog[0].date).add(1,'days').format("YYYY-MM-DD"); var date = moment(changelog[0].date).add(1,'days').format("YYYY-MM-DD");
res.end(u.query.callback+'({"message":"开始生成'+ date +'以来的更新记录:"});'); res.end(u.query.callback+'({"message":"开始生成'+ date +'以来的更新记录:"});');
makeChangelogs(config.script_path, "--since="+date); var since = changelog[0].commit ? (changelog[0].commit + "..") : ("--since=" + date);
makeChangelogs(config.script_path, since);
} }
else if (u.pathname === '/api/make_more_changelog') { else if (u.pathname === '/api/make_more_changelog') {
res.writeHead(200); res.writeHead(200);
...@@ -252,7 +257,7 @@ http.createServer(function (req, res) { ...@@ -252,7 +257,7 @@ http.createServer(function (req, res) {
else if (u.pathname === '/api/update_changelog') { else if (u.pathname === '/api/update_changelog') {
res.writeHead(200); res.writeHead(200);
res.end(u.query.callback+'({"message":"开始写入更新记录。"});'); res.end(u.query.callback+'({"message":"开始写入更新记录。"});');
updateChangelogs(u.query.message); updateChangelogs(config.script_path, u.query.message);
} }
else if (u.pathname === '/api/push_datas') { else if (u.pathname === '/api/push_datas') {
res.writeHead(200); res.writeHead(200);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment