Giter Club home page Giter Club logo

tamarack's Introduction

Build Status Coverage Status

Tamarack

A bot built with Python Tornado to automate common pull request tasks.

Specifically designed for use with the Salt repository.

WARNING: This project is very new and subject to change without notice.

This bot listens for pull request events coming from GitHub and responds to them as needed.

The first task this bot was written to do was to analyze newly opened Pull Requests and check if the files changed match any of the entries in the CODEOWNERS file. If any matches are found, the bot will comment on the Pull Request and mention the matching owners.

Dependencies

Tamarack requires a minimum version of:

Set Up

  1. Clone this repo
  2. Install Tornado
  3. Configure GitHub Webhooks
  4. Set environment variables
  5. Run the server

GitHub Webhooks

To configure a web hook, navigate to the project's settings page and click on the Webhooks section. Complete the following:

  • Payload URL: (https://your-tamarack-server.com/events)
  • Content type: application/json
  • Secret: your-secret (see HOOK_SECRET_KEY information below)
  • Select the "Let me select individual events." radio button, then check Pull request.

Then, click Add Webhook.

NOTE: Tamarack presently only cares about payloads that come to the /events endpoint. Please be sure that /events is at the end of the Payload URL setting.

Environment Variables

Tamarack needs a couple of configurations to be in place before it can start reacting to Pull Request events from GitHub. The following environment variables must be set:

  • GITHUB_TOKEN
  • HOOK_SECRET_KEY
  • PORT (optional)

GitHub Token

The GITHUB_TOKEN is the API token Tamarack will use to interact with the GitHub API. This token should be generated on the GitHub account that the bot will run as, comment on pull requests, etc.

To get started:

  1. Generate an API access token here.
  2. Set the token as an environment variable:
export GITHUB_TOKEN=your_github_token

Hook Secret Key

The HOOK_SECRET_KEY is generated on GitHub's WebHook settings page. This secret key is needed to limit requests to the /events endpoint only to payloads coming from GitHub.

To get started:

  1. Create a secret token at the CLI, using high entropy.
  2. Set the token in the 'Secret' field of the bot's GitHub WebHook settings page.
  3. Click 'Update WebHook'.
  4. Set the token as an environment variable:
export HOOK_SECRET_KEY=your_secret_key

Port

The PORT environment variable configures the port that Tamarack uses. This variable is optional. The default is set to 8080. To use a different port, set the environment variable:

export PORT=1234

Running Tamarack

Once the GitHub web hook is arranged and the environment variables are set, it is now time to run the server:

python server.py

The server should be listening for events coming from GitHub and responding to them appropriately.

Development

When testing new features and code changes for Tamarack, it is a good idea to set up some personal GitHub API tokens, a web hook on your own repository, and to run Tamarack in a virtual environment.

ngrok can be used to easily expose a local server to use as your web hook URL for payloads.

Simply place the URL that ngrok gave you when you started it in the Payload URL section of your Web hook settings and save the changes. (Remember to place /events at the end of the URL.) Then restart Tamarack.

The payload URL will look something like this:

http://12345678.ngrok.io/events

tamarack's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

denza ch3ll mikeg98

tamarack's Issues

Add ability to re-run certain tests when they fail

Occasionally tests fail for various reasons and we don't get any results back. We should add the ability to check for test results and if they're missing, automatically re-run those tests.

The easiest ones to start with would be the docs and lint tests.

The scenario could go something like:

  • Test results come back from Jenkins
  • Pylint is marked as failed.
  • There are no results in the "Violations" page
  • Bot comments with "re-run lint"

This depends on #5 being completed. It also would make sense to fix #3 before this issue.

Add ability to comment on PRs lint tests fail

We need to add the ability to comment on PRs we test results come back from Jenkins. The easiest one to start with would likely be the pylint run. If the pylint run fails are there are results available, comment on the PR to let the user know.

Something like:

@<user-name>: There is a lint failure on this pull request. The lint items must be fixed before the pull request can be merged.

<link-to-lint-violations-page>

Add mention-bot like commenting ability to tamarack

mention-bot has not been working correctly for months now, and today they archived the project.

This is a useful service and we could still benefit from it greatly. Let's implement it here with the correct "this was inspired by" text.

The ability to comment on the given PR is already there. We just need to parse out the logic of how to determine who should be pinged in the review request comment.

Add ability to post to slack when new branch is created

We want to be able to simply notify people when a new branch is created in the repo. This can be simple, using Slack's Incoming Webhooks.

Workflow:

  • A new branch is created upstream in GH
  • Event is sent to Tamarack
  • Tamarack posts the message to slack

Tasks:

  • Update GH token perms to include branch creation events
  • Create Slack App
  • Update config/env vars to take a Workspace Webhook URL for Slack
  • Add event handler for branch creation events
  • Compose json POST message and send to slack
  • Docs
  • Tests
  • Deploy!

Add ability to use a config file instead of environment variables

In some circumstances, environment variables are nice and good to use. However, as the project grows, it would be nice to configure certain options. Before we can figure out what those options are, we need to add support for a config file in general.

A great option to move from environment variable to config file would be the PORT option. We can build on it from there.

Add ability for bot to comment on PRs when merge-conflicts occur

If a PR is merged and causes another PR to have a merge conflict, we should have the bot comment on the PR and ask the user to fix it and rebase.

Is there an event from GitHub that we can react to for this? If yes, this is easiest.

If no, we could poll through the list of PRs and comment. However, we need a mechanism for if the bot has already notified the user of the conflict. (Sort of like how stale-bot uses the "stale" label to track what issues are newly stale and what issues should be closed.)

[bug] Don't re-request team reviews if the PR is already approved by the team

Because of the the way review_request events get triggered instead of opened on some PRs, this action handling will occasionally re-trigger review requests on PRs, even if the team has already approved the PR.

You can see this happening here: saltstack/salt#46002

When I requested the review from Mike, it triggered a review_request event and so the bot added team-core and team-transport back on the review list, even though those teams have already approve the PR. We need to account for this here.

If the team has already approved the PR, we need to make sure we filter that out in the API event back to GitHub.

Add ability to request reviews automatically

Originally, GitHub was still working out the API for requesting team reviews. I no longer see the warnings about this feature being in development mode on the API docs, so I need to add this ability. It should be easy to add.

We can keep the comment functionality that is currently there, but it is probably just better to auto-request team reviewers instead.

Relevant API docs: https://developer.github.com/v3/pulls/review_requests/#create-a-review-request and see team_reviewers input.

Restrict PR reviews on Merge-Forwards

We don't need to request reviews from all teams on merge-forwards. GitHub will request a review from team-core automatically because of the CODEOWNERS file and the team permissions, but we can skip these types of PRs for the other teams.

Easiest thing to do would be to add a check to search for "Merge forward" in the title of the PR, like we used to do for mention bot.

Improve Checking for Reviewers

Now that it's possible to assign reviewers directly on PRs, the GitHub webhook payload has changed as well. Let's leverage this instead of pulling down the CODEOWNERS file and parsing it. That's extra work we don't need to do.

The team payload looks something like this:

{
  "action": "review_requested",
  "number": 45897,
  "pull_request": {
    "url": "https://api.github.com/repos/saltstack/salt/pulls/45897",
    "id": 167730763,
<snipped>
    "requested_reviewers": [

    ],
    "requested_teams": [
      {
        "name": "team-boto",
        "id": foo,
        "slug": "team-boto",
        "description": "Boto Reviewers",
        <snipped>
      }
    ],
<snipped>
}

So, let's use that list of requested_teams and figure out what requested_reviewers might look like and handle that as well.

The way we're doing this currently is fine and it works, but we can reduce the # of API calls by half if we just use the data in the given webhook payload.

Create tests for files already present

Some unit tests need to be created for this repo so we can get started on the right foot. Let's use pytest ;)

@gtmanfred - Let's do this! We can chat about what this might look like moving forward if you like.

I will work on getting some docs together for this repo as well. But for now, the python parts should be able to have some tests running quickly. Then we can make a plan for getting tests running on PRs using travis or jenkins or whatever you like for now.

Create some documentation!

There will be a lot of docs to add, but here's a list to get started:

  • How to set up the bot to run in general
  • How to set up the bot to test on your own repo (should include things like helpful tips for using ngrok, etc.)
  • How the CODEOWNERS file in the salt stack repo works with the PR review comments.

Convert print statements to use logging

To get this up and running, it was easy to just print output to the console. Before this project gets too much bigger, we should convert these statements to use a log handler.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.