Skip to content

Commit

Permalink
Merge pull request #9 from jbjonesjr/probot-0.9.1-update
Browse files Browse the repository at this point in the history
Update Probot to v0.9.1 + others
  • Loading branch information
jbjonesjr committed Aug 21, 2017
2 parents 4ae2003 + e764f84 commit f87c9ba
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 57 deletions.
7 changes: 7 additions & 0 deletions etc/defaults.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"probotUsername" : "probot-snooze[bot]",
"labelName" : "probot:snooze",
"labelColor" : "gray",
"defaultFreezeDuration" : 7,
"sampleFormat" : "@probot, freeze this thread until 2100-01-01 with 'A message I\\'ll respond with'"
}
46 changes: 14 additions & 32 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const yaml = require('js-yaml');
const visitor = require('probot-visitor');
const fs = require('fs');
const createScheduler = require('probot-scheduler');
const Freeze = require('./lib/freeze');
const formatParser = require('./lib/format-parser');
const githubHelper = require('./lib/github-helper');
Expand All @@ -9,13 +9,12 @@ const githubHelper = require('./lib/github-helper');
module.exports = robot => {
robot.on('integration_installation.added', installationEvent);
robot.on('issue_comment', handleFreeze);
const visit = visitor(robot, {interval: 60 * 5 * 1000}, handleThaw);
robot.on('test.visit', async context => {
await handleThaw(75, context.payload.repository);
});
createScheduler(robot);

robot.on('schedule.repository', handleThaw);

async function installationEvent(context) {
const config = await getConfig(context.github, context.payload.repository);
const config = await context.config('probot-snooze.yml', JSON.parse(fs.readFileSync('./etc/defaults.json', 'utf8')));

context.github.issues.getLabel(context.repositories_added[0]({
name: config.labelName}).catch(() => {
Expand All @@ -27,7 +26,7 @@ module.exports = robot => {
}

async function handleFreeze(context) {
const config = await getConfig(context.github, context.payload.repository);
const config = await context.config('probot-snooze.yml', JSON.parse(fs.readFileSync('./etc/defaults.json', 'utf8')));
const freeze = new Freeze(context.github, config);

const comment = context.payload.comment;
Expand All @@ -40,14 +39,14 @@ module.exports = robot => {
}
}

async function handleThaw(installation, repository) {
const github = await robot.auth(installation.id);
const config = await getConfig(github, repository);
const freeze = new Freeze(github, config);
async function handleThaw(context) {
const config = await context.config('probot-snooze.yml', JSON.parse(fs.readFileSync('./etc/defaults.json', 'utf8')));

const freeze = new Freeze(context.github, config);

github.search.issues({q:'label:' + freeze.config.labelName, repo:repository.full_name}).then(resp => {
context.github.search.issues({q:'label:' + freeze.config.labelName, repo:context.repo().full_name}).then(resp => {
resp.data.items.forEach(issue => {
github.issues.getComments(githubHelper.parseCommentURL(issue.comments_url)).then(resp => {
context.github.issues.getComments(githubHelper.parseCommentURL(issue.comments_url)).then(resp => {
return freeze.getLastFreeze(resp.data);
}).then(lastFreezeComment => {
if (freeze.unfreezable(lastFreezeComment)) {
Expand All @@ -56,23 +55,6 @@ module.exports = robot => {
});
});
});
console.log('visitor/thaw run complete');
}

async function getConfig(github, repository) {
const owner = repository.owner.login;
const repo = repository.name;
const path = '.github/probot-snooze.yml';
let config = {};

try {
const resp = await github.repos.getContent({owner, repo, path});
config = Object.assign(yaml.safeLoad(Buffer.from(resp.data.content, 'base64').toString()) || {}, {perform:true});
} catch (err) {
console.log('error', err);
visit.stop(repository);
}

return Object.assign(config, {owner, repo, logger: robot.log});
console.log('scheduled thaw run complete');
}
};
8 changes: 0 additions & 8 deletions lib/defaults.js

This file was deleted.

4 changes: 2 additions & 2 deletions lib/freeze.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const GitHubHelper = require('./github-helper');

module.exports = class Freeze {

constructor(github, config = {}) {
constructor(github, config) {
this.github = github;
this.config = Object.assign({}, require('./defaults'), config);
this.config = config;
this.logger = config.logger || console;

this.nlp = this.getSnoozeBravey();
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
"dependencies": {
"chrono-node": "^1.3.4",
"bravey": "^0.1.2",
"js-yaml": "^3.8.3",
"moment": "^2.18.1",
"probot": "0.7.5",
"probot-visitor": "0.2.0"
"probot": "0.9.1",
"probot-scheduler": "1.0.2"
},
"devDependencies": {
"eslint-config-probot": ">=0.1.0",
Expand Down
24 changes: 12 additions & 12 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require('fs');
const expect = require('expect');
const {createRobot} = require('probot');
const plugin = require('..');
Expand Down Expand Up @@ -42,7 +43,7 @@ perform: true
},
name:'public-repo'
}, {
body:'@probot, we should snooze this for a while, until July 1, 2018 13:30 <!-- {"assignee":"baxterthehacker","unfreezeMoment":"2016-06-01T17:30:00.000Z","message":"Hey, we\'re back awake!"}-->',
body:'@probot, we should snooze this for a while, until July 1, 2017 13:30 <!-- {"assignee":"baxterthehacker","unfreezeMoment":"2017-07-01T17:30:00.000Z","message":"Hey, we\'re back awake!"}-->',
user: {
login:'probot-snooze[bot]'
},
Expand Down Expand Up @@ -100,7 +101,7 @@ perform: true
});

it('posts a snooze comment - no label', async () => {
commentEvent.payload.comment.body = '@probot, we should snooze this for a while, until July 1, 2018 13:30';
commentEvent.payload.comment.body = '@probot, we should snooze this for a while, until July 1, 2017 13:30';
await robot.receive(commentEvent);

expect(github.repos.getContent).toHaveBeenCalledWith({
Expand All @@ -125,13 +126,13 @@ perform: true
number: 2,
owner: 'baxterthehacker',
repo: 'public-repo',
body: 'Sure thing. I\'ll close this issue for a bit. I\'ll ping you around 07/01/2018 :clock1: ' +
'<!-- ' + JSON.stringify({assignee:'baxterthehacker', unfreezeMoment :chrono.parseDate('July 1, 2018 13:30'), message:'Hey, we\'re back awake!'}) + '-->'
body: 'Sure thing. I\'ll close this issue for a bit. I\'ll ping you around 07/01/2017 :clock1: ' +
'<!-- ' + JSON.stringify({assignee:'baxterthehacker', unfreezeMoment :chrono.parseDate('July 1, 2017 13:30'), message:'Hey, we\'re back awake!'}) + '-->'
});
});

it('posts a snooze comment - with label', async () => {
commentEvent.payload.comment.body = '@probot, we should snooze this for a while, until July 1, 2018 13:30';
commentEvent.payload.comment.body = '@probot, we should snooze this for a while, until July 1, 2017 13:30';
commentEvent.payload.issue.labels.push({
url: 'https://api.github.com/repos/baxterthehacker/public-repo/labels/probot:freeze',
name: 'probot:freeze',
Expand Down Expand Up @@ -159,16 +160,16 @@ perform: true
number:2,
owner: 'baxterthehacker',
repo: 'public-repo',
body: 'Sure thing. I\'ll close this issue for a bit. I\'ll ping you around 07/01/2018 :clock1: ' +
'<!-- ' + JSON.stringify({assignee:'baxterthehacker', unfreezeMoment :chrono.parseDate('July 1, 2018 13:30'), message:'Hey, we\'re back awake!'}) + '-->'
body: 'Sure thing. I\'ll close this issue for a bit. I\'ll ping you around 07/01/2017 :clock1: ' +
'<!-- ' + JSON.stringify({assignee:'baxterthehacker', unfreezeMoment :chrono.parseDate('July 1, 2017 13:30'), message:'Hey, we\'re back awake!'}) + '-->'
});
});

it('test visitor activation', async () => {
await robot.receive({
event: 'test',
event: 'schedule',
payload: {
action: 'visit',
action: 'repository',
repository: {
owner: {
login:'baxterthehacker'
Expand Down Expand Up @@ -223,7 +224,7 @@ perform: true
{msg:'Thanks for looking into this.\n\nSo i\'m out of office for the next three weeks. I\'m going to snooze this until I get back on 07/21/17.', props:{assignee: 'baxterthehacker', message: 'Hey, we\'re back awake!', unfreezeMoment: moment(chrono.parseDate('next three weeks'))}}
];

const freeze = new Freeze(github, {});
const freeze = new Freeze(github, JSON.parse(fs.readFileSync('./etc/defaults.json', 'utf8')));

validMessages.forEach(obj => {
const comment = {
Expand All @@ -247,8 +248,7 @@ perform: true
{msg:'snooze until 07/11/17 at 14:00, and "bug Seth"', props:{assignee: 'baxterthehacker', message: 'bug Seth', unfreezeMoment: moment(chrono.parseDate('07/11/17 at 14:00'))}},
{msg:'hey @probot, snooze this issue', props:{assignee: 'baxterthehacker', message: 'Hey, we\'re back awake!', unfreezeMoment: moment().add(defaultFreezeDuration, 'days').format()}}
];

const freeze = new Freeze(github, {});
const freeze = new Freeze(github, JSON.parse(fs.readFileSync('./etc/defaults.json', 'utf8')));

msgs.forEach(obj => {
const comment = {
Expand Down

0 comments on commit f87c9ba

Please sign in to comment.