Skip to content

Commit

Permalink
fix: code refactored to add new ecosystem (#357)
Browse files Browse the repository at this point in the history
* fix: code refactored to add new ecosystem
  • Loading branch information
zubairshakoorarbisoft authored Apr 6, 2023
1 parent d3037ae commit bceb9fc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion edx_repo_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

__version__ = '0.7.1'
__version__ = '0.7.2'
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import os
import click

from edx_repo_tools.utils import YamlLoader


github_actions = """\
# Adding new check for github-actions
package-ecosystem": github-actions
directory: /
package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: weekly
interval: "weekly"
"""

# Adding new packages for update. Add tuple with key and related data.
ADD_NEW_FIELDS = [("github-actions", github_actions,)]


class YamlModernizer(YamlLoader):
class DependabotYamlModernizer(YamlLoader):
"""
Yaml Modernizer class is responsible for adding new elements in yml.
Dependabot Yaml Modernizer class is responsible for adding new elements in dependabot.yml.
"""

def __init__(self, file_path):
super().__init__(file_path)

def _add_elements(self):
updates = self.elements.get('updates')

self.elements['updates'] = self.elements.get('updates') or []
found = False
for key, value in ADD_NEW_FIELDS:
for index in updates:
if key in index['package-ecosystem']:
for index in self.elements['updates']:
if key == index.get('package-ecosystem'):
found = True
break

Expand All @@ -46,10 +46,17 @@ def modernize(self):

@click.command()
@click.option(
'--path', default='dependantbot.yaml',
help="Path to target dependantbot.yaml file")
'--path', default='.github/dependabot.yml',
help="Path to target dependabot.yml file")
def main(path):
modernizer = YamlModernizer(path)
if not os.path.exists(path):
new_file_content = """\
version: 2
updates:
"""
with open(path, 'w') as file:
file.write(new_file_content)
modernizer = DependabotYamlModernizer(path)
modernizer.modernize()


Expand Down
1 change: 1 addition & 0 deletions edx_repo_tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class YamlLoader:
def __init__(self, file_path):
self.file_path = file_path
self.yml_instance = YAML()
self.yml_instance.preserve_quotes = True
self.yml_instance.default_flow_style = None
self.yml_instance.indent(mapping=2, sequence=2, offset=0)
self._load_file()
Expand Down

0 comments on commit bceb9fc

Please sign in to comment.