Code For The Issue Label Bot, an App that automatically labels issues using machine learning, available on the GitHub Marketplace. This is also code for the blog article: "How to automate tasks on GitHub with machine learning for fun and profit"
Table of Contents
Install this app from the GitHub marketplace
A GitHub App powered by machine learning, written in Python. A discussion of the motivation for building this app is described in this blog post.
When an issue is opened, the bot predicts if the label should be a:
questionand applies a label automatically if appropriate. Here is a screenshot of the bot in action:
More examples can be viewed on our app's homepage. It should be noted that the bot may not apply any label in circumstances where the prediction is uncertain. See the disclaimers section for more caveats.
To utilize the code in this repository, you will need to register a GitHub App of your own and install this app on your desired repositories and store authentication secrets.
First, walk through the prerequisites section of this getting started guide except "The Ruby programming language" section as we will be using Python instead as the client that interfaces with the GitHub API.
Second, setup your development environment. Make sure you create a Webhook secret, even though this step is optional.
Finally, you need to create environment variables for all the secrets, which is described below.
PRIVATE_KEY: this is the private key you use to authenticate as an app with the GitHub API.
WEBHOOK_SECRET: this is used to verify that payloads received by your app are actually from GitHub. This is described here.
DATABASE_URL: this is the URL that contains the login information for your POSTGRESQL database, usually in the form:
APP_ID: this is a unique identifier provided to you by GitHub when you register your app.
FLASK_ENV: this is usually set to either
development. You will want to use
deploymentfor local testing.
PORT: this is the port your app will be serving on. Note that if you are deploying to Heroku, Heroku will override this variable with their own value when building your app. For local development, you will want this to match the port Smee is serving to.
APP_URL: this is the url for the homepage of your app that is provided to users as a link in issue comments. You can set this to an arbitrary value for local development.
pipenv installin the root of this repository.
Run the flask app: run
python flask_app/app.pyfrom the root of this repository. For this to work, you must correctly set the environment variables as described in the Environment Variables section.
Optional - Run app as docker container. A Docker container that serves Issue-Label Bot can be built with the command
bash script/bootstrapfrom the root of this repository. This script builds a Docker image named
hamelsmu/mlapp, which is also available on Dockerhub. If you desire to run the Docker container locally for testing, you must pass the necessary environment variables to the Docker container at runtime, as well as expose necessary ports for the app. See the References section for more resources on using Docker.
The assets in this repo allow you to deploy to Heroku (easier) or a Kubernetes cluster (more advanced).
productionif you are going to deploy the app publicly.
We welcome all forms of contributions. We are especially interested in the following:
The authors of this project are interested in adding the following features in the near future:
The code in this repo and associated tutorial(s) assume familiarity with Docker. This blog post offers a gentle introduction to Docker for data scientists.
Need inspiration for other data products you can build using machine learning and public GitHub datasets? See these examples:
Issue-Label Bot is for educational and demonstration purposes only. Our goal was to provide a minimal working example for the community with the least amount of complexity as possible. Therefore, we believe the model demonstrated has great room from improvement. Furthermore, this app only works on public repositories and will do nothing if installed on a private repo.