From adb5d57b6b4927b1c61c4e63dccd8f9366b601be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Thu, 7 Jul 2022 20:33:41 +0200 Subject: [PATCH 1/5] Remove unused import --- tests/test_filepaths.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_filepaths.py b/tests/test_filepaths.py index c77c8f28..485b1bf3 100644 --- a/tests/test_filepaths.py +++ b/tests/test_filepaths.py @@ -2,7 +2,7 @@ from gidgethub import sansio -from bedevere import news, filepaths +from bedevere import filepaths from bedevere.prtype import Category From c1cc5891492b0cb2417312c6a7fa8f0226a0b1af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Thu, 7 Jul 2022 20:33:52 +0200 Subject: [PATCH 2/5] Refactor ``Category`` to be ``Labels`` --- bedevere/prtype.py | 10 +++++----- tests/test_filepaths.py | 10 +++++----- tests/test_prtype.py | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/bedevere/prtype.py b/bedevere/prtype.py index 893e0960..c6acf784 100644 --- a/bedevere/prtype.py +++ b/bedevere/prtype.py @@ -8,8 +8,8 @@ @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" @@ -19,7 +19,7 @@ class Category(enum.Enum): tests = "tests" -async def add_category(gh, issue, category): +async def add_label(gh, issue, category): """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 @@ -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.documentation) return diff --git a/tests/test_filepaths.py b/tests/test_filepaths.py index 485b1bf3..17e31d58 100644 --- a/tests/test_filepaths.py +++ b/tests/test_filepaths.py @@ -4,7 +4,7 @@ from bedevere import filepaths -from bedevere.prtype import Category +from bedevere.prtype import Labels from .test_news import check_n_pop_nonews_events @@ -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.documentation.value] @pytest.mark.parametrize('author_association', ['OWNER', 'MEMBER', 'CONTRIBUTOR', 'NONE']) @@ -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(): @@ -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(): @@ -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(): diff --git a/tests/test_prtype.py b/tests/test_prtype.py index 3e274e81..d4d778bc 100644 --- a/tests/test_prtype.py +++ b/tests/test_prtype.py @@ -1,5 +1,5 @@ from bedevere import prtype -from bedevere.prtype import Category +from bedevere.prtype import Labels class FakeGH: @@ -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.documentation.value] async def test_docs_and_news(): @@ -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.documentation.value] async def test_tests_only(): @@ -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(): @@ -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(): @@ -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(): From 48063eea822f259feeb84cce7a8f667261adaf81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Fri, 8 Jul 2022 01:06:58 +0200 Subject: [PATCH 3/5] Rename from ``documentation`` to ``docs`` --- bedevere/prtype.py | 4 ++-- tests/test_filepaths.py | 2 +- tests/test_prtype.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bedevere/prtype.py b/bedevere/prtype.py index c6acf784..0b97f346 100644 --- a/bedevere/prtype.py +++ b/bedevere/prtype.py @@ -12,7 +12,7 @@ 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" @@ -49,5 +49,5 @@ async def classify_by_filepaths(gh, pull_request, filenames): if tests: await add_label(gh, issue, Labels.tests) elif docs: - await add_label(gh, issue, Labels.documentation) + await add_label(gh, issue, Labels.docs) return diff --git a/tests/test_filepaths.py b/tests/test_filepaths.py index 17e31d58..1fbd3380 100644 --- a/tests/test_filepaths.py +++ b/tests/test_filepaths.py @@ -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.documentation.value] + assert gh.post_data[0] == [Labels.docs.value] @pytest.mark.parametrize('author_association', ['OWNER', 'MEMBER', 'CONTRIBUTOR', 'NONE']) diff --git a/tests/test_prtype.py b/tests/test_prtype.py index d4d778bc..d51bcdea 100644 --- a/tests/test_prtype.py +++ b/tests/test_prtype.py @@ -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 type-docs label. assert len(gh.post_url) == 0 assert len(gh.post_data) == 0 @@ -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.documentation.value] + assert gh.post_data[0] == [Labels.docs.value] async def test_docs_and_news(): @@ -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] == [Labels.documentation.value] + assert gh.post_data[0] == [Labels.docs.value] async def test_tests_only(): From 8109b9a66dbf5f789941783644a2bd699aa525af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Fri, 8 Jul 2022 01:07:23 +0200 Subject: [PATCH 4/5] Rename label --- bedevere/prtype.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bedevere/prtype.py b/bedevere/prtype.py index 0b97f346..8f1f333d 100644 --- a/bedevere/prtype.py +++ b/bedevere/prtype.py @@ -19,11 +19,11 @@ class Labels(enum.Enum): tests = "tests" -async def add_label(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): From 4ea7afb63a7fd6b5b35fcd646e9a3ba6e9a5e546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Fri, 8 Jul 2022 01:19:55 +0200 Subject: [PATCH 5/5] Update comment --- tests/test_prtype.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_prtype.py b/tests/test_prtype.py index d51bcdea..541a1d68 100644 --- a/tests/test_prtype.py +++ b/tests/test_prtype.py @@ -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-docs label. + # News only .rst does not add a docs label. assert len(gh.post_url) == 0 assert len(gh.post_data) == 0