diff --git a/work_item/src/work_item/core.py b/work_item/src/work_item/core.py index 4c755e2..c7a2334 100644 --- a/work_item/src/work_item/core.py +++ b/work_item/src/work_item/core.py @@ -446,19 +446,24 @@ class Gitea: self.tea(*args) def claim(self, story: Story) -> None: - self.tea( - "issues", - "edit", - str(story.number), - "--repo", - self.config.repo_slug, - "--add-assignees", - self.config.assignee, - "--add-labels", - "status/in-progress", - "--remove-labels", - "status/backlog,status/ready,status/blocked,status/review,status/done", + self.edit_labels( + story.number, + add=("status/in-progress",), + remove=( + "status/backlog", + "status/ready", + "status/blocked", + "status/review", + "status/done", + ), ) + self.set_assignee(story.number, self.config.assignee) + + def set_assignee(self, issue: int, assignee: str) -> None: + # Some Gitea/Forgejo deployments 404 on the issues/{n}/assignees + # sub-route that `tea --add-assignees` uses; the issue PATCH endpoint + # accepts the full assignees list and works across those versions. + self.api(f"{self.base}/issues/{issue}", method="PATCH", data={"assignees": [assignee]}) def comment(self, issue: int, body: str) -> None: self.tea("comments", "add", str(issue), body, "--repo", self.config.repo_slug) diff --git a/work_item/tests/test_cli_e2e.py b/work_item/tests/test_cli_e2e.py index 3f4c566..f2892b7 100644 --- a/work_item/tests/test_cli_e2e.py +++ b/work_item/tests/test_cli_e2e.py @@ -50,6 +50,13 @@ if args[0] == "api": out(state["prs"][str(number)]) elif "/commits/" in endpoint and endpoint.endswith("/status"): out({"state": state.get("ci_state", "success")}) + elif "--method" in args and args[args.index("--method") + 1] == "PATCH" and "/issues/" in endpoint: + number = int(endpoint.rsplit("/", 1)[1]) + issue = next(x for x in state["issues"] if x["number"] == number) + payload = json.loads(args[args.index("--data") + 1]) + if "assignees" in payload: + issue["assignees"] = [{"login": login} for login in payload["assignees"]] + save(); out(issue) else: raise SystemExit(f"unsupported api: {endpoint}") elif args[:2] == ["issues", "edit"]: