jasonkuster / merge-bot

An automatic merge robot for the ASF.
http://mergebot-vm.apache.org:8080
Apache License 2.0
2 stars 5 forks source link
bot

merge-bot

MergeBot is a bot for automatically merging pull requests with a mainline repository. It was written for the Apache Infrastructure team by Jason Kuster.

Usage

Authorized committers can comment on a pull request @asfgit merge. MergeBot polls repositories every fifteen seconds and upon seeing a request to merge will queue it and begin the merge process.

Implementation Info

MergeBot is written in Python and implemented in two parts: a frontend and a backend. These two pieces share information via a SQLite database; the backend writes info, and the frontend formats the information for viewing by users.

Frontend

The frontend is written using the Flask Python web framework. It is laid out as follows

The database is laid out as follows:

Poller

QueuedItem

WorkItemStatus

Backend

The backend is implemented via three complementary components.

mergebot.py

mergebot.py owns the overall mergebot process -- it is responsible for reading in configs and spinning up subprocesses for each of the projects for which MergeBot is configured.

mergebot_poller.py

mergebot_poller.py is in charge of polling an SCM for changes. Currently GitHub is the only SCM available, but MergeBot has been designed to allow for triggering from other SCM systems.

Currently the GitHub poller reads from GitHub every 15 seconds, looking for either new PRs, or PRs which have been updated since the last time it checked. When it notices a PR, it checks the PR for any of the commands available (currently only merge) and that the comments have been made by an authorized user. Once this is validated, it takes the appropriate step -- in the case of merge, adding the PR to the merge queue.

merge.py

merge.py owns the process of actually merging a pull request. It reads the merge queue from mergebot_poller.py and performs the merges in the order in which they were received. Merges proceed in a few phases.

All of these phases are communicated via WorkItemStatus updates.