diff --git a/.circleci/config.yml b/.circleci/config.yml index c9ab76e..d948fc1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,7 +26,7 @@ # fallback to using the latest cache if no exact match is found - v1-dependencies- - - run: yarn install + - run: npm install - save_cache: paths: diff --git a/index.js b/index.js index 9b29c8c..688c31a 100644 --- a/index.js +++ b/index.js @@ -43,8 +43,10 @@ module.exports = robot => { const config = await context.config('probot-snooze.yml', JSON.parse(fs.readFileSync('./etc/defaults.json', 'utf8'))); const freeze = new Freeze(context.github, config); + const {owner, repo} = context.repo(); + const q = `label:"${freeze.config.labelName}" repo:${owner}/${repo}`; - context.github.search.issues({q:'label:' + freeze.config.labelName, repo:context.repo().full_name}).then(resp => { + context.github.search.issues({q}).then(resp => { if (resp.data.total_count > 0) { resp.data.items.forEach(issue => { context.github.issues.getComments(githubHelper.parseCommentURL(issue.comments_url)).then(resp => { @@ -58,6 +60,7 @@ module.exports = robot => { robot.log(new Date() + ': ' + issue.comments_url + ' didn\'t find the snooze comment'); } }); + }); } else { console.log(new Date() + ': No issues found to thaw at this time'); diff --git a/lib/freeze.js b/lib/freeze.js index 05f321c..3d8f7f0 100644 --- a/lib/freeze.js +++ b/lib/freeze.js @@ -23,7 +23,7 @@ module.exports = class Freeze { propsHelper(assignee, commentBody) { const pd = formatParser.parseDateFromComment(commentBody); - // Console.log('parsed this comment: ', commentBody, '\nParsed this date: ', pd, pd.isValid()); + return { assignee, unfreezeMoment: pd.isValid() ? pd : moment().add(this.config.defaultFreezeDuration, 'days').format(), @@ -32,15 +32,9 @@ module.exports = class Freeze { } getLastFreeze(comments) { - let mainComment = {}; - comments.reverse().some(comment => { - if (comment.user.login === this.config.probotUsername) { - mainComment = comment; - return true; - } - return false; + return comments.reverse().find(comment => { + return comment.user.login === this.config.probotUsername; }); - return mainComment; } freeze(context, props) { @@ -57,7 +51,8 @@ module.exports = class Freeze { })); this.github.issues.createComment(context.issue({ - body: 'Sure thing. I\'ll close this issue for a bit. I\'ll ping you around ' + props.unfreezeMoment.calendar() + ' :clock1: ' + + body: 'Sure thing. I\'ll close this issue for a bit. I\'ll ping you around ' + + moment(props.unfreezeMoment).calendar() + ' :clock1: ' + '' })); } @@ -85,43 +80,28 @@ module.exports = class Freeze { nlp.addIntent('snooze_request', [{entity: 'cognomen', id: 'cognomen'}, {entity: 'command', id: 'command'}, {entity: 'reopen_text', id:'reopen_text'}]); - const robotEntity = - new Bravey.StringEntityRecognizer('cognomen'); + const robotEntity = new Bravey.StringEntityRecognizer('cognomen'); robotEntity.addMatch('robot', '@probot'); robotEntity.addMatch('robot', '@probot-freeze'); robotEntity.addMatch('robot', 'probot'); robotEntity.addMatch('robot', 'robot'); - const commandEntity = - new Bravey.StringEntityRecognizer('command'); + nlp.addEntity(robotEntity); + + const commandEntity = new Bravey.StringEntityRecognizer('command'); commandEntity.addMatch('snooze', 'snooze'); commandEntity.addMatch('freeze', 'freeze'); + nlp.addEntity(commandEntity); + + // Regex Entity parsing does not currently work. It causes a recursive f(x) that crashes node. That's why const responseEntity = new Bravey.RegexEntityRecognizer('reopen_text'); - /* ResponseEntity.addMatch(new RegExp('remind me to (.*) again'), vals => { */ - responseEntity.addMatch(new RegExp('foo bar (.*) again'), () => { - return undefined; - // Return { - // position: 1, - // entity: 'reopen_text', - // value: 'foo', - // string: 'foo', - // priority: .9 - // }; + responseEntity.addMatch(new RegExp('====== (.*) ======='), match => { + return match; }); - /* */ - nlp.addEntity(robotEntity); - nlp.addEntity(commandEntity); nlp.addEntity(responseEntity); - // Nlp.addDocument("{command_name} this issue", "snooze_request", {fromTaggedSentence: true}); - // nlp.addDocument("{command_name} this thread until dtg", "snooze_request", {fromTaggedSentence: true}); - // nlp.addDocument("Hey {robot_address}! Will you {command_name} this issue until dtg?", "snooze_request", {fromTaggedSentence: true}); - // nlp.addDocument("I'm going to pause this for the time being. I'll {command_name} this til dtg", "snooze_request", {fromTaggedSentence: true}); - - // nlp.addDocument("", "snooze_request", {fromTaggedSentence: true}); - nlp.addDocument('{cognomen}, {command} this thread until dtg. remind me to {reopen_text}', 'snooze_request'); return nlp; diff --git a/package.json b/package.json index 8f1702f..545b768 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,10 @@ "test": "mocha && xo --extend probot" }, "dependencies": { - "chrono-node": "^1.3.4", "bravey": "^0.1.2", + "chrono-node": "^1.3.4", "moment": "^2.18.1", - "probot": "0.9.1", + "probot": "^0.11.0", "probot-scheduler": "1.0.2" }, "devDependencies": {