Skip to content

Commit a9a3474

Browse files
authored
fix: Add npm version and fix app setup (#215)
* fix: Add npm version and fix app setup * Update README * Update README with local setup instructions
1 parent 6f15586 commit a9a3474

File tree

4 files changed

+34
-55
lines changed

4 files changed

+34
-55
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ versions.json
1717
.svn
1818
/credentials.json
1919
*.pem
20+
.env

README.md

+19-26
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,28 @@
11
[![Build Status](https://github.com/eslint/eslint-github-bot/workflows/CI/badge.svg)](https://github.com/eslint/eslint-github-bot/actions)
22

3-
ESLint GitHub bot
4-
==========================
3+
# ESLint GitHub bot
54

65
`eslint-github-bot` is a bot created with [probot](https://github.com/probot/probot) which automates some common tasks for repositories run by the ESLint team.
76

8-
The bot can perform the following tasks:
9-
10-
* **Triage** - adds the "triage" label to newly-created issues which don't have labels.
11-
* **Commit message check** - adds a status check to pull requests to verify that they follow ESLint's [pull request guidelines](https://eslint.org/docs/developer-guide/contributing/pull-requests#step-2-make-your-changes)
12-
* **Needs info** - adds a comment to issues requesting more information when a maintainer adds the `needs info` label.
13-
* **Release/TSC meeting issues** - creates a new issue with the `release`/`tsc meeting` label scheduled two weeks later, after another release/TSC meeting issue is closed.
14-
* **Release monitor** - searches the repository for an issue with the `release` and `patch release pending` labels, indicating that a patch release might soon be created from `master`. If an issue is found, adds a pending status check to all PRs that would require a semver-minor release, to prevent anyone from accidentally merging them.
15-
* **Issue Archiver** - Locks and adds a label to issues which have been closed for a while
16-
* **Issue Closer** - Closes and adds a label to issues which have been inactive for a while
17-
* **WIP Tracking** - adds pending status check for PRs with WIP in the title or with "do not merge" label, and marks the status check as successful once the WIP indicators are removed.
18-
* **PR ready to merge** (experimental) - adds a label to all PRs which are "ready to merge", defined by the following criteria:
19-
* At least one review is approved.
20-
* Build status is `success`.
21-
* **Check unit tests** (experimental) - makes sure a PR contains unit tests. This check will be ignored for PRs with `Build|Chore|Docs|Upgrade` in the commit message.
22-
* **Duplicate comments** (inactive) - removes all the duplicates comments by this bot and leaves the last one of each type.
7+
## Environment Variables:
8+
9+
* `APP_ID` (required): The numeric GitHub app ID
10+
* `PRIVATE_KEY` (required): the contents of the private key you downloaded after creating the app.
11+
* `WEBHOOK_SECRET` (required): Secret setup for GitHub webhook or you generated when you created the app.
12+
* `PORT`: Port for web server _(optional, defaults to 8000)_.
2313

2414
## :wrench: Setup
2515

26-
* Clone this repo.
16+
* Clone this repo
2717
* `npm install`
28-
* Start the app
29-
* `npm start` to start it as a GitHub APP
18+
* `npm test`
3019

31-
### ENV variables required:
20+
To start the server locally, you'll need:
3221

33-
* `PORT`: Port for web server _(optional, defaults to 8000)_.
34-
* `SECRET`: Secret setup for GitHub webhook or you generated when you created the app.
35-
* `PRIVATE_KEY`: the contents of the private key you downloaded after creating the app.
36-
* `APP_ID`: The numeric app ID
22+
* A PEM file
23+
* A `.env` file that specifies the required environment variables
24+
25+
The `APP_ID` and `WEBHOOK_SECRET` need to be present but need not be the registered application ID or webhook secret to start the server. `PRIVATE_KEY` must be a valid PEM private key.
3726

3827
#### Adding plugins
3928

@@ -45,4 +34,8 @@ To add a plugin:
4534

4635
## Deployment
4736

48-
The bot is deployed to a [Dokku](https://dokku.com) instance named github-bot.eslint.org and is installed as a GitHub Application at the organization level.
37+
The bot is deployed to a [Dokku](https://dokku.com) instance named <https://github-bot.eslint.org> and is installed as a GitHub Application at the organization level.
38+
39+
### Health Check
40+
41+
<https://github-bot.eslint.org/ping>

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"testEnvironment": "node"
5555
},
5656
"engines": {
57-
"node": "22.x"
57+
"node": "22.x",
58+
"npm": "10.x"
5859
}
5960
}

src/app.js

+12-28
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,19 @@
99
// Requirements
1010
//-----------------------------------------------------------------------------
1111

12-
const { Probot, run } = require("probot");
12+
const { run } = require("probot");
1313
const plugins = require("./plugins");
1414

1515
//-----------------------------------------------------------------------------
1616
// Type Definitions
1717
//-----------------------------------------------------------------------------
1818

1919
/** @typedef {import("probot").Probot} Probot */
20-
/** @typedef {import("probot").Context<any>} ProbotContext */
21-
/** @typedef {import("probot").ProbotOctokit} ProbotOctokit */
2220

2321
//-----------------------------------------------------------------------------
2422
// Main
2523
//-----------------------------------------------------------------------------
2624

27-
if (!process.env.SECRET) {
28-
throw new Error("Missing 'SECRET' environment variable");
29-
}
30-
31-
if (!process.env.PRIVATE_KEY) {
32-
throw new Error("Missing 'PRIVATE_KEY' environment variable");
33-
}
34-
35-
if (!process.env.APP_ID) {
36-
throw new Error("Missing 'APP_ID' environment variable");
37-
}
38-
39-
const port = process.env.PORT || 8000;
40-
const app = new Probot({
41-
privateKey: process.env.PRIVATE_KEY,
42-
appId: process.env.APP_ID,
43-
secret: process.env.SECRET,
44-
port
45-
});
46-
4725
const enabledPlugins = new Set([
4826
"commitMessage",
4927
"needsInfo",
@@ -52,10 +30,16 @@ const enabledPlugins = new Set([
5230
"wip"
5331
]);
5432

55-
// load all the enabled plugins from inside plugins folder
56-
Object.keys(plugins)
57-
.filter(pluginId => enabledPlugins.has(pluginId))
58-
.forEach(pluginId => app.load(plugins[pluginId]));
33+
/**
34+
* Assign the plugins to the robot.
35+
* @param {Probot} robot The Probot instance.
36+
* @returns {void}
37+
*/
38+
function appFn(robot) {
39+
Object.keys(plugins)
40+
.filter(pluginId => enabledPlugins.has(pluginId))
41+
.forEach(pluginId => plugins[pluginId](robot));
42+
}
5943

6044
// start the server
61-
run(app);
45+
run(appFn);

0 commit comments

Comments
 (0)