Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix discussion URL on datasets and spaces #1465

Merged
merged 2 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/huggingface_hub/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def url(self) -> str:
"""Returns the URL of the discussion on the Hub."""
if self.repo_type is None or self.repo_type == REPO_TYPE_MODEL:
return f"{self.endpoint}/{self.repo_id}/discussions/{self.num}"
return f"{self.endpoint}/{self.repo_type}/{self.repo_id}/discussions/{self.num}"
return f"{self.endpoint}/{self.repo_type}s/{self.repo_id}/discussions/{self.num}"


@dataclass
Expand Down
10 changes: 10 additions & 0 deletions tests/test_hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2187,6 +2187,16 @@ def test_create_discussion(self):
self.assertEqual(discussion.is_pull_request, False)
self.assertEqual(discussion.title, "Test discussion !")

@use_tmp_repo("dataset")
def test_create_discussion_space(self, repo_url: RepoUrl):
"""Regression test for #1463.

Computed URL was malformed with `dataset` and `space` repo_types.
See https://github.com/huggingface/huggingface_hub/issues/1463.
"""
discussion = self._api.create_discussion(repo_id=repo_url.repo_id, repo_type="dataset", title="title")
self.assertEqual(discussion.url, f"{repo_url}/discussions/1")

def test_create_pull_request(self):
discussion = self._api.create_discussion(repo_id=self.repo_id, title=" Test PR ! ", pull_request=True)
self.assertEqual(discussion.num, 3)
Expand Down