From f59d7ce840d6b35af0bf91dcd1c9000b61695533 Mon Sep 17 00:00:00 2001 From: Jordi Montes Date: Tue, 13 Mar 2018 17:27:23 +0000 Subject: [PATCH] Fixed contract address length and action condition --- bot/index.js | 4 ++-- index.js | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/bot/index.js b/bot/index.js index 1412120..cdc49e3 100644 --- a/bot/index.js +++ b/bot/index.js @@ -22,7 +22,7 @@ const logger = winston.createLogger({ const needsFunding = function (req) { - if (req.body.action === 'edited' || !req.body.hasOwnProperty('comment')) { + if (req.body.action !== 'edited' || !req.body.hasOwnProperty('comment')) { return false } else if (req.body.comment.user.login !== config.githubUsername) { return false @@ -43,7 +43,7 @@ const hasAddress = function (req) { const getAddress = function (req) { 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) { diff --git a/index.js b/index.js index 3d6b758..10ba9ad 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,6 @@ * and in case it's a comment that has "@autobounty " * awards that bounty to the address posted earlier in the thread (by the * commiteth bot). -* TODO tests * REVIEW parsing, non-persisting storage of addresses, hardcoded string length. * 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. app.post(`${config.urlEndpoint}`, jsonParser, function (req, res, next) { - + if (!req.body || !req.body.action) { return res.sendStatus(400); } else if (!bot.needsFunding(req)) { return res.sendStatus(204); } - validation = validateRequest(req); if (validation.correct) {