-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial commits #1
Open
pyokagan
wants to merge
15
commits into
se-edu:master
Choose a base branch
from
pyokagan:initial
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
011a4a7
Initial commit
pyokagan d4b29ed
server: add source-map-support
pyokagan 01e70df
server: implement support for ".env" files
pyokagan eb1554e
server: implement "Hello world!" web server
pyokagan 4129757
Implement testing support with mocha
pyokagan 096f261
lib/github: implement Github webhook support
pyokagan 6a5404a
logic: implement logic architecture
pyokagan 142ea4d
lib/github: support making authenticated API requests
pyokagan 9a24daa
logic: implement github API support
pyokagan c35a85e
logic: praise PR authors when their PRs are merged
pyokagan 5325ddd
logs: implement logging
pyokagan 627d9a4
lib/github: implement forEachPage() helper function
pyokagan 805a9a7
lib/Auth: implement support for authenticated user sessions
pyokagan 1eb4f04
logs: only allow organization members to access them
pyokagan d1fc430
README.adoc changes from dogfooding
pyokagan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 4 | ||
trim_trailing_whitespace = true | ||
charset = utf-8 | ||
max_line_length = 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/node_modules/ | ||
/npm-debug.log | ||
/se-edu-bot-*.tgz | ||
/dist/ | ||
/.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
language: node_js | ||
|
||
node_js: | ||
- "7" | ||
|
||
script: npm run all build lint test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright 2017 seedu-bot contributors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: npm start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,298 @@ | ||
= se-edu-bot | ||
:toc: preamble | ||
:toc-title: | ||
:sectnums: | ||
ifdef::env-github[] | ||
:tip-caption: :bulb: | ||
:note-caption: :information_source: | ||
endif::[] | ||
ifdef::env-github,env-browser[:outfilesuffix: .adoc] | ||
|
||
Helps out with managing SE-EDU projects. | ||
|
||
== Local development setup | ||
|
||
=== Prerequisites | ||
|
||
. Node `7.9.0` or later. | ||
. An editor with Typescript language service support is strongly recommended. | ||
(e.g. https://code.visualstudio.com/[VS Code]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a Note that for VSCode, the |
||
. https://ngrok.com/[ngrok] | ||
|
||
=== Cloning the repo | ||
|
||
. Fork this repo, and clone the fork to your computer. | ||
. `cd` into the project directory. | ||
. Run `npm install` to install dependencies. | ||
|
||
=== Setting up ngrok | ||
|
||
We use https://ngrok.com/[ngrok] to expose our local server to the internet for Webhook testing. | ||
Run | ||
|
||
---- | ||
ngrok http 5000 | ||
---- | ||
|
||
You should see a line like this: | ||
|
||
---- | ||
Forwarding https://abcdefg123.ngrok.io -> localhost:5000 | ||
---- | ||
|
||
This is your temporary ngrok URL which exposes your local server to the internet. | ||
It is valid until the `ngrok` process terminates. | ||
Take note of it, we'll use it in later steps. | ||
|
||
=== Setting up a GitHub App | ||
|
||
.Creating the GitHub App | ||
. Go to your https://github.com/settings/apps[User Owned GitHub Apps] page and click on `Register a new GitHub App`. | ||
. Fill in the details as follows: | ||
(replace `https://abc123.ngrok.io` with your temporary ngrok URL which you got in <<Setting up ngrok>>) | ||
|
||
Github App Name:: | ||
Give a name to identify the bot (e.g. `se-edu-bot`) | ||
|
||
Homepage URL:: | ||
The URL to your fork. | ||
|
||
User authorization callback URL:: | ||
`https://abc123.ngrok.io/auth/login/callback` | ||
|
||
Webhook URL:: | ||
`https://abc123.ngrok.io/webhook` | ||
|
||
Webhook Secret:: | ||
Fill in a random string (preferably generated with a cryptographically secure random string generator). | ||
Take note of it, as you will need it later for setting `GITHUB_WEBHOOK_SECRET` in the <<Environment variables>>. | ||
+ | ||
NOTE: Yes, *any* random string. | ||
|
||
Permissions:: | ||
Select the following, leaving the rest at their default: | ||
|
||
* Issues: `Read & write` | ||
** Webhook events: `Issue comment`, `Issues`. | ||
* Pull requests: `Read & write` | ||
** Webhook events: `Pull request`, `Pull request review`, `Pull request review comment` | ||
|
||
Where can this app be installed?:: | ||
Ensure `Only on this account` is selected. | ||
|
||
. Click `Create GitHub App` to create your GitHub App. | ||
. You will then be taken to your GitHub App's page. | ||
This page will show your GitHub App's ID. | ||
You will need to set it later as the `GITHUB_APP_ID` in the <<Environment variables>>. | ||
+ | ||
This page will also show the OAuth client ID and secret of your GitHub App. | ||
You will need to set it later as the `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET` respectively in the <<Environment variables>>. | ||
|
||
. You will also need to generate a private key for the GitHub App. | ||
Click on `Generate private key`, and save the file to a known location. | ||
You will need its *full* contents later for setting the `GITHUB_APP_PRIVATE_KEY` in the <<Environment variables>>. | ||
|
||
.Installing the GitHub App | ||
. Next, we will need to install the GitHub App. Click on `Install`. | ||
. Select `All repositories` and then click `Install` to install your GitHub App on all your GitHub repositories. | ||
. You will be taken to the installation page which has the URL with the format | ||
`https://github.com/settings/installations/INSTALLATION_ID` | ||
(or `https://github.com/organizations/ORGANIZATION_NAME/settings/installations/INSTALLATION_ID` for organizations) | ||
where `INSTALLATION_ID` is the installation ID number. | ||
You will need to set it later as the `GITHUB_INSTALLATION_ID` in the <<Environment variables>>. | ||
|
||
NOTE: Since your ngrok URL is temporary, | ||
you will need to reconfigure your GitHub App each time you get a new temporary URL. | ||
(Not applicable for herokuapp URLs) | ||
|
||
=== Configuring environment variables | ||
|
||
Environment variables are used to configure the bot. | ||
See <<Environment variables>> for a full list of settings. | ||
|
||
For ease of development, | ||
se-edu-bot will automatically load environment variables defined in the `.env` file in the project root. | ||
|
||
This is done using https://github.com/motdotla/dotenv[dotenv]. | ||
See the aforementioned link for information on the `.env` file format. | ||
|
||
=== Building the project | ||
|
||
* Build the project once. | ||
+ | ||
[source,shell] | ||
---- | ||
npm run build | ||
---- | ||
|
||
* Do a clean build. | ||
+ | ||
[source,shell] | ||
---- | ||
npm run all clean build | ||
---- | ||
|
||
=== Running the server | ||
|
||
The project must be built first (`npm run build`). | ||
|
||
* Run the server | ||
+ | ||
[source,shell] | ||
---- | ||
npm start | ||
---- | ||
|
||
* Run the server and watch for changes, | ||
incrementally rebuilding the project and restarting the server whenever source files change. | ||
+ | ||
[source,shell] | ||
---- | ||
npm run watch | ||
---- | ||
|
||
The server should be accessible via your ngrok address which you got in <<Setting up ngrok>>. | ||
|
||
=== Linting | ||
|
||
[source,shell] | ||
---- | ||
npm run lint | ||
---- | ||
|
||
=== Running tests | ||
|
||
The project must be built first (`npm run build`). | ||
|
||
* Run tests once. | ||
+ | ||
[source,shell] | ||
---- | ||
npm test | ||
---- | ||
|
||
* Run tests and watch for changes, | ||
incrementally rebuilding the project and re-running tests whenever source files change. | ||
+ | ||
[source,shell] | ||
---- | ||
npm run test-watch | ||
---- | ||
|
||
=== Cleaning build products | ||
|
||
[source,shell] | ||
---- | ||
npm run clean | ||
---- | ||
|
||
== Deploying to Heroku | ||
|
||
This repository is setup to automatically deploy to Heroku whenever new commits are pushed to `master`. | ||
As such, there is no need for any manual deployment. | ||
|
||
Below is a guide for setting up the Heroku application from scratch should there be any need to (e.g. for testing). | ||
|
||
=== Setting up the Heroku application from scratch | ||
|
||
.Part 1: Set up Heroku App | ||
. Go to the https://dashboard.heroku.com[Heroku dashboard] and login. | ||
. `New` -> `Create new App`. | ||
. Enter the app name (i.e. `se-edu-bot`) and click `Create App`. | ||
. Under `Deployment method`, select `Github`. | ||
. If Heroku Dashboard does not have access to your GitHub account, | ||
it will display a single `Connect to GitHub` button. | ||
Click on it, and then authorize the Heroku Dashboard to access your GitHub account and `se-edu` organization. | ||
. Follow the instructions to connect the Heroku app to the `se-edu/se-edu-bot` repo. | ||
. Ensure the `Wait for CI to pass before deploy` checkbox is checked, and then click `Enable Automatic Deploys`. | ||
|
||
.Part 2: Set up GitHub App | ||
. On GitHub, go to https://github.com/settings/profile[Your profile page] -> Organization Settings -> `se-edu`. | ||
. Click on `Github Apps`. | ||
. Click on `Register a new GitHub App` | ||
. Follow the same steps as <<Setting up a GitHub App>>, | ||
except instead of using the `ngrok.io` hostname use the Heroku App's hostname (e.g. `https://se-edu-bot.herokuapp.com`) | ||
|
||
.Part 3: Continue setting up Heroku App | ||
. Go back to the https://dashboard.heroku.com[Heroku dashboard] and click on the `se-edu-bot` app to go to its page. | ||
. Go to `Settings` -> `Config Variables`, and set `NPM_CONFIG_PRODUCTION` to `false`. | ||
. Configure the rest of the <<Environment variables>>. | ||
+ | ||
WARNING: Make sure you set *all* required environment variables! | ||
|
||
. Next, to complete setting up the Heroku App, go back to the `Deploy` tab. | ||
Look for `Manual deploy`, ensure the `master` branch is selected and then click `Deploy`. | ||
. Hopefully, the deployment is successful. | ||
Visit the Heroku App's URL (e.g. `https://se-edu-bot.herokuapp.com`) and it should show `Hello world!`, | ||
indicating that the app was successfully set up. | ||
|
||
== Environment variables | ||
|
||
`PROXY`:: | ||
(Required) Set to `true` if se-edu-bot is served behind a reverse proxy (e.g. ngrok or heroku). | ||
Given that we host se-edu-bot on heroku and use ngrok for development, | ||
this should usually be set to `true`. | ||
|
||
`PORT`:: | ||
TCP port which the server will listen on. | ||
There is no need to explicitly set this on Heroku, | ||
as Heroku will automatically set the `PORT` environment variable. | ||
(Default: 5000) | ||
|
||
`GITHUB_WEBHOOK_SECRET`:: | ||
(Required) The webhook secret of the GitHub App. (See <<Setting up a GitHub App>>) | ||
|
||
`GITHUB_APP_ID`:: | ||
(Required) The GitHub App ID. (See <<Setting up a GitHub App>>) | ||
|
||
`GITHUB_APP_PRIVATE_KEY`:: | ||
(Required) The *full* contents of the GitHub App private key file. | ||
Newlines must be preserved. | ||
(See <<Setting up a GitHub App>>) | ||
|
||
`GITHUB_INSTALLATION_ID`:: | ||
(Required) The installation ID of the GitHub App. | ||
(See <<Setting up a GitHub App>>) | ||
|
||
`GITHUB_CLIENT_ID`:: | ||
(Required) The OAuth Client ID of the GitHub App. | ||
(See <<Setting up a GitHub App>>) | ||
|
||
`GITHUB_CLIENT_SECRET`:: | ||
(Required) The OAuth Client secret of the GitHub App. | ||
(See <<Setting up a GitHub App>>) | ||
|
||
== Architecture | ||
|
||
`lib/`:: | ||
Utility libraries. | ||
Try to avoid encoding policy within the code, | ||
instead pass options to them via the entry point (`server.ts`). | ||
|
||
`logic/`:: | ||
Code controlling the behavior of the bot. | ||
|
||
=== `logic` | ||
|
||
The bot's behavior is split into multiple logic components, | ||
each doing one thing. | ||
Each logic component is implemented as an individual file within the `logic/` directory. | ||
|
||
All logic components implement the `Logic` interface. | ||
Most logic components also inherit from the `BaseLogic` class, | ||
which provides some useful base functionality such as splitting the `webhookMiddleware()` method into event-specific callback methods. | ||
|
||
== Logging | ||
|
||
To facilitate debugging problems in production, | ||
se-edu-bot exposes its logs via the `/logs` endpoint. | ||
|
||
You need to be a member of the `se-edu` organization in order to access them. | ||
|
||
== Coding standard | ||
|
||
We follow the oss-generic coding standard. | ||
|
||
== License | ||
|
||
MIT License |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to specify required npm version as well.