From c11f922b0bfa023a4cf49f26e55aec6a1413344b Mon Sep 17 00:00:00 2001 From: Cliff Brake Date: Thu, 16 Aug 2012 11:02:23 -0400 Subject: update weekly changelog tools --- tools/config-sample.js | 16 ++++++++++++++++ tools/dateutil.js | 19 ++++++++++++------- tools/git.js | 15 +++++++++------ tools/test/dateutil.test.js | 18 ++++++++++++++++++ tools/test/git.test.js | 4 ++-- tools/weekly-changelog.js | 34 +++++++++++++++++++++------------- 6 files changed, 78 insertions(+), 28 deletions(-) create mode 100644 tools/config-sample.js create mode 100644 tools/test/dateutil.test.js (limited to 'tools') diff --git a/tools/config-sample.js b/tools/config-sample.js new file mode 100644 index 0000000..9f0941d --- /dev/null +++ b/tools/config-sample.js @@ -0,0 +1,16 @@ +exports.config = { + email: { + transport: { + type: 'SMTP', + options: { + host: "my-server.com", + auth: { + user: 'smtp-user', + pass: 'password' + } + } + }, + from: 'user@gmail.com' + } +} + diff --git a/tools/dateutil.js b/tools/dateutil.js index bf33b0e..3995e63 100644 --- a/tools/dateutil.js +++ b/tools/dateutil.js @@ -2,12 +2,15 @@ var dateutil = require('./dateutil'); exports.last_week = function() { - // we go from Mon-Mon + // we go from Sun-Sun var day = 1000*60*60*24; - var d = new Date(); + var d = new Date() + d.setUTCHours(0) + d.setUTCMinutes(0) + d.setUTCSeconds(0) var today_weekday = d.getDay(); var ret = {}; - ret['end'] = new Date(d.getTime() - (today_weekday-1)*day); + ret['end'] = new Date(d.getTime() - (today_weekday + 1)*day); ret['start'] = new Date(ret['end'].getTime() - 7*day); return ret; } @@ -17,12 +20,14 @@ exports.last_week_text = function() { var lastwk = dateutil.last_week(); var end_day = lastwk.end; var start_day = lastwk.start; - return dateutil.isoformat(start_day) + ' to ' + dateutil.isoformat(end_day); + return 'since ' + dateutil.isoDate(start_day) + ' until ' + dateutil.isoDate(end_day); } -exports.isoformat = function(d) { - var m = d.getMonth() + 1; - return d.getFullYear() + '-' + (m < 10 ? '0' : '') + m + '-' + d.getDate(); +exports.isoDate = function(d) { +// var m = d.getMonth() + 1; +// return d.getFullYear() + '-' + (m < 10 ? '0' : '') + m + '-' + d.getDate(); + var e = /(.*)T/.exec(d.toISOString()) + return e[1] } diff --git a/tools/git.js b/tools/git.js index 523c7e0..5b2b47d 100644 --- a/tools/git.js +++ b/tools/git.js @@ -1,6 +1,7 @@ var fs = require('fs'), child_process = require('child_process'), - dateutil = require('./dateutil'); + dateutil = require('./dateutil'), + util = require('util') exports.parse_gitmodules = function(filepath, callback) { fs.readFile(filepath, 'utf8', function(err, data) { @@ -14,14 +15,15 @@ exports.parse_gitmodules = function(filepath, callback) { var url = null; var submodules = {} for (var i=0; i < lines.length; i++) { - if (/submodule/(lines[i])) { + console.log("lines[i] = " + lines[i]) + if (/submodule/.exec(lines[i])) { path = null; url = null; } - var re_path = /path = (\S.*)/(lines[i]); + var re_path = /path = (\S.*)/.exec(lines[i]); if (re_path) path = re_path[1]; - var re_url = /url = (\S.*)/(lines[i]); + var re_url = /url = (\S.*)/.exec(lines[i]); if (re_url) { url = re_url[1]; } @@ -37,8 +39,9 @@ exports.parse_gitmodules = function(filepath, callback) { } exports.changelog = function(repo_dir, startdate, enddate, callback) { - var start_iso = dateutil.isoformat(startdate); - var end_iso = dateutil.isoformat(enddate); + var start_iso = dateutil.isoDate(startdate); + var end_iso = dateutil.isoDate(enddate); + console.log("git changelog " + start_iso + " to " + end_iso) child_process.exec('cd ' + repo_dir + "; git shortlog --since=" + start_iso + " --until=" + end_iso + " origin/master | grep -v 'Merge branch' | grep -v 'Merge commit'|sed -e 's/^ //g'|cut -b -78", function(error, stdout, stderr) { if (stderr) diff --git a/tools/test/dateutil.test.js b/tools/test/dateutil.test.js new file mode 100644 index 0000000..8023a8f --- /dev/null +++ b/tools/test/dateutil.test.js @@ -0,0 +1,18 @@ +var dateutil = require('../dateutil'), + util = require('util'), + assert = require('assert') + +exports.test_last_week = function() { + var lastwk = dateutil.last_week() + console.log(util.inspect(lastwk)) + + assert(/Sun.*00:00:00/.exec(lastwk.start.toUTCString()), "lastwk start is not correct " + lastwk.start.toUTCString()) + + assert(/Sun.*00:00:00/.exec(lastwk.end.toUTCString()), "lastwk end is not correct " + lastwk.start.toUTCString()) + +} + +exports.test_last_week_text = function() { + console.log(dateutil.last_week_text()) +} + diff --git a/tools/test/git.test.js b/tools/test/git.test.js index 9fc1ddd..7afdb4f 100644 --- a/tools/test/git.test.js +++ b/tools/test/git.test.js @@ -19,8 +19,8 @@ exports.test_changelog = function() { var repo_dir = path.join(__dirname, 'fixture/openembedded-admin'); var expected = "Cliff Brake (2):\n initial commit of admin repos and tools\n add .gitignore\n\n" child_process.exec('git clone git://git.openembedded.org/openembedded-admin ' + repo_dir, function(error, stdout, stderr) { - var start = new Date('2011-05-19'); - var end = new Date('2011-05-20'); + var start = new Date('2011-05-18'); + var end = new Date('2011-05-19'); git.changelog(repo_dir, start, end, function(err, changelog) { assert.equal(err, null); assert.equal(changelog, expected); diff --git a/tools/weekly-changelog.js b/tools/weekly-changelog.js index 71d1935..71e1625 100644 --- a/tools/weekly-changelog.js +++ b/tools/weekly-changelog.js @@ -1,6 +1,6 @@ // script to collect the weekly changelog in a git repo -var testing = false; +var testing = true; var email_to = ''; var email_bcc = 'cbrake@bec-systems.com,'; @@ -14,7 +14,8 @@ var path = require('path'), fs = require('fs'), nodemailer = require('nodemailer'), git = require('./git'), - dateutil = require('./dateutil'); + dateutil = require('./dateutil'), + config = require('./config').config String.prototype.format = function() { var formatted = this; @@ -45,24 +46,30 @@ var format_report = function(projects, weekly_data) { } var email_report = function(report) { - nodemailer.send_mail( - { - sender: "cliff.brake@gmail.com", - to: email_to, - bcc: email_bcc, - subject: "OE Changelog for " + dateutil.last_week_text(), - body: report - }, - function(error, success) { - console.log("Message " + (success?"sent":"failed")); + console.log("send email ...") + var transport = nodemailer.createTransport(config.email.transport.type, config.email.transport.options) + var mailOptions = { + from: config.email.from, + to: email_to, + bcc: email_bcc, + subject: "OE Changelog " + dateutil.last_week_text(), + text: report + } + + transport.sendMail(mailOptions, function(error, response) { + if (error) { + console.log("Failed to send email: " + response) + } else { + console.log("mail sent: " + response.message) } - ); + }) } var run_changelog = function(projects) { var output = {}; var count = Object.keys(projects).length; var lastwk = dateutil.last_week(); + console.log("start = " + lastwk.start + " end = " + lastwk.end) var project; for (project in projects) { // function required to preserve the value of project @@ -75,6 +82,7 @@ var run_changelog = function(projects) { console.log('changelog error: ' + err); } else { output[project] = changelog; + console.log("changelog finished for " + project) } count--; if (count === 0) { -- cgit 1.2.3-korg