Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions bedevere/prtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from . import util

NEWS_NEXT_PATH = pathlib.PurePosixPath(util.NEWS_NEXT_DIR)
TYPE_LABEL_PREFIX = "type"


Expand Down Expand Up @@ -37,25 +38,36 @@ async def classify_by_filepaths(gh, pull_request, filenames):

The routing is handled by the filepaths module.
"""
pr_labels = []
issue = await util.issue_for_PR(gh, pull_request)
news = docs = tests = False
news = docs = tests = security = unclassified = False
for filename in filenames:
if util.is_news_dir(filename):
news = True
filepath = pathlib.PurePath(filename)
try:
news_path = filepath.relative_to(NEWS_NEXT_PATH)
except ValueError:
pass # Not news
else:
news = True
if news_path.parts[0] == "Security":
security = True
if filepath.suffix in {".md", ".rst"} or filepath.name == ".nitignore":
docs = True
elif filepath.name.startswith(("test_", "_test")):
tests = True
else:
return pr_labels
if tests:
unclassified = True

if security:
pr_labels = [Labels.type_security]
elif unclassified:
return []
elif tests:
pr_labels = [Labels.tests]
elif docs:
if news:
pr_labels = [Labels.docs]
else:
pr_labels = [Labels.docs, Labels.skip_news]
pr_labels = [Labels.docs]
if not news:
pr_labels.append(Labels.skip_news)
else:
return []
await add_labels(gh, issue, pr_labels)
return pr_labels
39 changes: 39 additions & 0 deletions tests/test_prtype.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import itertools

import pytest

from bedevere import prtype
from bedevere.prtype import Labels

Expand All @@ -23,6 +27,13 @@ async def post(self, url, *, data):


GOOD_BASENAME = "2017-06-16-20-32-50.bpo-1234.nonce.rst"
SSL_FILENAMES = frozenset(
[
"Lib/ssl.py",
"Lib/test/test_ssl.py",
"Doc/library/ssl.rst",
]
)


async def test_no_files():
Expand Down Expand Up @@ -278,3 +289,31 @@ async def test_other_files():
assert gh.getitem_url == "https://api.github.com/repos/cpython/python/issue/1234"
# No labels if a file other than doc or test exists.
assert len(gh.post_url) == 0


@pytest.mark.parametrize(
"filenames",
[
subset
for count in range(len(SSL_FILENAMES) + 1)
for subset in itertools.combinations(SSL_FILENAMES, count)
],
)
async def test_security(filenames):
filenames = {f"Misc/NEWS.d/next/Security/{GOOD_BASENAME}", *filenames}
issue = {"labels": [], "labels_url": "https://api.github.com/some/label"}
gh = FakeGH(getitem=issue)
event_data = {
"action": "opened",
"number": 1234,
"pull_request": {
"url": "https://api.github.com/repos/cpython/python/pulls/1234",
"statuses_url": "https://api.github.com/some/status",
"issue_url": "https://api.github.com/repos/cpython/python/issue/1234",
},
}
await prtype.classify_by_filepaths(gh, event_data["pull_request"], filenames)
assert gh.getitem_url == "https://api.github.com/repos/cpython/python/issue/1234"
assert len(gh.post_url) == 1
assert gh.post_url[0] == "https://api.github.com/some/label"
assert gh.post_data[0] == [Labels.type_security.value]
Loading