Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto add the skip news label to docs PRs #485

Merged
merged 13 commits into from
Jul 13, 2022
17 changes: 11 additions & 6 deletions bedevere/prtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ class Labels(enum.Enum):
performance = "performance"
type_security = f"{TYPE_LABEL_PREFIX}-security"
tests = "tests"
skip_news = "skip news"
ezio-melotti marked this conversation as resolved.
Show resolved Hide resolved


async def add_label(gh, issue, label):
async def add_label(gh, issue, labels):
DanielNoord marked this conversation as resolved.
Show resolved Hide resolved
"""Apply this type label if there aren't any type labels on the PR."""
if any(label.startswith("type") for label in util.labels(issue)):
return
DanielNoord marked this conversation as resolved.
Show resolved Hide resolved
await gh.post(issue["labels_url"], data=[label.value])
label_names = [c.value for c in labels]
await gh.post(issue["labels_url"], data=label_names)
DanielNoord marked this conversation as resolved.
Show resolved Hide resolved


async def classify_by_filepaths(gh, pull_request, filenames):
Expand All @@ -35,10 +37,10 @@ async def classify_by_filepaths(gh, pull_request, filenames):
The routing is handled by the filepaths module.
"""
issue = await util.issue_for_PR(gh, pull_request)
docs = tests = False
news = docs = tests = False
for filename in filenames:
if util.is_news_dir(filename):
continue
news = True
filepath = pathlib.PurePath(filename)
if filepath.suffix == '.rst':
docs = True
Expand All @@ -47,7 +49,10 @@ async def classify_by_filepaths(gh, pull_request, filenames):
else:
return
if tests:
await add_label(gh, issue, Labels.tests)
await add_label(gh, issue, [Labels.tests])
DanielNoord marked this conversation as resolved.
Show resolved Hide resolved
elif docs:
await add_label(gh, issue, Labels.docs)
if news:
await add_label(gh, issue, [Labels.docs])
else:
await add_label(gh, issue, [Labels.docs, Labels.skip_news])
DanielNoord marked this conversation as resolved.
Show resolved Hide resolved
return
2 changes: 1 addition & 1 deletion tests/test_filepaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async def test_docs_only(author_association):
check_n_pop_nonews_events(gh, author_association == 'NONE')
assert len(gh.post_url) == 1
assert gh.post_url[0] == 'https://api.github.com/some/label'
assert gh.post_data[0] == [Labels.docs.value]
assert gh.post_data[0] == [Labels.docs.value, Labels.skip_news.value]


@pytest.mark.parametrize('author_association', ['OWNER', 'MEMBER', 'CONTRIBUTOR', 'NONE'])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_prtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async def test_docs_no_news():
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.docs.value]
assert gh.post_data[0] == [Labels.docs.value, Labels.skip_news.value]


async def test_docs_and_news():
Expand Down