Skip to content

Commit

Permalink
Refactor Category to be Labels (#486)
Browse files Browse the repository at this point in the history
* Remove unused import

* Refactor ``Category`` to be ``Labels``

* Rename from ``documentation`` to ``docs``

* Rename label

* Update comment
  • Loading branch information
DanielNoord authored Jul 11, 2022
1 parent 6aebdb4 commit 83a2d22
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
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."""

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

0 comments on commit 83a2d22

Please sign in to comment.