Skip to content

Commit

Permalink
Add: delete_all on labels
Browse files Browse the repository at this point in the history
Unlike the description says within set_all labels are not overriden but
labels that are not within the POST data but are on the PR stay.

For the use case that an action wants to override managed labels it
needs the possibility to delete previous tags. For that the delete_all
method is introduced.
  • Loading branch information
nichtsfrei committed Mar 18, 2024
1 parent 176ad88 commit a8fd1c3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
22 changes: 21 additions & 1 deletion pontos/github/api/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,31 @@ async def get_all(
for label in data:
yield label["name"] # type: ignore

async def delete_all(self, repo: str, issue: Union[int, str]) -> None:
"""
Deletes all labels in the issue/pr.
Args:
repo: GitHub repository (owner/name) to use
issue: Issue/Pull request number
Example:
.. code-block:: python
from pontos.github.api import GitHubAsyncRESTApi
async with GitHubAsyncRESTApi(token) as api:
await api.labels.set_all("foo/bar", 123, ["bug", "doc"])
"""
api = f"/repos/{repo}/issues/{issue}/labels"
response = await self._client.delete(api)
response.raise_for_status()

async def set_all(
self, repo: str, issue: Union[int, str], labels: Iterable[str]
) -> None:
"""
Set labels in the issue/pr. Existing labels will be overwritten
Set labels in the issue/pr.
Args:
repo: GitHub repository (owner/name) to use
Expand Down
10 changes: 10 additions & 0 deletions tests/github/api/test_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ async def test_get_all(self):
params={"per_page": "100"},
)

async def test_delete_all(self):
response = create_response()
self.client.post.return_value = response

await self.api.delete_all("foo/bar", 123)

self.client.delete.assert_awaited_once_with(
"/repos/foo/bar/issues/123/labels"
)

async def test_set_all(self):
response = create_response()
self.client.post.return_value = response
Expand Down

0 comments on commit a8fd1c3

Please sign in to comment.