Skip to content

Commit

Permalink
feat(mkdir): add mkdir bash command and fix github get user
Browse files Browse the repository at this point in the history
  • Loading branch information
Miou-zora committed Jul 9, 2023
1 parent e2b0969 commit 5b079da
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 13 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ tests_run:
@python3 -m coverage run -m pytest
@python3 -m coverage report --precision=4
@python3 -m coverage html -d $(TESTS_HTML_FOLDER)
python3 -m unittest discover -s tests

tclean:
$(RM) .coverage
Expand Down
2 changes: 1 addition & 1 deletion src/Github/Github.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, token: str) -> None:
# TODO: add return value type
def get_user(self, user_name: str | None = None):
from .User import User
if user_name is not None:
if user_name is None:
return User(self.github.get_user())
return User(self.github.get_user(user_name))

Expand Down
11 changes: 11 additions & 0 deletions src/Utils/BashUtils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python3
# @Miou-zora Project, Mirror-Generator, 2023

import subprocess


class BashUtils:
@staticmethod
def mkdir(path: str):
if subprocess.run(["mkdir", path]).returncode == 1:
raise Exception("Folder already exist: " + path)
18 changes: 6 additions & 12 deletions src/generate_mirror_workflow.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# @Miou-zora Project, Mirror-Generator, 2023

import subprocess
from .Utils.BashUtils import BashUtils


def generate_mirror_workflow(project_name: str,
Expand All @@ -14,16 +14,10 @@ def generate_mirror_workflow(project_name: str,
repo_ssh)
mirror_file_data = mirror_file_data.replace("EXECUTABLE_MIRROR_GENERATOR",
project_name)
actions = [(["mkdir", f"{project_name}/{mirror_name}/.github"],
"Folder already exist: "
+ f"{project_name}/{mirror_name}/.github"),
(["mkdir", f"{project_name}/{mirror_name}/.github/workflows"],
"Folder already exist: "
+ f"{project_name}/{mirror_name}/.github/workflows")]
for action in actions:
if subprocess.run(action[0]).returncode == 1:
raise Exception(action[1])
mirror_file = open(f"{project_name}/{mirror_name}/\
.github/workflows/verif_mirror.yml", "w")
mirror_folder = f"{project_name}/{mirror_name}"
BashUtils.mkdir(f"{mirror_folder}/.github")
BashUtils.mkdir(f"{mirror_folder}/.github/workflows")
mirror_file = open(f"{mirror_folder}/.github/workflows/verif_mirror.yml",
"w")
mirror_file.write(mirror_file_data)
mirror_file.close()
Empty file added tests/BashUtils/__init__.py
Empty file.
20 changes: 20 additions & 0 deletions tests/BashUtils/testBashUtils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3
# @Miou-zora Project, Mirror-Generator, 2023

import unittest
from src.Utils.BashUtils import BashUtils
import os


class TestBashUtils(unittest.TestCase):
def __init__(self, methodName: str = "runTest") -> None:
super().__init__(methodName)

def test_mkdir(self):
folder_name = "test_folder"
if os.path.exists(folder_name):
self.fail("Folder already exist: " + folder_name)
BashUtils.mkdir(folder_name)
if not os.path.exists(folder_name):
self.fail("Folder not created: " + folder_name)
os.rmdir(folder_name)
Empty file added tests/__init__.py
Empty file.

0 comments on commit 5b079da

Please sign in to comment.