Skip to main content

Automatically label Github pull requests based on elements of the PR title. Expects Jira style ticket code(PROJ-100) in PR title

Project description

pull_request_auto_labeler

Automatically label Github pull requests based on elements of the PR title. Default configuration expects Jira style ticket code(PROJ-100) in PR title

This labeler does the following:

  • get all open Pull Requests for all the repositories for an organization/user
  • check each PR to see if it has any matching a Jira style ticket code in the title (PROJ-100)
  • apply a label to the Pull Request matching the uppercase version of the project codes from the title (PROJ)

PyPI version

Installation

If you want to run this as a cron, you can install from pypi with pip: pip install pull-request-auto-labeler

But if you're going to set this up as an AWS Lambda, you'll want the serverless.yaml, serverless-requirements.txt and handler.py so you might as well pull the source.

Setup

Set the following enviornment vars:

  • [Required] GITHUB_API_TOKEN: A Github API Token which has access to read the repositories you want and modify pull requests. If you don't have one you see the guide here
  • [Required] ORGANIZATION: the name of the github organization/username that you want to check PRs for.
  • [Optional] LABEL_EXTRACTING_REGEX: Regex expression which will be applied on the PR title using python's re.findall.
    • This regex expression should have one matching group which returns the portion of the title which should be used as a label. i.e. if the regex finds PROJ-100, the matching group should be PROJ
    • Since we're using re.findall this can have multiple matches on the title, but each match must have only one group.
    • Default is \s*[\[]*([a-zA-Z0-9]{2,})[-|\s][0-9]+ which matches: PROJ-100, [PROJ-100], B2C-1, Proj 100.

Running from command line

python auto_labeler.py

Running as a Cron on AWS Lambda

For convenience I've included setup instructions to run this as a cron using aws lambda made easy by the serverless toolkit. If you haven't used serverless, I have a getting started with serverless guide here

Install serverless plugins

serverless-python-requirements

Its pretty annoying to add external requirements to a lambda when deploying manually. You have to build the wheels for the packages on an aws linux ami and include those in the zip that you upload. Luckily, there's a serverless plugin to make that all super easy.

sls plugin install -n serverless-python-requirements

Setup serverless for this project

  • Copy the serverless.yaml, serverless-requirements.txt and handler.py files in this repo to wherever you're using this, or simply download this repo and use that as your source
  • tweak any provider params you need to to match your setup
  • Set the run frequency (update under functions>lambdaCron>events>schedule)

Deploy to AWS

sls deploy

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pull_request_auto_labeler-0.12.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

pull_request_auto_labeler-0.12-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file pull_request_auto_labeler-0.12.tar.gz.

File metadata

  • Download URL: pull_request_auto_labeler-0.12.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.3

File hashes

Hashes for pull_request_auto_labeler-0.12.tar.gz
Algorithm Hash digest
SHA256 8fd37424e5ce835cbb6d4a9a74b947c883734c078d03b71996f3c31d67953a67
MD5 db05de96c66b0908aaaafecfa02830ce
BLAKE2b-256 992479b946e820cf84972a050e816ac146ac0fabe835a1d40a3999649adeef67

See more details on using hashes here.

File details

Details for the file pull_request_auto_labeler-0.12-py3-none-any.whl.

File metadata

  • Download URL: pull_request_auto_labeler-0.12-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.3

File hashes

Hashes for pull_request_auto_labeler-0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 d4d448a7159359ab83ce6aaa7c17f380f1411a4f97aee7564ee130f7d8ad7a1c
MD5 70d3832e938e7b8159ca6bd50fa525ef
BLAKE2b-256 2d829ff70a597ed9e9e21419b93f05e0a2b946fa53f861f0b06b413df97a2a08

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page