├── .env.example ├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── __tests__ └── index.tests.js ├── app.json ├── docs └── deploy.md ├── index.js └── package.json /.env.example: -------------------------------------------------------------------------------- 1 | # The ID of your GitHub App 2 | APP_ID= 3 | WEBHOOK_SECRET=development 4 | 5 | # Uncomment this to get verbose logging 6 | # LOG_LEVEL=trace # or `info` to show less 7 | 8 | # Subdomain to use for localtunnel server. Defaults to your local username. 9 | # SUBDOMAIN= 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | *.pem 4 | .env 5 | package-lock.json 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - "7.7.1" 5 | notifications: 6 | disabled: true 7 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at clarkbw@github.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | [fork]: /fork 4 | [pr]: /compare 5 | [style]: https://github.com/prettier/prettier 6 | [code-of-conduct]: CODE_OF_CONDUCT.md 7 | 8 | Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great. 9 | 10 | Please note that this project is released with a [Contributor Code of Conduct][code-of-conduct]. By participating in this project you agree to abide by its terms. 11 | 12 | ## Submitting a pull request 13 | 14 | 1. [Fork][fork] and clone the repository 15 | 1. Configure and install the dependencies: `npm install` 16 | 1. Make sure the tests pass on your machine: `npm test`, note: these tests also apply the linter, so no need to lint seperately 17 | 1. Create a new branch: `git checkout -b my-branch-name` 18 | 1. Make your change, add tests, and make sure the tests still pass 19 | 1. Push to your fork and [submit a pull request][pr] 20 | 1. Pat your self on the back and wait for your pull request to be reviewed and merged. 21 | 22 | Here are a few things you can do that will increase the likelihood of your pull request being accepted: 23 | 24 | - Follow the [style guide][style] which is using standard. Any linting errors should be shown when running `npm test` 25 | - Write and update tests. 26 | - Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests. 27 | - Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html). 28 | 29 | Work in Progress pull request are also welcome to get feedback early on, or if there is something blocked you. 30 | 31 | ## Resources 32 | 33 | - [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) 34 | - [Using Pull Requests](https://help.github.com/articles/about-pull-requests/) 35 | - [GitHub Help](https://help.github.com) 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) , Bryan Clark 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Task List Zero 2 | 3 | > a GitHub App built with [probot](https://github.com/probot/probot) that blocks 4 | > merging a PR while there are unchecked items in your task list. 5 | > Get Task List Zero! 6 | 7 | ![](https://user-images.githubusercontent.com/2134/32394182-7d2260b2-c099-11e7-93af-3c3ced3fa244.gif) 8 | 9 | ## Setup 10 | 11 | ``` 12 | # Install dependencies 13 | npm install 14 | 15 | # Run the bot 16 | npm start 17 | ``` 18 | 19 | See [docs/deploy.md](docs/deploy.md) if you would like to run your own instance of this app. 20 | -------------------------------------------------------------------------------- /__tests__/index.tests.js: -------------------------------------------------------------------------------- 1 | const plugin = require('..'); 2 | 3 | const { createRobot } = require('probot'); 4 | 5 | describe('block-on-task-list', () => { 6 | let robot; 7 | let github; 8 | 9 | beforeEach(() => { 10 | robot = createRobot(); 11 | plugin(robot); 12 | 13 | github = { 14 | repos: { 15 | createStatus: jest.fn(() => Promise.resolve()) 16 | } 17 | }; 18 | 19 | robot.auth = () => Promise.resolve(github); 20 | }); 21 | 22 | describe('listens to correct events', () => { 23 | beforeEach(() => { 24 | github.repos.createStatus.mockReset(); 25 | }); 26 | 27 | it('creates a status when a PR is edited', async () => { 28 | // Simulates delivery of a payload 29 | await robot.receive({ 30 | event: 'pull_request', 31 | payload: { 32 | action: 'edited', 33 | pull_request: { 34 | title: 'title', 35 | body: 'body', 36 | head: { 37 | sha: '0781b461a8c12ac1ac8b2d511cb7621fbf1160ea' 38 | } 39 | }, 40 | repository: { 41 | owner: { 42 | login: 'clarkbw' 43 | } 44 | }, 45 | installation: { 46 | id: 64798 47 | } 48 | } 49 | }); 50 | // This test would pass if in your main code you called `context.github.issues.createComment` 51 | expect(github.repos.createStatus).toHaveBeenCalled(); 52 | }); 53 | it('creates a status when a PR is opened', async () => { 54 | // Simulates delivery of a payload 55 | await robot.receive({ 56 | event: 'pull_request', 57 | payload: { 58 | action: 'opened', 59 | pull_request: { 60 | title: 'title', 61 | body: 'body', 62 | head: { 63 | sha: '0781b461a8c12ac1ac8b2d511cb7621fbf1160ea' 64 | } 65 | }, 66 | repository: { 67 | owner: { 68 | login: 'clarkbw' 69 | } 70 | }, 71 | installation: { 72 | id: 64798 73 | } 74 | } 75 | }); 76 | // This test would pass if in your main code you called `context.github.issues.createComment` 77 | expect(github.repos.createStatus).toHaveBeenCalled(); 78 | }); 79 | it('creates a status when a PR is reopened', async () => { 80 | // Simulates delivery of a payload 81 | await robot.receive({ 82 | event: 'pull_request', 83 | payload: { 84 | action: 'reopened', 85 | pull_request: { 86 | title: 'title', 87 | body: 'body', 88 | head: { 89 | sha: '0781b461a8c12ac1ac8b2d511cb7621fbf1160ea' 90 | } 91 | }, 92 | repository: { 93 | owner: { 94 | login: 'clarkbw' 95 | } 96 | }, 97 | installation: { 98 | id: 64798 99 | } 100 | } 101 | }); 102 | // This test would pass if in your main code you called `context.github.issues.createComment` 103 | expect(github.repos.createStatus).toHaveBeenCalled(); 104 | }); 105 | }); 106 | 107 | describe('correctly sets status', () => { 108 | beforeEach(() => { 109 | github.repos.createStatus.mockReset(); 110 | }); 111 | 112 | it('does not block when checkboxes are not present', async () => { 113 | // Simulates delivery of a payload 114 | await robot.receive({ 115 | event: 'pull_request', 116 | payload: { 117 | action: 'edited', 118 | pull_request: { 119 | title: 'title', 120 | body: 'This is the text of a PR', 121 | head: { 122 | sha: '0781b461a8c12ac1ac8b2d511cb7621fbf1160ea' 123 | } 124 | }, 125 | repository: { 126 | owner: { 127 | login: 'clarkbw' 128 | } 129 | }, 130 | installation: { 131 | id: 64798 132 | } 133 | } 134 | }); 135 | // This test would pass if in your main code you called `context.github.issues.createComment` 136 | expect(github.repos.createStatus).toHaveBeenCalled(); 137 | expect(github.repos.createStatus.mock.calls[0][0].state).toEqual( 138 | 'success' 139 | ); 140 | }); 141 | it('does not block when checked checkboxes are present', async () => { 142 | // Simulates delivery of a payload 143 | await robot.receive({ 144 | event: 'pull_request', 145 | payload: { 146 | action: 'edited', 147 | pull_request: { 148 | title: 'title', 149 | body: 'Text text text\r\n\r\n- [x] 1st item\r\n- [x] 2nd item\r\n', 150 | head: { 151 | sha: '0781b461a8c12ac1ac8b2d511cb7621fbf1160ea' 152 | } 153 | }, 154 | repository: { 155 | owner: { 156 | login: 'clarkbw' 157 | } 158 | }, 159 | installation: { 160 | id: 64798 161 | } 162 | } 163 | }); 164 | // This test would pass if in your main code you called `context.github.issues.createComment` 165 | expect(github.repos.createStatus).toHaveBeenCalled(); 166 | expect(github.repos.createStatus.mock.calls[0][0].state).toEqual( 167 | 'success' 168 | ); 169 | }); 170 | it('does block when some checkboxes are unchecked', async () => { 171 | // Simulates delivery of a payload 172 | await robot.receive({ 173 | event: 'pull_request', 174 | payload: { 175 | action: 'edited', 176 | pull_request: { 177 | title: 'title', 178 | body: 179 | 'Text text text\r\n\r\n- [x] 1st item\r\n- [ ] 2nd item\r\n- [x] 3rd item\r\n', 180 | head: { 181 | sha: '0781b461a8c12ac1ac8b2d511cb7621fbf1160ea' 182 | } 183 | }, 184 | repository: { 185 | owner: { 186 | login: 'clarkbw' 187 | } 188 | }, 189 | installation: { 190 | id: 64798 191 | } 192 | } 193 | }); 194 | // This test would pass if in your main code you called `context.github.issues.createComment` 195 | expect(github.repos.createStatus).toHaveBeenCalled(); 196 | expect(github.repos.createStatus.mock.calls[0][0].state).toEqual( 197 | 'pending' 198 | ); 199 | }); 200 | }); 201 | }); 202 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "PRIVATE_KEY": { 4 | "description": "the private key you downloaded when creating the GitHub App" 5 | }, 6 | "APP_ID": { 7 | "description": "the ID of your GitHub App" 8 | }, 9 | "WEBHOOK_SECRET": { 10 | "description": "the secret configured for your GitHub App" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /docs/deploy.md: -------------------------------------------------------------------------------- 1 | # Deploying 2 | 3 | If you would like to run your own instance of this app, see the [docs for deployment](https://probot.github.io/docs/deployment/). 4 | 5 | This app requires these **Permissions & events** for the GitHub App: 6 | 7 | > **TODO**: List permissions required for deployment here. See [probot/stale](https://github.com/probot/stale/blob/master/docs/deploy.md) for an example. 8 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = robot => { 2 | robot.on( 3 | [ 4 | "pull_request.opened", 5 | "pull_request.edited", 6 | "pull_request.synchronize", 7 | "pull_request.reopened" 8 | ], 9 | context => { 10 | const title = context.payload.pull_request.title; 11 | const body = context.payload.pull_request.body; 12 | const isUnChecked = /-\s\[\s\]/g.test(body); 13 | const status = isUnChecked ? "pending" : "success"; 14 | 15 | robot.log( 16 | `Updating PR "${title}" (${context.payload.pull_request 17 | .html_url}): ${status}` 18 | ); 19 | 20 | context.github.repos.createStatus( 21 | context.repo({ 22 | sha: context.payload.pull_request.head.sha, 23 | state: status, 24 | target_url: "https://github.com/settings/apps/task-list-zero", 25 | description: status 26 | ? "task list not completed yet" 27 | : "ready for the next steps", 28 | context: "Task List Zero" 29 | }) 30 | ); 31 | } 32 | ); 33 | }; 34 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "block-on-task-list", 3 | "version": "1.0.0", 4 | "description": "", 5 | "author": "Bryan Clark ", 6 | "license": "ISC", 7 | "repository": "https://github.com/clarkbw/block-on-task-list.git", 8 | "scripts": { 9 | "start": "probot run ./index.js", 10 | "test": "jest" 11 | }, 12 | "dependencies": { 13 | "probot": "^3.0.0" 14 | }, 15 | "devDependencies": { 16 | "jest": "^21.2.1", 17 | "localtunnel": "^1.8.2" 18 | }, 19 | "engines": { 20 | "node": ">= 7.7.0", 21 | "npm": ">= 4.0.0" 22 | } 23 | } 24 | --------------------------------------------------------------------------------