Skip to content

Commit

Permalink
feat: upgrade to Probot v10 / deploy to Vercel (#330)
Browse files Browse the repository at this point in the history
Basically a rewrite, but plenty of code has been reused from previous contributors


Co-authored-by: Frederick Fogerty <frederick.fogerty@gmail.com>
Co-authored-by: Jake Bolam <jake.bolam@gmail.com>
Co-authored-by: Jeff Wen <sinchangwen@gmail.com>
Co-authored-by: Jérémie Astor <astor.jeremie@wanadoo.fr>
Co-authored-by: Kyle Martin <kyle.martin@hotmail.co.nz>
Co-authored-by: Maximilian Berkmann <maxieberkmann@gmail.com>
Co-authored-by: Michael Fix <mrfix84@gmail.com>
Co-authored-by: mralwin <owendthiele@gmail.com>
Co-authored-by: Nicolas Goutay <phacks@users.noreply.github.com>
Co-authored-by: Owen Thiele <owendthiele@gmail.com>
Co-authored-by: Pierre Grimaud <grimaud.pierre@gmail.com>
Co-authored-by: Sang Lostrie <sang.lostrie@gmail.com>
Co-authored-by: Stefano Moia <s.moia@bcbl.eu>
  • Loading branch information
13 people committed Jan 1, 2021
1 parent 31fd74b commit 8a3f99d
Show file tree
Hide file tree
Showing 107 changed files with 16,746 additions and 12,411 deletions.
10 changes: 0 additions & 10 deletions .codecov.yml

This file was deleted.

10 changes: 0 additions & 10 deletions .editorconfig

This file was deleted.

13 changes: 0 additions & 13 deletions .env.example

This file was deleted.

3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

6 changes: 0 additions & 6 deletions .eslintrc.js

This file was deleted.

6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
title: ""
labels: bug
assignees: ''

assignees: ""
---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand Down
5 changes: 2 additions & 3 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
title: ""
labels: enhancement
assignees: ''

assignees: ""
---

**Is your feature request related to a problem? Please describe.**
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Test

on:
push:
branches:
- master

pull_request:
types:
- opened
- synchronize

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- run: npm ci
- run: npm test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
artifacts
coverage
node_modules
package-lock.json # We use yarn ;)
yarn.lock

.env
*.pem
Expand All @@ -10,3 +10,5 @@ yarn-error.log
.serverless
npm-debug.log
.idea

.vercel
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

7 changes: 0 additions & 7 deletions .releaserc.js

This file was deleted.

1 change: 0 additions & 1 deletion .yvmrc

This file was deleted.

4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Contributing

If you're interested in helping out, come join us on [Slack](https://join.slack.com/t/all-contributors/shared_invite/enQtNTE3ODMyMTA4NTk0LTUwZDMxZGZkMmViMzYzYzk2YTM2NjRkZGM5Yzc0ZTc5NmYzNWY3Y2Q0ZTY3ZmFhZDgyY2E3ZmIzNWQwMTUxZmE) for help getting-started [![Chat on Slack](https://img.shields.io/badge/slack-join-ff69b4.svg)](https://join.slack.com/t/all-contributors/shared_invite/enQtNTE3ODMyMTA4NTk0LTUwZDMxZGZkMmViMzYzYzk2YTM2NjRkZGM5Yzc0ZTc5NmYzNWY3Y2Q0ZTY3ZmFhZDgyY2E3ZmIzNWQwMTUxZmE)

For issues to work on, [see the issues tab](https://github.com/all-contributors/all-contributors-bot/issues)

## Resources:

- [Bot Architecture](contributing/bot-architecture.md)
- [Run bot locally](contributing/run-bot-locally.md)
- [Working with forks](contributing/working-with-forks.md)
- [Production: Deployments & Monitoring](contributing/deployments-and-monitoring.md)
- [Production: Deployments & Monitoring](contributing/deployments-and-monitoring.md)
1 change: 0 additions & 1 deletion IMPLEMENTATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ list, please [make a pull request](CONTRIBUTING.md)!
- [thechangelog org](https://github.com/thechangelog)
- [netlify-cms](https://github.com/netlify/netlify-cms)


**Note**: There are likely many projects not listed here. You'll probably be able to find more with this
[github search](https://github.com/search?utf8=%E2%9C%93&q=.all-contributorsrc+in%3Apath&type=Code&ref=searchresults)
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
🤖 A GitHub bot to automate acknowledging contributors to your open source projects.

## Motivation

Implementing the [All Contributors spec](https://github.com/all-contributors/all-contributors) by hand is a laborious process.

Enter the `@all-contributors bot`! The bot will automatically pull a user's profile, grab the contribution type emoji, update the project README and then open a Pull Request against the project :sparkles:
Expand All @@ -39,9 +40,11 @@ Enter the `@all-contributors bot`! The bot will automatically pull a user's prof
</a>

## Using the @all-contributors bot 🤖

If you're looking to use the bot, head over to the [bot docs on allcontributors.org](https://allcontributors.org/docs/en/bot/overview). The all-contributors website contains all the information required to install, configure and use the bot.

## Contributing

If you have suggestions for how the @all-contributors bot could be improved, or want to report a bug, [open an issue](https://github.com/all-contributors/all-contributors-bot/issues)!

For more, check out the [Contributing Guide](CONTRIBUTING.md).
Expand Down Expand Up @@ -80,6 +83,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/all-contri

<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome
Expand Down
11 changes: 11 additions & 0 deletions api/github/webhooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { createNodeMiddleware, createProbot } = require("probot");

const app = require("../../app");

This comment has been minimized.

Copy link
@LESEDE2580

LESEDE2580 Jul 5, 2021

trojen

const probot = createProbot({
overrides: {
// override default "/" path
webhookPath: "/api/github/webhooks",
},
});

module.exports = createNodeMiddleware(app, { probot });
69 changes: 69 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const isMessageByApp = require("./lib/is-message-by-app");
const isMessageForApp = require("./lib/is-message-for-app");
const CommentReply = require("./lib/modules/comment-reply");
const processIssueComment = require("./lib/process-issue-comment");
const { AllContributorBotError } = require("./lib/modules/errors");

/**
* @param {import('probot').Probot} app
*/
module.exports = (app) => {
app.on("issue_comment.created", async (context) => {
if (isMessageByApp(context)) return;
if (!isMessageForApp(context)) return;

// process comment and reply
const commentReply = new CommentReply(context);
try {
await processIssueComment({ context, commentReply });
} catch (error) {
const isKnownError = error instanceof AllContributorBotError;
if (!isKnownError) {
commentReply.reply(
`We had trouble processing your request. Please try again later.`
);

throw error;
}

context.log.info({ isKnownError, error: error.name }, error.message);
commentReply.reply(error.message);
} finally {
await commentReply.send();
}
});

app.on(
["installation", "installation_repositories"],
async ({ name, payload, log }) => {
const {
action,
repositories,
repositories_added,
repositories_removed,
installation,
} = payload;

const repositoriesChange =
action === "created"
? repositories.length
: action === "deleted"
? -repositories.length
: repositories_added
? repositories_added.length - repositories_removed.length
: 0;

const meta = {
event: name,
action,
account: installation.account.id,
accountType: installation.account.type.toLowerCase(),
accountLogin: installation.account.login,
installation: installation.id,
selection: installation.repository_selection,
repositoriesChange,
};
log.info(meta, `${meta.accountLogin}: ${name} ${action}`);
}
);
};
3 changes: 2 additions & 1 deletion contributing/bot-architecture.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Bot Architecture

Structure:

- `/src/tasks/processIsssueComment` is the root for incoming comments with the following sub components:
- `CommentReply`, deals with responding to a comment
- `ContentFiles`, or readmes files that will be re-generated and updated with the table
Expand All @@ -8,4 +10,3 @@ Structure:
- `utils/parse-comment` used for determining the intention of the users comment

Uses [Probot](https://github.com/probot/probot) for incoming events, and communicating/authenticating with github. [Probot docs](https://probot.github.io/docs/), [GitHub oktokit/restjs API docs](https://octokit.github.io/rest.js/)

5 changes: 3 additions & 2 deletions contributing/deployments-and-monitoring.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Production: Deployments & Monitoring

## Deployments

There is a sandbox environment:
https://github.com/all-contributors-sandbox


## Monitoring:

- [Thundra](https://console.thundra.io/functions/)
- [Sentry](https://sentry.io/all-contributors/github-bot/)
- [AWS Dashboard](https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#dashboards:name=All-Contributors-Bot)
- [AWS Lambda](https://console.aws.amazon.com/lambda/home?region=us-east-1#/functions/all-contributors-bot-prod-githubWebhook?tab=monitoring)
- [Bot Stats](https://gkioebvccg.execute-api.us-east-1.amazonaws.com/prod/probot/stats)
- [Analytics](https://analytics.amplitude.com/all-contributors)
- Coming Soon [All Contributors Usage Stats](d)
- Coming Soon [All Contributors Usage Stats](d)
22 changes: 16 additions & 6 deletions contributing/run-bot-locally.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,53 @@

# Local Bot Setup
> *IMPORTANT*: Please uninstall the production bot from your user account before continuing (otherwise multiple bots will respond to your comments)

> _IMPORTANT_: Please uninstall the production bot from your user account before continuing (otherwise multiple bots will respond to your comments)
To get your app running against GitHub

## 1. Create a GitHub App for testing

### 1.1 Go to your github [developer settings](https://github.com/settings/developers)

### 1.2 Create a [new github app](https://github.com/settings/apps/new)

Required fields are:

- `name`, which can be whatever you like, globally unique on github
- `homepage url`, which can be set to anything
- `webhook url`, which can be set to anything

Important fields are:

- `webhook secret`, set this to `development`
- `Permissions` which should be set [as defined in the app.yml](https://github.com/all-contributors/all-contributors-bot/blob/master/app.yml#L54), e.g. set read & write for `Repository contents`, `Issues` and `Pull Requests`, and read for `Repository Metadata`
- `Subscribe to Events` which should be set [as defined in the app.yml](https://github.com/all-contributors/all-contributors-bot/blob/master/app.yml#L15), e.g. check the checkbox for `Issue comment`
- Ensure `Where can this GitHub App be installed?` is set to `only this account`
![where can this app be installed](where-can-this-app-be-installed.png)
![where can this app be installed](where-can-this-app-be-installed.png)

## 2. Configure Your GitHub App for testing

You should now have an app created
![my test app](app-created.png)

- On the General Tab, Click `Generate Private Key` and download it for later usage, call it something like `allcontributorsbot.pem`
- On the Install Tab, Install the app/bot on your user


## 3. Configure Your local to talk to the github app

Copy `.env.example` and name it `.env`, replace the following lines with content from above.

```
APP_ID=
WEBHOOK_SECRET=development
PRIVATE_KEY=
```

- `APP_ID`, you can get this from the General tab on the developer settings for your app
- `WEBHOOK_SECRET`, leave as development (you set this on app setup)
- `PRIVATE_KEY` when you generated the private key from your app, you should have a `allcontributorsbot.pem` file locally (or similar). run `openssl base64 < allcontributorsbot.pem | tr -d '\n' | pbcopy` on the file which will copy the base64 contents onto your clipboard, paste that into the line for `PRIVATE_KEY`

## 4. Setup a test github repository/with issues PR

- Setup a repostiory under your name (the name on github where the bot is installed)
- Enable issues and pull requests
- Create an issue
Expand All @@ -47,12 +56,13 @@ PRIVATE_KEY=
To verify if the bot should have seen this goto [your app settings](https://github.com/settings/apps/). On the Advanced Tab, Click the most recent deliever to see the payload. It should look something like this:
![delivery comment](delivery-comment.png). Copy the payload and save it locally in a file called `test-webhook-payload.json`


## 5. Send your first hook

1. Install the node modules for the bot `yarn install`
2. Run the bot `yarn start`
3. Curl the bot (or use postman, with 2 headers and the content from `test-webhook-payload.json`)
If you're using curl it would look like:
If you're using curl it would look like:

```
curl -vX POST http://localhost:3000/ -d @test-webhook-payload.json \
--header "Content-Type: application/json" \
Expand Down
4 changes: 3 additions & 1 deletion contributing/working-with-forks.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Working with forks:

## Syncing a fork

1. `git remote add parent git@github.com:all-contributors/all-contributors-bot.git`
2. `git fetch parent`
3. `git checkout master` or `git checkout empty-contribs` (this branch on your fork)
4. `git merge parent/master`

See https://help.github.com/articles/syncing-a-fork/
See https://help.github.com/articles/syncing-a-fork/
Loading

1 comment on commit 8a3f99d

@vercel
Copy link

@vercel vercel bot commented on 8a3f99d Jan 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.