Skip to content

Commit 83a2d22

Browse files
authored
Refactor Category to be Labels (#486)
* Remove unused import * Refactor ``Category`` to be ``Labels`` * Rename from ``documentation`` to ``docs`` * Rename label * Update comment
1 parent 6aebdb4 commit 83a2d22

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

bedevere/prtype.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88

99

1010
@enum.unique
11-
class Category(enum.Enum):
12-
"""Category of Pull Request."""
11+
class Labels(enum.Enum):
12+
"""Labels that can be applied to a Pull Request."""
1313

1414
type_bug = f"{TYPE_LABEL_PREFIX}-bug"
15-
documentation = "docs"
15+
docs = "docs"
1616
type_feature = f"{TYPE_LABEL_PREFIX}-feature"
1717
performance = "performance"
1818
type_security = f"{TYPE_LABEL_PREFIX}-security"
1919
tests = "tests"
2020

2121

22-
async def add_category(gh, issue, category):
22+
async def add_label(gh, issue, label):
2323
"""Apply this type label if there aren't any type labels on the PR."""
2424
if any(label.startswith("type") for label in util.labels(issue)):
2525
return
26-
await gh.post(issue["labels_url"], data=[category.value])
26+
await gh.post(issue["labels_url"], data=[label.value])
2727

2828

2929
async def classify_by_filepaths(gh, pull_request, filenames):
@@ -47,7 +47,7 @@ async def classify_by_filepaths(gh, pull_request, filenames):
4747
else:
4848
return
4949
if tests:
50-
await add_category(gh, issue, Category.tests)
50+
await add_label(gh, issue, Labels.tests)
5151
elif docs:
52-
await add_category(gh, issue, Category.documentation)
52+
await add_label(gh, issue, Labels.docs)
5353
return

tests/test_filepaths.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from gidgethub import sansio
44

5-
from bedevere import news, filepaths
5+
from bedevere import filepaths
66

7-
from bedevere.prtype import Category
7+
from bedevere.prtype import Labels
88

99
from .test_news import check_n_pop_nonews_events
1010

@@ -88,7 +88,7 @@ async def test_docs_only(author_association):
8888
check_n_pop_nonews_events(gh, author_association == 'NONE')
8989
assert len(gh.post_url) == 1
9090
assert gh.post_url[0] == 'https://api.github.com/some/label'
91-
assert gh.post_data[0] == [Category.documentation.value]
91+
assert gh.post_data[0] == [Labels.docs.value]
9292

9393

9494
@pytest.mark.parametrize('author_association', ['OWNER', 'MEMBER', 'CONTRIBUTOR', 'NONE'])
@@ -117,7 +117,7 @@ async def test_tests_only(author_association):
117117
check_n_pop_nonews_events(gh, author_association == 'NONE')
118118
assert len(gh.post_url) == 1
119119
assert gh.post_url[0] == 'https://api.github.com/some/label'
120-
assert gh.post_data[0] == [Category.tests.value]
120+
assert gh.post_data[0] == [Labels.tests.value]
121121

122122

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

150150

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

179179

180180
async def test_synchronize():

tests/test_prtype.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from bedevere import prtype
2-
from bedevere.prtype import Category
2+
from bedevere.prtype import Labels
33

44

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

@@ -85,7 +85,7 @@ async def test_docs_no_news():
8585
assert gh.getitem_url == 'https://api.github.com/repos/cpython/python/issue/1234'
8686
assert len(gh.post_url) == 1
8787
assert gh.post_url[0] == 'https://api.github.com/some/label'
88-
assert gh.post_data[0] == [Category.documentation.value]
88+
assert gh.post_data[0] == [Labels.docs.value]
8989

9090

9191
async def test_docs_and_news():
@@ -106,7 +106,7 @@ async def test_docs_and_news():
106106
assert gh.getitem_url == 'https://api.github.com/repos/cpython/python/issue/1234'
107107
assert len(gh.post_url) == 1
108108
assert gh.post_url[0] == 'https://api.github.com/some/label'
109-
assert gh.post_data[0] == [Category.documentation.value]
109+
assert gh.post_data[0] == [Labels.docs.value]
110110

111111

112112
async def test_tests_only():
@@ -127,7 +127,7 @@ async def test_tests_only():
127127
assert gh.getitem_url == 'https://api.github.com/repos/cpython/python/issue/1234'
128128
assert len(gh.post_url) == 1
129129
assert gh.post_url[0] == 'https://api.github.com/some/label'
130-
assert gh.post_data[0] == [Category.tests.value]
130+
assert gh.post_data[0] == [Labels.tests.value]
131131

132132

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

154154

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

196196

197197
async def test_other_files():

0 commit comments

Comments
 (0)