Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use require to load defaults once #14

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions etc/defaults.json

This file was deleted.

8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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');
const defaults = require('./lib/defaults');

/* Configuration Variables */

Expand All @@ -14,7 +14,7 @@ module.exports = robot => {
robot.on('schedule.repository', handleThaw);

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

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

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

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

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

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

Expand Down
7 changes: 7 additions & 0 deletions lib/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
probotUsername: (process.env.APP_NAME || 'probot-snooze') + '[bot]',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Workaround until #12 is implemented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbjonesjr oh, I forgot, this was the actual motivation for making this change. The bot name needs to be configurable until #12 is fixed. Would you reconsider this PR for that reason?

labelName: 'probot:snooze',
labelColor: 'gray',
defaultFreezeDuration: 7,
sampleFormat: '@probot, freeze this thread until 2100-01-01 with "A message I\'ll respond with"'
};
5 changes: 2 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const fs = require('fs');
const expect = require('expect');
const {createRobot} = require('probot');
const plugin = require('..');
Expand Down Expand Up @@ -224,7 +223,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, JSON.parse(fs.readFileSync('./etc/defaults.json', 'utf8')));
const freeze = new Freeze(github, require('../lib/defaults'));

validMessages.forEach(obj => {
const comment = {
Expand All @@ -248,7 +247,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, JSON.parse(fs.readFileSync('./etc/defaults.json', 'utf8')));
const freeze = new Freeze(github, require('../lib/defaults'));

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