Skip to content

Commit

Permalink
feat(Core): add verification if mirroring can be done before execution
Browse files Browse the repository at this point in the history
  • Loading branch information
Miou-zora committed Jul 9, 2023
1 parent 49dddb5 commit d249483
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 21 deletions.
43 changes: 42 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from src.Github.Github import Github as Github
from src.SshKeyRepositoryParser.SshKeyRepositoryParserEpitech import \
SshKeyRepositoryParserEpitech
import os
from github import GithubException

DEFAULT_COMMIT: str = "CI/CD push"

Expand All @@ -27,6 +29,42 @@ class bcolors:
BOLD = '\033[1m'
UNDERLINE = '\033[4m'

def check_all(github: Github,
sshParser: SshKeyRepositoryParserEpitech,
mirror_name: str):
try:
organization = github.get_organization(sshParser.organizationName)
except GithubException as err:
print(f"{bcolors.FAIL}"
"ERROR: Unable to find organization "
f"\"{sshParser.organizationName}\": "
f"{str(err.args[1]['message'])}{bcolors.ENDC}")
if err.args[1]['message'] == "Bad credentials":
print(f"{bcolors.HEADER}"
"You maybe need to change the token in data.json"
f"{bcolors.ENDC}")
exit(84)
try:
repository = organization.get_repo(sshParser.repositoryName)
except Exception as err:
print(f"{bcolors.FAIL}"
"ERROR: Unable to find repository "
f"\"{sshParser.repositoryName}\": "
f"{str(err.args[1]['message'])}{bcolors.ENDC}")
exit(84)
user = github.get_user()
try:
user.get_repo(mirror_name)
print(f"{bcolors.FAIL}"
"ERROR: Unable to create repository: "
f"{mirror_name} already exist{bcolors.ENDC}")
exit(84)
except Exception as err:
pass
if os.path.isdir(sshParser.projectName):
print(f"{bcolors.FAIL}ERROR: Unable to create directory: "
f"{sshParser.projectName} directory already exist{bcolors.ENDC}")
exit(84)

def main():
args = argumentManager()
Expand All @@ -45,7 +83,10 @@ def main():
mirror_name = f"{sshParser.projectName}-mirror"
if args.mirror_name is not None:
mirror_name = args.mirror_name[0]
commit = (args.commit[0] if (args.commit is not None) else DEFAULT_COMMIT)
commit = DEFAULT_COMMIT
if args.commit is not None:
commit = args.commit[0]
check_all(github, sshParser, mirror_name)
generate_mirror(sshParser.organizationName,
sshParser.repositoryName, github, mirror_name)
generate_folders_with_repo(sshParser.sshKey, sshParser.projectName,
Expand Down
Empty file removed tests/BashUtils/__init__.py
Empty file.
20 changes: 0 additions & 20 deletions tests/BashUtils/testBashUtils.py

This file was deleted.

0 comments on commit d249483

Please sign in to comment.