Skip to content

Commit

Permalink
Merge pull request #3 from alalkamys/fix/modes-flags-resets
Browse files Browse the repository at this point in the history
Fix: Modes Flags Resets Enforcement
  • Loading branch information
alalkamys authored Mar 21, 2024
2 parents 2356ccf + 9132000 commit 498f6c3
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 18 deletions.
26 changes: 26 additions & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class AppConfig:
Attributes:
APP_NAME (str): The name of the application. Defaults to "code_migration_assistant".
APP_MODES (dict): Available modes for the application and their corresponding flags configuration.
The flags configuration is a nested dictionary with boolean values indicating whether each flag is enabled or not.
Keys are mode names ('dev', 'prod', etc.), and values are dictionaries with flag names as keys and boolean values as values.
LOG_LEVEL (str): The logging level for the application. Defaults to "INFO".
TARGETS_CONFIG_FILE (str): The file path to the targets configuration file. Defaults to "./config.json".
REMOTE_TARGETS_CLONING_PATH (str): The path where remote targets are cloned. Defaults to "./remote-targets".
Expand All @@ -25,6 +28,29 @@ class AppConfig:
APP_NAME = os.getenv('CODE_MIGRATION_ASSISTANT_APP_NAME',
"code_migration_assistant")

APP_MODES: dict[str, dict[str, dict[str, bool]]] = {
'dev': {
'flags': {
'check_branch': False,
'setup_identity': False,
'search_only': True,
'commit': False,
'push': False,
'create_pull_request': False
}
},
'prod': {
'flags': {
'check_branch': True,
'setup_identity': True,
'search_only': False,
'commit': True,
'push': True,
'create_pull_request': True
}
}
}

LOG_LEVEL = os.getenv('CODE_MIGRATION_ASSISTANT_LOG_LEVEL', "INFO")

TARGETS_CONFIG_FILE = os.getenv(
Expand Down
49 changes: 31 additions & 18 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
from app.helpers.scm_providers_operations import is_open_pull_requests
from app.helpers.scm_providers_operations import raise_pull_request

from tabulate import tabulate
from copy import deepcopy
from tabulate import tabulate
from typing import Literal
import logging.config
import os
import sys
Expand All @@ -30,23 +31,10 @@
REPLACEMENTS = TARGETS_CONFIG['replacements']
FILES_TO_EXCLUDE = TARGETS_CONFIG.get('filesToExclude', [])

MODE: str = TARGETS_CONFIG.get('mode', 'prod').strip().lower()

if MODE == 'dev':
check_branch = False
setup_identity = False
search_only = True
commit = False
push = False
create_pull_request = False
elif MODE == 'prod':
check_branch = True
setup_identity = True
search_only = False
commit = True
push = True
create_pull_request = True
else:
MODE: Literal['dev', 'prod'] = TARGETS_CONFIG.get(
'mode', 'prod').strip().lower()

if MODE not in app_config.APP_MODES:
_logger.error(f"Invalid mode: '{
MODE}'. The mode must be set to either 'dev' for development/testing or 'prod' for production usage.")
_logger.info("Exiting..")
Expand All @@ -65,6 +53,22 @@

_logger.info(f"Migrating '{repo_name}'..")

check_branch = app_config.APP_MODES[MODE]['flags']['check_branch']
setup_identity = app_config.APP_MODES[MODE]['flags']['setup_identity']
search_only = app_config.APP_MODES[MODE]['flags']['search_only']
commit = app_config.APP_MODES[MODE]['flags']['commit']
push = app_config.APP_MODES[MODE]['flags']['push']
create_pull_request = app_config.APP_MODES[MODE]['flags']['create_pull_request']

_logger.debug("Initial Flags")
_logger.debug("-------------")
_logger.debug(f"check_branch: {check_branch}")
_logger.debug(f"setup_identity: {setup_identity}")
_logger.debug(f"search_only: {search_only}")
_logger.debug(f"commit: {commit}")
_logger.debug(f"push: {push}")
_logger.debug(f"create_pull_request: {create_pull_request}")

if setup_identity:
identity_configured = identity_setup(
repo=repo, actor_username=app_config.ACTOR['username'], actor_email=app_config.ACTOR['email'])
Expand Down Expand Up @@ -190,6 +194,15 @@
"Skipping to the next migration..")
continue

_logger.debug("Flags After Checks")
_logger.debug("------------------")
_logger.debug(f"check_branch: {check_branch}")
_logger.debug(f"setup_identity: {setup_identity}")
_logger.debug(f"search_only: {search_only}")
_logger.debug(f"commit: {commit}")
_logger.debug(f"push: {push}")
_logger.debug(f"create_pull_request: {create_pull_request}")

if commit:
COMMIT_MESSAGE = TARGETS_CONFIG.get('commitMessage', None)
COMMIT_TITLE = COMMIT_MESSAGE.get(
Expand Down

0 comments on commit 498f6c3

Please sign in to comment.