-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support new folders structure (#434)
openfoodfacts/openfoodfacts-server@2b2d85f added a new structure to taxonomy folders. This is a quick fix to support it
- Loading branch information
Showing
6 changed files
with
37 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
PullRequest, | ||
) | ||
|
||
from . import settings | ||
from . import settings, utils | ||
|
||
|
||
class GithubOperations: | ||
|
@@ -26,6 +26,10 @@ def __init__(self, taxonomy_name: str, branch_name: str): | |
self.taxonomy_name = taxonomy_name | ||
self.branch_name = branch_name | ||
|
||
@property | ||
def taxonomy_path_in_repository(self): | ||
return utils.taxonomy_path_in_repository(self.taxonomy_name) | ||
|
||
@cached_property | ||
def repo_info(self) -> tuple[str, str]: | ||
repo_uri = settings.repo_uri | ||
|
@@ -68,10 +72,9 @@ async def get_file_sha(self) -> str: | |
""" | ||
Get the file SHA from the 'main' branch in the "openfoodfacts-server" repo | ||
""" | ||
github_filepath = f"taxonomies/{self.taxonomy_name}.txt" | ||
file_contents: ContentFile = ( | ||
await self.connection.rest.repos.async_get_content( | ||
*self.repo_info, path=github_filepath | ||
*self.repo_info, path=self.taxonomy_path_in_repository | ||
) | ||
).parsed_data | ||
|
||
|
@@ -90,8 +93,7 @@ async def update_file(self, filename: str, file_sha: str, author_name) -> FileCo | |
Update the taxonomy txt file edited by user using the Taxonomy Editor | ||
""" | ||
# Find taxonomy text file to be updated | ||
github_filepath = f"taxonomies/{self.taxonomy_name}.txt" | ||
commit_message = f"Update {self.taxonomy_name}.txt" | ||
commit_message = f"Update {self.taxonomy_path_in_repository}" | ||
author = {"name": author_name, "email": "[email protected]"} | ||
try: | ||
with open(filename, "r") as f: | ||
|
@@ -103,7 +105,7 @@ async def update_file(self, filename: str, file_sha: str, author_name) -> FileCo | |
return ( | ||
await self.connection.rest.repos.async_create_or_update_file_contents( | ||
*self.repo_info, | ||
path=github_filepath, | ||
path=self.taxonomy_path_in_repository, | ||
message=commit_message, | ||
content=base64.b64encode(new_file_contents.encode("utf-8")), | ||
sha=file_sha, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters