diff --git a/gitea/apiobject.py b/gitea/apiobject.py index 3e533ec..fdf26ec 100644 --- a/gitea/apiobject.py +++ b/gitea/apiobject.py @@ -343,7 +343,7 @@ class Repository(ApiObject): REPO_ISSUES = """/repos/{owner}/{repo}/issues""" # REPO_DELETE = """/repos/%s/%s""" # , REPO_TIMES = """/repos/%s/%s/times""" # , - REPO_TOPICS = """/repos/%s/%s/topics""" # + REPO_TOPICS = """/repos/%s/%s/topics""" # REPO_TOPIC = """/repos/%s/%s/topics/%s""" # , REPO_USER_TIME = """/repos/%s/%s/times/%s""" # , , REPO_COMMITS = "/repos/%s/%s/commits" # , @@ -433,7 +433,7 @@ class Repository(ApiObject): try: results = self.gitea.requests_get_paginated( Repository.REPO_COMMITS % (self.owner.username, self.name), - page_limit= page_limit + page_limit=page_limit, ) except ConflictException as err: logging.warning(err) @@ -465,19 +465,25 @@ class Repository(ApiObject): Repository.REPO_TIMES % (self.owner.username, self.name) ) return results - - def get_topics(self): + + def get_topics(self) -> list[str]: results = self.gitea.requests_get( Repository.REPO_TOPICS % (self.owner.username, self.name) ) return results["topics"] - + def add_topic(self, topic: str): """Add a topic to the repository""" - result = self.gitea.requests_put( + self.gitea.requests_put( Repository.REPO_TOPIC % (self.owner.username, self.name, topic) ) - + + def del_topic(self, topic: str): + """Add a topic to the repository""" + self.gitea.requests_delete( + Repository.REPO_TOPIC % (self.owner.username, self.name, topic) + ) + def get_user_time(self, username) -> float: if isinstance(username, User): username = username.username diff --git a/tests/test_api.py b/tests/test_api.py index 2fa87bd..d2ae8cc 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -348,6 +348,19 @@ def test_team_get_org(instance): assert org.username == teams[0].organization.name +def test_topic_functions(instance): + user = User.request(instance, test_user) + repo = Repository.request(instance, user.username, test_repo) + repo.add_topic("rings") + repo.add_topic("swords") + repo.add_topic("dragons") + assert "swords" in repo.get_topics() + repo.del_topic("swords") + assert "swords" not in repo.get_topics() + assert "dragons" in repo.get_topics() + assert "rings" in repo.get_topics() + + def test_delete_repo_userowned(instance): user = User.request(instance, test_user) repo = Repository.request(instance, user.username, test_repo)