Created
June 22, 2012 02:02
-
-
Save jclulow/2969772 to your computer and use it in GitHub Desktop.
webrev rss bits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env node | |
| var restify = require('restify'); | |
| var pg = require('pg'); | |
| var log = console.log; | |
| var C = require('/etc/opt/cr_rss.json'); | |
| Object.keys(C).forEach(function(k) { | |
| pg.defaults[k] = C[k]; | |
| }); | |
| var s = restify.createServer(); | |
| s.use(restify.acceptParser(s.acceptable)); | |
| s.use(restify.bodyParser()); | |
| s.post('/cr/notify', function(req, res, next) { | |
| pg.connect(function(err, db) { | |
| db.query('INSERT INTO cr_activity (who, name, action) ' + | |
| 'VALUES ($1, $2, $3)', | |
| [req.params.who, req.params.name, req.params.action], | |
| function(err, result) { | |
| if (err) return res.send(500, err); | |
| res.send(200, {message: 'ok'}); | |
| }); | |
| }); | |
| }); | |
| s.listen(3089, 'localhost', function(err) { | |
| if (err) { | |
| log(err); | |
| process.exit(1); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env node | |
| var restify = require('restify'); | |
| var pg = require('pg'); | |
| var log = console.log; | |
| var fs = require('fs'); | |
| var path = require('path'); | |
| // load rss proforma | |
| var RSS = fs.readFileSync(path.join(__dirname, | |
| 'proforma-rss.xml'), 'utf8'); | |
| // load rss item proforma | |
| var RSSITEM = fs.readFileSync(path.join(__dirname, | |
| 'proforma-rss-item.xml'), 'utf8'); | |
| var C = require('/etc/opt/cr_rss.json'); | |
| Object.keys(C).forEach(function(k) { | |
| pg.defaults[k] = C[k]; | |
| }); | |
| var s = restify.createServer(); | |
| s.use(restify.acceptParser(s.acceptable)); | |
| s.use(restify.bodyParser()); | |
| s.get('/rss/webrev.xml', function(req, res, next) { | |
| pg.connect(function(err, db) { | |
| db.query('SELECT * FROM cr_activity ORDER BY id DESC LIMIT 20', | |
| function(err, result) { | |
| if (err) return res.send(500, err); | |
| if (result.rowCount < 1) return res.send(500); | |
| var doc = RSS.replace(/%%LASTBUILD%%/g, | |
| result.rows[0].time.toGMTString()); | |
| var items = ''; | |
| for (var i = result.rows.length - 1; i >= 0; i--) { | |
| var row = result.rows[i]; | |
| items += RSSITEM. | |
| replace(/%%who%%/g, row.who). | |
| replace(/%%name%%/g, row.name). | |
| replace(/%%action%%/g, row.action). | |
| replace(/%%id%%/g, row.id). | |
| replace(/%%time%%/g, row.time.toGMTString()); | |
| } | |
| doc = doc.replace(/%%ITEMS%%/g, items); | |
| res.contentType = 'application/rss+xml'; | |
| res.send(200, doc); | |
| }); | |
| }); | |
| }); | |
| s.listen(3090, 'localhost', function(err) { | |
| if (err) { | |
| log(err); | |
| process.exit(1); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env node | |
| var restify = require('restify'); | |
| var nc = restify.createJsonClient({ | |
| url: 'http://localhost:3089', | |
| connectTimeout: 5 | |
| }); | |
| var parms = { | |
| who: 'someuser', | |
| name: 'theirwebrev', | |
| action: 'update' | |
| }; | |
| nc.post('/cr/notify', parms, function(err, _req, _res, json) { | |
| console.log(json); | |
| process.exit(0); | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE TABLE cr_activity ( | |
| id BIGSERIAL, | |
| time TIMESTAMP DEFAULT NOW(), | |
| who VARCHAR(100) NOT NULL, | |
| name VARCHAR(100) NOT NULL, | |
| action VARCHAR(100) NOT NULL, | |
| PRIMARY KEY (id) | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment