Fixed contract address length and action condition

This commit is contained in:
Jordi Montes 2018-03-13 17:27:23 +00:00
parent 069f031e3e
commit f59d7ce840
2 changed files with 3 additions and 5 deletions

View File

@ -22,7 +22,7 @@ const logger = winston.createLogger({
const needsFunding = function (req) { const needsFunding = function (req) {
if (req.body.action === 'edited' || !req.body.hasOwnProperty('comment')) { if (req.body.action !== 'edited' || !req.body.hasOwnProperty('comment')) {
return false return false
} else if (req.body.comment.user.login !== config.githubUsername) { } else if (req.body.comment.user.login !== config.githubUsername) {
return false return false
@ -43,7 +43,7 @@ const hasAddress = function (req) {
const getAddress = function (req) { const getAddress = function (req) {
const commentBody = req.body.comment.body; const commentBody = req.body.comment.body;
return commentBody.substring(commentBody.search("Contract address:") + 18, commentBody.search("Contract address:") + 60) return commentBody.substring(commentBody.search("Contract address:") + 19, commentBody.search("Contract address:") + 61)
} }
const getLabelMock = function (req) { const getLabelMock = function (req) {

View File

@ -3,7 +3,6 @@
* and in case it's a comment that has "@autobounty <decimal> <currency>" * and in case it's a comment that has "@autobounty <decimal> <currency>"
* awards that bounty to the address posted earlier in the thread (by the * awards that bounty to the address posted earlier in the thread (by the
* commiteth bot). * commiteth bot).
* TODO tests
* REVIEW parsing, non-persisting storage of addresses, hardcoded string length. * REVIEW parsing, non-persisting storage of addresses, hardcoded string length.
* Depends on commiteth version as of 2017-06-10. * Depends on commiteth version as of 2017-06-10.
*/ */
@ -25,13 +24,12 @@ app.use(helmet());
// Receive a POST request at the url specified by an env. var. // Receive a POST request at the url specified by an env. var.
app.post(`${config.urlEndpoint}`, jsonParser, function (req, res, next) { app.post(`${config.urlEndpoint}`, jsonParser, function (req, res, next) {
if (!req.body || !req.body.action) { if (!req.body || !req.body.action) {
return res.sendStatus(400); return res.sendStatus(400);
} else if (!bot.needsFunding(req)) { } else if (!bot.needsFunding(req)) {
return res.sendStatus(204); return res.sendStatus(204);
} }
validation = validateRequest(req); validation = validateRequest(req);
if (validation.correct) { if (validation.correct) {