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

Refactor Category to be Labels #486

Merged
merged 5 commits into from
Jul 11, 2022
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
14 changes: 7 additions & 7 deletions bedevere/prtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@


@enum.unique
class Category(enum.Enum):
"""Category of Pull Request."""
class Labels(enum.Enum):
"""Labels that can be applied to a Pull Request."""
ezio-melotti marked this conversation as resolved.
Show resolved Hide resolved

type_bug = f"{TYPE_LABEL_PREFIX}-bug"
documentation = "docs"
docs = "docs"
type_feature = f"{TYPE_LABEL_PREFIX}-feature"
performance = "performance"
type_security = f"{TYPE_LABEL_PREFIX}-security"
tests = "tests"


async def add_category(gh, issue, category):
async def add_label(gh, issue, label):
"""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
await gh.post(issue["labels_url"], data=[category.value])
await gh.post(issue["labels_url"], data=[label.value])


async def classify_by_filepaths(gh, pull_request, filenames):
Expand All @@ -47,7 +47,7 @@ async def classify_by_filepaths(gh, pull_request, filenames):
else:
return
if tests:
await add_category(gh, issue, Category.tests)
await add_label(gh, issue, Labels.tests)
elif docs:
await add_category(gh, issue, Category.documentation)
await add_label(gh, issue, Labels.docs)
return
12 changes: 6 additions & 6 deletions tests/test_filepaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from gidgethub import sansio

from bedevere import news, filepaths
from bedevere import filepaths

from bedevere.prtype import Category
from bedevere.prtype import Labels

from .test_news import check_n_pop_nonews_events

Expand Down 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] == [Category.documentation.value]
assert gh.post_data[0] == [Labels.docs.value]


@pytest.mark.parametrize('author_association', ['OWNER', 'MEMBER', 'CONTRIBUTOR', 'NONE'])
Expand Down Expand Up @@ -117,7 +117,7 @@ async def test_tests_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] == [Category.tests.value]
assert gh.post_data[0] == [Labels.tests.value]


async def test_docs_and_tests():
Expand Down Expand Up @@ -145,7 +145,7 @@ async def test_docs_and_tests():
assert gh.post_url[0] == 'https://api.github.com/some/status'
assert gh.post_data[0]['state'] == 'success'
assert gh.post_url[1] == 'https://api.github.com/some/label'
assert gh.post_data[1] == [Category.tests.value]
assert gh.post_data[1] == [Labels.tests.value]


async def test_news_and_tests():
Expand Down Expand Up @@ -174,7 +174,7 @@ async def test_news_and_tests():
assert gh.post_url[0] == 'https://api.github.com/some/status'
assert gh.post_data[0]['state'] == 'success'
assert gh.post_url[1] == 'https://api.github.com/some/label'
assert gh.post_data[1] == [Category.tests.value]
assert gh.post_data[1] == [Labels.tests.value]


async def test_synchronize():
Expand Down
14 changes: 7 additions & 7 deletions tests/test_prtype.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from bedevere import prtype
from bedevere.prtype import Category
from bedevere.prtype import Labels


class FakeGH:
Expand Down Expand Up @@ -62,7 +62,7 @@ async def test_news_only():
}
await prtype.classify_by_filepaths(gh, event_data['pull_request'], filenames)
assert gh.getitem_url == 'https://api.github.com/repos/cpython/python/issue/1234'
# News only .rst does not add a type-documentation label.
# News only .rst does not add a docs label.
assert len(gh.post_url) == 0
assert len(gh.post_data) == 0

Expand All @@ -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] == [Category.documentation.value]
assert gh.post_data[0] == [Labels.docs.value]


async def test_docs_and_news():
Expand All @@ -106,7 +106,7 @@ async def test_docs_and_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] == [Category.documentation.value]
assert gh.post_data[0] == [Labels.docs.value]


async def test_tests_only():
Expand All @@ -127,7 +127,7 @@ async def test_tests_only():
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] == [Category.tests.value]
assert gh.post_data[0] == [Labels.tests.value]


async def test_docs_and_tests():
Expand All @@ -149,7 +149,7 @@ async def test_docs_and_tests():
# Only creates type-tests label.
assert len(gh.post_url) == 1
assert gh.post_url[0] == 'https://api.github.com/some/label'
assert gh.post_data[0] == [Category.tests.value]
assert gh.post_data[0] == [Labels.tests.value]


async def test_leave_existing_type_labels():
Expand Down Expand Up @@ -191,7 +191,7 @@ async def test_news_and_tests():
# Creates type-tests label.
assert len(gh.post_url) == 1
assert gh.post_url[0] == 'https://api.github.com/some/label'
assert gh.post_data[0] == [Category.tests.value]
assert gh.post_data[0] == [Labels.tests.value]


async def test_other_files():
Expand Down