Skip to content

Commit

Permalink
Fix cannot create pr on foreign repo (#1183)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wauplin authored Nov 10, 2022
1 parent 0d36cbd commit fa05ff5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/huggingface_hub/_commit_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ def fetch_upload_modes(
token: Optional[str],
revision: str,
endpoint: Optional[str] = None,
create_pr: bool = False,
) -> Dict[str, UploadMode]:
"""
Requests the Hub "preupload" endpoint to determine wether each input file
Expand Down Expand Up @@ -450,6 +451,7 @@ def fetch_upload_modes(
f"{endpoint}/api/{repo_type}s/{repo_id}/preupload/{revision}",
json=payload,
headers=headers,
params={"create_pr": "1"} if create_pr else None,
)
hf_raise_for_status(resp)
preupload_info = _validate_preupload_info(resp.json())
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1887,6 +1887,7 @@ def create_commit(
token=token or self.token,
revision=revision,
endpoint=self.endpoint,
create_pr=create_pr,
)
except RepositoryNotFoundError as e:
e.append_to_message(_CREATE_COMMIT_NO_REPO_ERROR_MESSAGE)
Expand Down
18 changes: 18 additions & 0 deletions tests/test_hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,24 @@ def test_create_commit_create_pr_against_branch(self):
# Cleanup
self._api.delete_repo(repo_id=repo_id)

@retry_endpoint
def test_create_commit_create_pr_on_foreign_repo(self):
# Repo on which we don't have right
# We must be able to create a PR on it
self._api.create_commit(
operations=[
CommitOperationAdd(
path_in_repo="regular.txt", path_or_fileobj=b"File content"
),
CommitOperationAdd(
path_in_repo="lfs.pkl", path_or_fileobj=b"File content"
),
],
commit_message="PR on foreign repo",
repo_id="datasets_server_org/repo_for_huggingface_hub_ci_with_prs",
create_pr=True,
)

@retry_endpoint
def test_create_commit(self):
for private in (False, True):
Expand Down

0 comments on commit fa05ff5

Please sign in to comment.