From 1d74ee29512f33d55cb4df79f464dc4a5ba52685 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Tue, 29 Aug 2017 08:10:07 -0500 Subject: [PATCH 1/9] Add repo to search query --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 84f3fd7..7a267a1 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 => { resp.data.items.forEach(issue => { context.github.issues.getComments(githubHelper.parseCommentURL(issue.comments_url)).then(resp => { return freeze.getLastFreeze(resp.data); From a29eaa164bd412a81956ed59f7f80322fb194a14 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Tue, 29 Aug 2017 08:46:22 -0500 Subject: [PATCH 2/9] Skip unfreeze if no freeze comment found Fixes #8 --- index.js | 2 +- lib/freeze.js | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 84f3fd7..24a452b 100644 --- a/index.js +++ b/index.js @@ -49,7 +49,7 @@ module.exports = robot => { context.github.issues.getComments(githubHelper.parseCommentURL(issue.comments_url)).then(resp => { return freeze.getLastFreeze(resp.data); }).then(lastFreezeComment => { - if (freeze.unfreezable(lastFreezeComment)) { + if (lastFreezeComment && freeze.unfreezable(lastFreezeComment)) { freeze.unfreeze(issue, formatParser.propFromComment(lastFreezeComment)); } }); diff --git a/lib/freeze.js b/lib/freeze.js index 05f321c..0f58dca 100644 --- a/lib/freeze.js +++ b/lib/freeze.js @@ -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) { From e42b2f7c5cb7ef669abc365fea8bb3083ae4f2cc Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Tue, 29 Aug 2017 08:46:56 -0500 Subject: [PATCH 3/9] Use moment to parse time for comment --- lib/freeze.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/freeze.js b/lib/freeze.js index 0f58dca..dd7d47e 100644 --- a/lib/freeze.js +++ b/lib/freeze.js @@ -51,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: ' + '' })); } From 61ef34c45f8c142630fb76b111d26baa2e1d5cbd Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Wed, 6 Sep 2017 20:39:55 -0500 Subject: [PATCH 4/9] Remove commented out code --- lib/freeze.js | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/lib/freeze.js b/lib/freeze.js index 05f321c..baee8db 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(), @@ -85,43 +85,25 @@ 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'); + const commandEntity = new Bravey.StringEntityRecognizer('command'); commandEntity.addMatch('snooze', 'snooze'); commandEntity.addMatch('freeze', 'freeze'); 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 - // }; }); - /* */ 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; From 5462f21b32e48e639af1eb6f3de8953dcb42332b Mon Sep 17 00:00:00 2001 From: Jamie Jones Date: Fri, 8 Sep 2017 17:15:44 -0400 Subject: [PATCH 5/9] detail regex matching - add a comment about why regex parsing is hardwired to fail - hardwire it to fail in a safer way - not that it's safer, make the rest work --- lib/freeze.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/freeze.js b/lib/freeze.js index baee8db..7a0cbe4 100644 --- a/lib/freeze.js +++ b/lib/freeze.js @@ -91,17 +91,20 @@ module.exports = class Freeze { robotEntity.addMatch('robot', 'probot'); robotEntity.addMatch('robot', 'robot'); + 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('foo bar (.*) again'), () => { - return undefined; + responseEntity.addMatch(new RegExp('====== (.*) ======='), (match) => { + return match; }); - nlp.addEntity(robotEntity); - nlp.addEntity(commandEntity); nlp.addEntity(responseEntity); nlp.addDocument('{cognomen}, {command} this thread until dtg. remind me to {reopen_text}', 'snooze_request'); From d9467c982c14998acaada820e53d6709e65a1a97 Mon Sep 17 00:00:00 2001 From: Jamie Jones Date: Fri, 8 Sep 2017 17:22:59 -0400 Subject: [PATCH 6/9] shouldn't be able to get to that failure --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 24a452b..84f3fd7 100644 --- a/index.js +++ b/index.js @@ -49,7 +49,7 @@ module.exports = robot => { context.github.issues.getComments(githubHelper.parseCommentURL(issue.comments_url)).then(resp => { return freeze.getLastFreeze(resp.data); }).then(lastFreezeComment => { - if (lastFreezeComment && freeze.unfreezable(lastFreezeComment)) { + if (freeze.unfreezable(lastFreezeComment)) { freeze.unfreeze(issue, formatParser.propFromComment(lastFreezeComment)); } }); From 94fafd65b76f63cbcd50ff5124a8a6649a2eccc0 Mon Sep 17 00:00:00 2001 From: Jamie Jones Date: Sat, 9 Sep 2017 00:16:48 -0400 Subject: [PATCH 7/9] update probot, dependencies --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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": { From 47e05bc9394549fdfdadbaa59f51651a45c91097 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Sat, 9 Sep 2017 14:08:04 -0500 Subject: [PATCH 8/9] Fix lint errors --- lib/freeze.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/freeze.js b/lib/freeze.js index 8337bf9..3d8f7f0 100644 --- a/lib/freeze.js +++ b/lib/freeze.js @@ -93,10 +93,10 @@ module.exports = class Freeze { 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 + + // 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('====== (.*) ======='), (match) => { + responseEntity.addMatch(new RegExp('====== (.*) ======='), match => { return match; }); From 9e6e116c8d510e61eb4aede4d61c4fc853ad48f1 Mon Sep 17 00:00:00 2001 From: Jamie Jones Date: Sun, 10 Sep 2017 14:13:00 -0400 Subject: [PATCH 9/9] remove yarn from circle build --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: