24 lines
638 B
Python
24 lines
638 B
Python
"""Labels PRs based on title. Must be run in a github action with the
|
|
pull_request_target event."""
|
|
from github import Github
|
|
import os
|
|
import json
|
|
import re
|
|
|
|
context_dict = json.loads(os.getenv("CONTEXT_GITHUB"))
|
|
|
|
repo = context_dict["repository"]
|
|
g = Github(context_dict["token"])
|
|
repo = g.get_repo(repo)
|
|
pr_number = context_dict["event"]["number"]
|
|
issue = repo.get_issue(number=pr_number)
|
|
title = issue.title
|
|
|
|
|
|
regex_to_labels = [(r"\bDOC\b", "Documentation"), (r"\bCI\b", "Build / CI")]
|
|
|
|
labels_to_add = [label for regex, label in regex_to_labels if re.search(regex, title)]
|
|
|
|
if labels_to_add:
|
|
issue.add_to_labels(*labels_to_add)
|