Skip to content

Commit

Permalink
Merge pull request #675 from NASA-IMPACT/674-fix-plugin-generation-bug
Browse files Browse the repository at this point in the history
674 fix plugin generation bug
  • Loading branch information
CarsonDavis authored Apr 19, 2024
2 parents 2d3ad10 + ce35cb5 commit 6c04d9c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
2 changes: 0 additions & 2 deletions config_generation/db_to_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,9 @@ def convert_template_to_plugin_indexer(self, scraper_editor) -> None:
]

for field in transfer_fields:
print(field, scraper_editor.get_tag_value(field, strict=True))
self.update_or_add_element_value(field, scraper_editor.get_tag_value(field, strict=True))

for parent, child in double_transfer_fields:
print(parent, child, scraper_editor.get_tag_value(f"{parent}/{child}", strict=True))
self.update_or_add_element_value(
f"{parent}/{child}", scraper_editor.get_tag_value(f"{parent}/{child}", strict=True)
)
Expand Down
2 changes: 1 addition & 1 deletion sde_collections/models/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def _process_document_type_list(self):
def _write_to_github(self, path, content, overwrite):
gh = GitHubHandler()
if overwrite:
gh.update_file(path, content)
gh.create_or_update_file(path, content)
else:
gh.create_file(path, content)

Expand Down
35 changes: 14 additions & 21 deletions sde_collections/utils/github_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def create_file(self, file_path, file_string, branch=None):
branch=branch,
)

def update_file(self, file_path, file_string, branch=None):
def create_or_update_file(self, file_path, file_string, branch=None):
"""
Update file contents on GitHub
if no branch is provided, it will default to the webapp_pr_branch
Expand All @@ -81,16 +81,19 @@ def update_file(self, file_path, file_string, branch=None):
if not branch:
branch = self.webapp_pr_branch

contents = self._get_file_contents(file_path)
COMMIT_MESSAGE = f"Webapp: Update {file_path}"

self.repo.update_file(
contents.path,
COMMIT_MESSAGE,
file_string,
contents.sha,
branch=branch,
)
if self.check_file_exists(file_path):
contents = self._get_file_contents(file_path)
COMMIT_MESSAGE = f"Webapp: Update {file_path}"

self.repo.update_file(
contents.path,
COMMIT_MESSAGE,
file_string,
contents.sha,
branch=branch,
)
else:
self.create_file(file_path, file_string, branch)

def update_config_with_current_rules(self, collection):
"""
Expand All @@ -112,16 +115,6 @@ def update_config_with_current_rules(self, collection):
branch=self.github_branch,
)

def create_or_update_file(self, file_path, file_string):
"""
Create or update file contents on GitHub
"""

if self.check_file_exists(file_path):
self.update_file_contents(file_path, file_string)
else:
self.create_file(file_path, file_string)

def branch_exists(self, branch_name: str) -> bool:
try:
self.repo.get_branch(branch=branch_name)
Expand Down

0 comments on commit 6c04d9c

Please sign in to comment.