Repository: JasonEtco/todo
Pull request #5 (2017-10-01 17:55:35)

Use `config.yml` instead of `todo.yml`
Use a `todo` object in the `.github/config.yml` file instead of a special `todo.yml` based on the suggestion by @hiimbex and the direction Probot is going (probably) 🍕 

This PR is also a good place to start using proper fixtures for config testing instead of feeble strings.


Patch:
diff --git a/.github/config.yml b/.github/config.yml
new file mode 100644
index 0000000..e0de16d
--- /dev/null
+++ b/.github/config.yml
@@ -0,0 +1,3 @@
+todo:
+  keyword: ":TODO:"
+  caseSensitive: true
diff --git a/.github/todo.yml b/.github/todo.yml
deleted file mode 100644
index 2d60f38..0000000
--- a/.github/todo.yml
+++ /dev/null
@@ -1,2 +0,0 @@
-keyword: ":TODO:"
-caseSensitive: true
\ No newline at end of file
diff --git a/README.md b/README.md
index 3c41f74..2ec8f6f 100644
--- a/README.md
+++ b/README.md
@@ -26,7 +26,13 @@ function ruleOverPunyHumans () {
 
 There are a couple of configuration options in case you need to change the default behaviour. Note that the defaults are likely fine for most projects, so you might not need to change them.
 
-Add a file called `todo.yml` in the `.github` folder at the root of your project.
+Add a `todo` object in your `.github/config.yml` file like this:
+
+```yml
+todo:
+  keyword: "@makeAnIssue"
+
+```
 
 ### Available options
 
diff --git a/index.js b/index.js
index f1e87bd..d6d2206 100644
--- a/index.js
+++ b/index.js
@@ -5,7 +5,8 @@ const commitIsInPR = require('./lib/commit-is-in-pr')
 
 module.exports = (robot) => {
   robot.on('push', async context => {
-    const cfg = await context.config('todo.yml', defaultConfig)
+    const config = await context.config('config.yml')
+    const cfg = {...defaultConfig, ...config.todo}
 
     // Get array of issue objects in the current repo
     const issues = await context.github.issues.getForRepo(context.repo())


Test patch:
diff --git a/__tests__/fixtures/configs/autoAssignArr.yml b/__tests__/fixtures/configs/autoAssignArr.yml
new file mode 100644
index 0000000..a3d9e4c
--- /dev/null
+++ b/__tests__/fixtures/configs/autoAssignArr.yml
@@ -0,0 +1,5 @@
+todo:
+  keyword: "@todo"
+  autoAssign:
+    - "JasonEtco"
+    - "matchai"
\ No newline at end of file
diff --git a/__tests__/fixtures/configs/autoAssignFalse.yml b/__tests__/fixtures/configs/autoAssignFalse.yml
new file mode 100644
index 0000000..5679329
--- /dev/null
+++ b/__tests__/fixtures/configs/autoAssignFalse.yml
@@ -0,0 +1,3 @@
+todo:
+  keyword: "@todo"
+  autoAssign: false
\ No newline at end of file
diff --git a/__tests__/fixtures/configs/autoAssignString.yml b/__tests__/fixtures/configs/autoAssignString.yml
new file mode 100644
index 0000000..3bb334c
--- /dev/null
+++ b/__tests__/fixtures/configs/autoAssignString.yml
@@ -0,0 +1,3 @@
+todo:
+  keyword: "@todo"
+  autoAssign: "matchai"
\ No newline at end of file
diff --git a/__tests__/fixtures/configs/basic.yml b/__tests__/fixtures/configs/basic.yml
new file mode 100644
index 0000000..43c3bee
--- /dev/null
+++ b/__tests__/fixtures/configs/basic.yml
@@ -0,0 +1,2 @@
+todo:
+  keyword: "@todo"
\ No newline at end of file
diff --git a/__tests__/fixtures/configs/caseSensitive.yml b/__tests__/fixtures/configs/caseSensitive.yml
new file mode 100644
index 0000000..d4230ca
--- /dev/null
+++ b/__tests__/fixtures/configs/caseSensitive.yml
@@ -0,0 +1,3 @@
+todo:
+  keyword: "@TODO"
+  caseSensitive: true
\ No newline at end of file
diff --git a/__tests__/fixtures/configs/caseSensitivePizza.yml b/__tests__/fixtures/configs/caseSensitivePizza.yml
new file mode 100644
index 0000000..0a5a45b
--- /dev/null
+++ b/__tests__/fixtures/configs/caseSensitivePizza.yml
@@ -0,0 +1,3 @@
+todo:
+  keyword: "pizza"
+  caseSensitive: true
\ No newline at end of file
diff --git a/__tests__/fixtures/configs/existing.yml b/__tests__/fixtures/configs/existing.yml
new file mode 100644
index 0000000..78cac00
--- /dev/null
+++ b/__tests__/fixtures/configs/existing.yml
@@ -0,0 +1,2 @@
+todo:
+  keyword: "@existing"
\ No newline at end of file
diff --git a/__tests__/index.js b/__tests__/index.js
index a1e2cb2..a034f19 100644
--- a/__tests__/index.js
+++ b/__tests__/index.js
@@ -1,8 +1,11 @@
 const {createRobot} = require('probot')
 const payloads = require('./fixtures/payloads')
 const app = require('..')
+const fs = require('fs')
+const path = require('path')
 
-function gimmeRobot (config = 'keyword: "@todo"') {
+function gimmeRobot (config = 'basic.yml') {
+  const cfg = fs.readFileSync(path.join(__dirname, 'fixtures', 'configs', config), 'utf8')
   let robot
   let github
   const content = (str) => Promise.resolve({ data: { content: Buffer.from(str) } })
@@ -18,8 +21,8 @@ function gimmeRobot (config = 'keyword: "@todo"') {
     repos: {
       // Response for getting content from '.github/todo.yml'
       getContent: jest.fn((obj) => {
-        if (obj.path.includes('todo.yml')) {
-          return content(config)
+        if (obj.path.includes('config.yml')) {
+          return content(cfg)
         } else if (obj.path === 'index.js') {
           return content('\n\n@todo Jason!\nsdfasd\nsdfas\ndsfsa\n\n\nsdfsdaf\n@existing An issue that exists\n\n\n\n')
         } else if (obj.path === 'another.js') {
@@ -64,7 +67,7 @@ describe('todo', () => {
   })
 
   it('creates an issue without assigning anyone', async () => {
-    const {robot, github} = gimmeRobot('autoAssign: false')
+    const {robot, github} = gimmeRobot('autoAssignFalse.yml')
     await robot.receive(payloads.basic)
     expect(github.issues.create).toBeCalledWith({
       body: "https://github.com/JasonEtco/test/blob/f7d286aa6381bbb5045288496403d9427b0746e2/index.js#L3-L8\n\n---\n\n###### This issue was generated by [todo](https://github.com/jasonetco/todo) based on a `@todo` comment in f7d286aa6381bbb5045288496403d9427b0746e2 in #10. It's been assigned to @JasonEtco because they committed the code.",
@@ -76,7 +79,7 @@ describe('todo', () => {
   })
 
   it('creates an issue and assigns the configured user', async () => {
-    const {robot, github} = gimmeRobot('autoAssign: "matchai"')
+    const {robot, github} = gimmeRobot('autoAssignString.yml')
     await robot.receive(payloads.basic)
     expect(github.issues.create).toBeCalledWith({
       body: "https://github.com/JasonEtco/test/blob/f7d286aa6381bbb5045288496403d9427b0746e2/index.js#L3-L8\n\n---\n\n###### This issue was generated by [todo](https://github.com/jasonetco/todo) based on a `@todo` comment in f7d286aa6381bbb5045288496403d9427b0746e2 in #10. It's been assigned to @JasonEtco because they committed the code.",
@@ -89,7 +92,7 @@ describe('todo', () => {
   })
 
   it('creates an issue and assigns the configured users', async () => {
-    const {robot, github} = gimmeRobot('autoAssign: ["JasonEtco", "matchai"]')
+    const {robot, github} = gimmeRobot('autoAssignArr.yml')
     await robot.receive(payloads.basic)
     expect(github.issues.create).toBeCalledWith({
       body: "https://github.com/JasonEtco/test/blob/f7d286aa6381bbb5045288496403d9427b0746e2/index.js#L3-L8\n\n---\n\n###### This issue was generated by [todo](https://github.com/jasonetco/todo) based on a `@todo` comment in f7d286aa6381bbb5045288496403d9427b0746e2 in #10. It's been assigned to @JasonEtco because they committed the code.",
@@ -108,19 +111,19 @@ describe('todo', () => {
   })
 
   it('respects the capitalization config', async () => {
-    const {robot, github} = gimmeRobot('keyword: "@TODO"\ncaseSensitive: true')
+    const {robot, github} = gimmeRobot('caseSensitive.yml')
     await robot.receive(payloads.complex)
     expect(github.issues.create.mock.calls.length).toBe(1)
   })
 
   it('does not create any issues', async () => {
-    const {robot, github} = gimmeRobot('keyword: "pizza"\ncaseSensitive: true')
+    const {robot, github} = gimmeRobot('caseSensitivePizza.yml')
     await robot.receive(payloads.complex)
     expect(github.issues.create.mock.calls.length).toBe(0)
   })
 
   it('does not create an issues that already exists', async () => {
-    const {robot, github} = gimmeRobot('keyword: "@existing"')
+    const {robot, github} = gimmeRobot('existing.yml')
     await robot.receive(payloads.complex)
     expect(github.issues.create.mock.calls.length).toBe(0)
   })