Skip to content

Commit

Permalink
Merge branch 'master' into #8
Browse files Browse the repository at this point in the history
  • Loading branch information
jbjonesjr committed Sep 11, 2017
2 parents 94029a2 + fc94a39 commit 3453615
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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');
Expand Down
48 changes: 14 additions & 34 deletions lib/freeze.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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) {
Expand All @@ -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: ' +
'<!-- ' + JSON.stringify(props) + '-->'
}));
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 3453615

Please sign in to comment.