probot/docs/development.md

82 lines
3.8 KiB
Markdown
Raw Normal View History

2017-08-18 20:46:23 +08:00
---
next: docs/webhooks.md
---
2017-03-20 11:20:30 +08:00
2017-08-20 23:42:51 +08:00
# Developing an App
2017-08-18 20:46:23 +08:00
2017-08-20 23:42:51 +08:00
To develop a Probot app, you will first need a recent version of [Node.js](https://nodejs.org/) installed. Probot uses the `async/await` keywords, so Node.js 7.6 is the minimum required version.
2017-08-18 20:46:23 +08:00
2017-08-20 23:42:51 +08:00
## Generating a new app
2017-08-18 20:46:23 +08:00
[create-probot-app](https://github.com/probot/create-probot-app) is the best way to start building a new app. It will generate a new app with everything you need to get started and run your app in production.
2017-08-18 20:46:23 +08:00
2018-02-04 04:51:53 +08:00
To get started, run one of these commands:
2017-08-18 20:46:23 +08:00
2018-02-04 04:51:53 +08:00
- If you're using npm: `$ npx create-probot-app my-first-app`
- or, if you're using Yarn: `$ yarn create probot-app my-first-app`
2017-08-18 20:46:23 +08:00
2017-08-20 23:42:51 +08:00
This will ask you a series of questions about your app, which should look something like this:
2017-08-18 20:46:23 +08:00
```
Let's create a Probot app!
? App name: my-first-app
? Description of app: A "Hello World" GitHub App built with Probot
? Author's full name: Katie Horne
? Author's email address: katie@auth0.com
? Homepage:
? GitHub user or org name: khorne3
? Repository name: my-first-app
created file: my-first-app/.env.example
created file: my-first-app/.gitignore
created file: my-first-app/.travis.yml
created file: my-first-app/LICENSE
created file: my-first-app/README.md
created file: my-first-app/app.json
created file: my-first-app/index.js
created file: my-first-app/package-lock.json
created file: my-first-app/package.json
created file: my-first-app/docs/deploy.md
Finished scaffolding files!
Installing Node dependencies!
Done! Enjoy building your Probot app!
2017-08-18 20:46:23 +08:00
```
2017-08-20 23:42:51 +08:00
The most important files note here are `index.js`, which is where the code for your app will go, and `package.json`, which makes this a standard [npm module](https://docs.npmjs.com/files/package.json).
2017-08-18 20:46:23 +08:00
## Configure a GitHub App
2017-08-20 23:42:51 +08:00
To run your app in development, you will need to configure a GitHub App to deliver webhooks to your local machine.
2017-03-20 11:20:30 +08:00
1. On your local machine, copy `.env.example` to `.env`.
1. Go to [smee.io](https://smee.io) and click **Start a new channel**. Set `WEBHOOK_PROXY_URL` in `.env` to the URL that you are redirected to.
1. [Create a new GitHub App](https://github.com/settings/apps/new) with:
2018-01-12 11:51:39 +08:00
- **Webhook URL**: Use your `WEBHOOK_PROXY_URL` from the previous step.
2017-03-25 21:25:56 +08:00
- **Webhook Secret:** `development`
2017-08-22 05:33:59 +08:00
- **Permissions & events** is located lower down the page and will depend on what data you want your app to have access to. Note: if, for example, you only enable issue events, you will not be able to listen on pull request webhooks with your app. However, for development we recommend enabling everything.
2017-08-20 23:32:26 +08:00
1. Download the private key and move it to your project's directory.
1. Edit `.env` and set `APP_ID` to the ID of the app you just created. The App ID can be found in your app settings page here <img width="1048" alt="screen shot 2017-08-20 at 8 31 31 am" src="https://user-images.githubusercontent.com/13410355/29496168-044b9a48-8582-11e7-8be4-39cc75090647.png">
2018-01-12 11:51:39 +08:00
1. Run `$ npm start` to start the server/
2017-03-20 11:20:30 +08:00
You'll need to create a test repository and install your app by clicking the "Install" button on the settings page of your app.
2017-03-20 11:20:30 +08:00
2017-08-20 23:42:51 +08:00
## Running the app
2017-08-18 20:46:23 +08:00
2017-08-22 05:30:26 +08:00
Once you've set the `APP_ID` of your GitHub app in `.env` and downloaded the private key, you're ready to run your app.
2017-08-18 20:46:23 +08:00
```
$ npm start
> probot run ./index.js
Yay, the plugin was loaded!
2017-08-30 12:38:51 +08:00
18:11:55.838Z DEBUG Probot: Loaded plugin: ./index.js
2017-08-18 20:46:23 +08:00
```
2017-03-20 11:20:30 +08:00
2017-08-20 23:42:51 +08:00
Optionally, you can also run your app through [nodemon](https://github.com/remy/nodemon#nodemon) which will listen on any files changes in your local development environment and automatically restart the server. After installing nodemon, you can run `nodemon --exec "npm start"` and from there the server will automatically restart upon file changes.
2017-07-25 04:50:27 +08:00
2017-03-20 11:20:30 +08:00
## Debugging
2017-08-18 20:46:23 +08:00
1. Always run `$ npm install` and restart the server if `package.json` has changed.
2017-03-20 11:20:30 +08:00
1. To turn on verbose logging, start server by running: `$ LOG_LEVEL=trace npm start`