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

Remove configuration #27

Merged
merged 1 commit into from
Apr 5, 2018
Merged
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
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@ Use the `/remind` slash command to set a reminder on any comment box on GitHub a
<img width="797" alt="screen shot 2017-09-15 at 6 48 56 pm" src="https://user-images.githubusercontent.com/13410355/30493981-99505cfe-9a46-11e7-8738-3652da872141.png">

## Usage
1. **[Configure the GitHub App](https://github.com/apps/reminders)**
2. Start using the `/reminders` command on the repository.
3. Optionally, add a `.github/config.yml` to customize the app:

```yml
reminders:
# Label applied to issues with pending reminders
label: reminder
```
1. **[Install the GitHub App](https://github.com/apps/reminders)**
2. Start using the `/reminders` command on the repository.

## Setup

Expand Down
32 changes: 6 additions & 26 deletions lib/reminders.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ const moment = require('moment')
const metadata = require('probot-metadata')
const parseReminder = require('parse-reminder')

const defaults = {
reminders: {
label: 'reminder'
}
}
const LABEL = 'reminder'

module.exports = {
async set (context, command) {
Expand All @@ -17,17 +13,9 @@ module.exports = {
reminder.who = context.payload.comment.user.login
}

let config

try {
config = await context.config('config.yml', defaults)
} catch (err) {
config = defaults
}

const {labels} = context.payload.issue
if (!labels.find(({name}) => name === config.reminders.label)) {
labels.push(config.reminders.label)
if (!labels.find(({name}) => name === LABEL)) {
labels.push(LABEL)
}
await context.github.issues.edit(context.issue({labels}))

Expand All @@ -45,16 +33,8 @@ module.exports = {
},

async check (context) {
let config

try {
config = await context.config('config.yml', defaults)
} catch (err) {
config = defaults
}

const {owner, repo} = context.repo()
const q = `label:"${config.reminders.label}" repo:${owner}/${repo}`
const q = `label:"${LABEL}" repo:${owner}/${repo}`

const resp = await context.github.search.issues({q})

Expand All @@ -72,11 +52,11 @@ module.exports = {
await context.github.issues.removeLabel({owner,
repo,
number,
name: config.reminders.label
name: LABEL
})
} else if (moment(reminder.when) < moment()) {
const labels = issue.labels
const frozenLabel = labels.find(({name}) => name === config.reminders.label)
const frozenLabel = labels.find(({name}) => name === LABEL)
const pos = labels.indexOf(frozenLabel)
labels.splice(pos, 1)

Expand Down
11 changes: 0 additions & 11 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ describe('reminders', () => {
getInstallations: jest.fn()
},
paginate: jest.fn(),
repos: {
// Response for getting content from '.github/config.yml'
getContent: jest.fn().mockImplementation(() => Promise.resolve({
data: {content: Buffer.from(`reminders:\n label: reminder`).toString('base64')}
}))
},
issues: {
createComment: jest.fn(),
edit: jest.fn(),
Expand Down Expand Up @@ -132,11 +126,6 @@ describe('reminders', () => {
test('test visitor activation', async () => {
await robot.receive(scheduleEvent)

expect(github.repos.getContent).toHaveBeenCalledWith({
owner: 'baxterthehacker',
repo: 'public-repo',
path: '.github/config.yml'
})
expect(github.issues.edit).toHaveBeenCalledWith({
labels: [],
owner: 'baxterthehacker',
Expand Down