Skip to content

Commit

Permalink
CI Fixes regex label action labeler (scikit-learn#20229)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjpfan authored Jun 11, 2021
1 parent 95afec8 commit e71ae40
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
22 changes: 13 additions & 9 deletions .github/scripts/label_title_regex.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
"""Labels PRs based on title. Must be run in a github action with the
pull_request_target event."""
from ghapi.all import context_github
from ghapi.all import GhApi
from ghapi.all import user_repo
from ghapi.all import github_token
from github import Github
import os
import json
import re

owner, repo = user_repo()
pull_request = context_github.event.pull_request
title = pull_request.title
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"),
Expand All @@ -21,5 +26,4 @@
]

if labels_to_add:
api = GhApi(owner=owner, repo=repo, token=github_token())
api.issues.add_labels(pull_request.number, labels=labels_to_add)
issue.add_to_labels(*labels_to_add)
8 changes: 6 additions & 2 deletions .github/workflows/labeler-title-regex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ on:
pull_request_target:
types: [opened, edited]

permissions:
contents: read
pull-requests: write

jobs:

labeler:
Expand All @@ -12,8 +16,8 @@ jobs:
- uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Install ghapi
run: pip install -Uq ghapi
- name: Install PyGithub
run: pip install -Uq PyGithub
- name: Label pull request
run: python .github/scripts/label_title_regex.py
env:
Expand Down

0 comments on commit e71ae40

Please sign in to comment.