Skip to content
Browse files

Merge pull request #1 from drewfish/master

latest
  • Loading branch information...
2 parents 4f831b5 + 7dd083c commit 9712f8dab254507c8e20c8d11b88f28b93fdaaae @drewfish drewfish committed May 8, 2012
Showing with 95 additions and 11 deletions.
  1. +5 −5 Readme.md
  2. +1 −0 lib/crank.js
  3. +6 −1 lib/op-changelog.js
  4. +83 −5 lib/scm-svn.js
View
10 Readme.md
@@ -88,23 +88,23 @@ updates changelog. {file} defaults to `Changelog.md`
* `template`: template type, or path on disk
* defaults to file extension
* simple string taken as one of the built-in template types to use
- * builtin types are "md" (markdown) and "txt" (plain text)
+ * builtin types are `md` (markdown) and `txt` (plain text)
* otherwise, template to use
* `changes`:
* `dateformat`: string
* format to use for change dates
* `filters`: list of objects describing how to modify changes
- * `subject`: "message", "author", "date", "changeid"
+ * `subject`: string `message`, `author`, `date`, or `changeid`
* `regexp`: string
- * `replace`: "string"
+ * `replace`: string
* if results in `--CRANK:SKIP--` then change is skipped
* `versions`:
* `dateformat`: string
* format to use for revision dates
* `filters`: list of objects describing how to modify versions
- * `subject`: "version", "date", "changeid"
+ * `subject`: string `version`, `date`, or `changeid`
* `regexp`: string
- * `replace`: "string"
+ * `replace`: string
* if results in `--CRANK:SKIP--` then version is skipped
View
1 lib/crank.js
@@ -156,6 +156,7 @@ Base.prototype.fileWrite = function(path, content) {
Base.prototype.fileWriteJSON = function(path, content) {
content = JSON.stringify(content, null, 4);
+ content += '\n';
return libfs.writeFileSync(path, content, 'utf-8');
};
View
7 lib/op-changelog.js
@@ -187,7 +187,12 @@ OPChangelog.prototype.run = function(command) {
cb();
}
- ]);
+ ], function(error) {
+ if (error) {
+ console.error('ERROR: ' + error.message);
+ return;
+ }
+ });
};
View
88 lib/scm-svn.js
@@ -23,25 +23,103 @@
*/
+var
+ libpath = require('path'),
+ libprocess = require('child_process');
-function SCMSvn() {}
+
+
+function SCMSvn(base) {}
module.exports = SCMSvn;
SCMSvn.prototype.init = function(target, cb) {
- // TODO
+ var path = libpath.join(target, '.svn');
+ if (libpath.existsSync(path)) {
+ this.target = target;
+ cb(null, this);
+ return;
+ }
cb(null, null);
- return;
};
SCMSvn.prototype.getCurrentChangeID = function(cb) {
- // TODO
+ var me = this;
+ libprocess.exec('svn info', function(error, stdout, stderr) {
+ var info;
+ if (error) {
+ cb(error);
+ return;
+ }
+ info = me._parseInfo(stdout);
+ cb(null, info['Revision']);
+ });
};
SCMSvn.prototype.listChanges = function(fromChange, toChange, cb) {
- // TODO
+ var me = this,
+ cmd, log;
+ fromChange = parseInt(fromChange, 10);
+ // reverse order, so that changelog "reads up"
+ cmd = 'svn log -r ' + toChange + ':' + (fromChange + 1);
+ libprocess.exec(cmd, function(error, stdout, stderr) {
+ if (error) {
+ cb(error);
+ return;
+ }
+ log = me._parseLog(stdout);
+ cb(null, log);
+ });
+};
+
+
+SCMSvn.prototype._parseInfo = function(raw) {
+ var info = {},
+ l, line, lines,
+ sepPos, key;
+ lines = raw.split('\n');
+ for (l = 0; l < lines.length; l += 1) {
+ line = lines[l];
+ if (!line.length) {
+ continue;
+ }
+ sepPos = line.indexOf(': ');
+ if (-1 === sepPos) {
+ continue;
+ }
+ key = line.substr(0, sepPos);
+ info[key] = line.substr(sepPos + 2);
+ }
+ return info;
};
+SCMSvn.prototype._parseLog = function(raw) {
+ var changes = [],
+ e, entry, entries,
+ lines, matches, crank;
+ entries = raw.split(/------------------------------------+\n/m);
+ for (e = 0; e < entries.length; e++) {
+ entry = entries[e].trim();
+ if (!entry.length) {
+ continue;
+ }
+ lines = entry.split('\n');
+ // r14611 | jcatera | 2012-05-08 09:45:20 -0700 (Tue, 08 May 2012) | 2 lines
+ matches = lines[0].match(/^r(\d+)\s+\|\s+(\S+)\s+\|\s+([^|]+)\s+|/);
+ lines.shift();
+ lines.shift();
+ crank = {};
+ crank.changeid = matches[1];
+ crank.author = matches[2];
+ crank.date = new Date(matches[3]);
+ crank.message = lines.join('\n');
+ changes.push(crank);
+ }
+ return changes;
+};
+
+
+

0 comments on commit 9712f8d

Please sign in to comment.
Something went wrong with that request. Please try again.