mirror of
https://github.com/Dictionarry-Hub/profilarr.git
synced 2026-01-22 19:01:02 +01:00
* feat: initialise task scheduler * feat: add "next run" field to task status * fix: adjust status route path * feat: task dashboard + api functions * fix: return sucess object for alert * refactor: turn task cards into seperate objects * fix: change task names * feat: implement compile and import module - only working for custom formats for now * refactor/feature: refactor compilation module - seperate file for mappings - seperate format compiler into new file - add compiler for profiles * feat: add import logic for quality profiles * fix: properly resolve cutoff IDs for singular qualities * fix: remux mappings for sonarr * fix: retain quality group order - stop groups first, then singular * fix: dynamically find next group ID to stop duplicate IDs from occuring * fix: normalise quality letter case * feat: add api functions for import functionality * fix: adjust validation for import.js * feat: add mass selection tool componnet - keyboard shortcuts to enter state - mass delete / import * feat: add loading indicator on import * style: improve selected card styling * fix: append extra custom formats with 0 score * perf: add git status caching to improve load times * fix: adjust mass import handling and selection logic - use content.name rather than content.id * fix: enhance quality name mapping with alternate names and case-insensitive lookups * feat: add description truncation to ProfileCard for improved readability - also remove qualitites * fix: update upgrade quality selection logic to handle disabling scenarios * feat: expand language mappings with additional languages and identifiers * feat: enhance profile conversion logging with language handling * fix: clarify language setting impact in ProfileLanguagesTab component * feat: add Sonarr language mappings and update language selection logic * feat: implement language normalization and enhance logging in format conversion * feat: enhance logging in format conversion and add language specification handling * feat: add Afrikaans and Albanian languages to the language constants * refactor: remove language strictness feature and update language handling in ProfileModal * feat: add logging setup for improved debugging in mappings module * feat: enhance language compilation to work with new system * feat: update language handling in ProfileLanguagesTab to support 'any' behavior * fix: remove redundant import statement in profile.py * feat: implement in-memory format import functionality and update profile compiler to utilize it for non english language compilation * feat: add comparison for tweaks in quality profile changes * feat: add functions to convert display names to filenames and vice versa * fix: remove unnecessary filename modification in formats data * feat: add process_tweaks function to handle profile tweaks and import formats before compilation * feat: refactor process_tweaks to modularize format import and scoring - include lossless audio tweak handling * feat: add support for Dolby Vision no fallback and bleeding edge codecs in process_tweaks * feat: add support for disabling prereleases based on profile tweaks * fix: reduce cache TTL from 30 seconds to 1 second for quicker updates * feat: add resetState function to initialize profile modal state * feat: enhance save_yaml_file function to optionally use data name for filename * feat: enhance handle_rename function to account for staged renames * feat: enhance revert functionality to handle untracked files and staged deletions * chore: update timezone setting in docker-compose.yml * feat: increase maximum description length in ProfileCard component * refactor: generic YAML comparison and change summary functionality * refactor: incoming changes now uses generic comparison logic * refactor: add YAML conflict comparison functionality with detailed summary generation for merge conflicts * refactor: heavily simplified resolve conflict modal to work with new generic conflict parsing * refactor: implement GitStatusManager for improved repository status handling and sync task updates * refactor: integrate GitStatusManager to update remote status after pull operations * refactor: remove isDevMode prop from ChangeRow, ConflictRow, ConflictTable, ChangeTable, RepoContainer, and ActionButtons components * refactor: migrate settings handling from settings_utils to db module and enhance settings management * refactor: remove deprecated authentication methods and streamline push operations with SSH access * refactor: enhance error handling and authentication for Git operations, including PAT support * refactor: remove old settings_utils * refactor: add settings prop to StatusContainer and update database initialization for profilarr_pat * refactor: simplify format name handling in ViewChanges component by removing old API call * fix: update fetchSettings to handle cases with no git repository and ensure settings is null * fix: enhance get_git_status to return a valid status object when no git repository is found * style: various improvements to repo container - add database stats - add organisation / profile avatar - parse organisation / repo name - improvements to branch button * feat: implement authentication setup and middleware for secure session management * fix: auto login after setting up authentication * feat: enhance authentication setup with GET method and track failed attempts * feat: add authentication setup and login components with API integration * feat: redesign SetupPage component with improved layout and user guidance * feat: enhance LoginPage layout with improved design and user guidance * refactor: remove unused API functions for regex and format management * improvements: whole lot more stuff (#17) * feat: implement configuration management for directory paths and session settings * feat: implement backup management with API endpoints for backup operations * feat: add backup import functionality with zip file validation and restoration * feat: implement backup API with endpoints for listing, creating, downloading, restoring, deleting, and importing backups * feat: enhance backup listing with file size and last modified time * feat: add backup management interface with listing, creation, restoration, and deletion functionalities * fix: refresh backups list after successful deletion * feat: create BackupCard component for displaying backup details and actions * fix: status parsing improvements - now properly shows outgoing changes with / without developer mode * fix: remove authentication bypass for backup routes during testing * feat: add logging configuration and ensure log directory creation * feat: implement application-wide logging configuration and ensure log directory creation * feat: add logging blueprint with endpoints for retrieving and searching log files * feat: add git logging configuration to enhance logging capabilities * refactor: enhance logging details and improve error handling in repository cloning and file processing * refactor: update tab labels for clarity in settings page * refactor: remove unused tasks and streamline task scheduler * refactor: improve repository settings handling and UI updates in RepoContainer * style: add slight gradient to modal * feat: enhance footer with GitHub repository info and organization avatar * refactor: update imports and enhance modal layout for linking Git repository * refactor: remove documentation and issue links from footer component * refactor: git settings refactor. - new git container to contain repo / status - split repo container into active / empty components - split status into seperate sections for incoming, outgoing, conflict * chore: simplify environment configuration by using .env file in docker-compose * fix: update remote status after commit and push operations * refactor: restructure application initialization and configure Git user settings on startup * refactor: improve default Git user configuration handling in initialization * style: enhance UI styling and structure for Git status display * style: enhance UI layout and styling for ChangeRow and ChangeTable components * style: enhance UI layout and styling for CommitMessage component * style: improve selected row styling * style: enhance UI styling for ConflictRow and ConflictTable components * style: update merge process to include remote status update after finalization * style: update noChangesMessages for improved clarity and engagement * feat: add animated Logo component and integrate it into Navbar * feat: enhance selection handling - add shift selection - add will be selected state and styling * feat: enhance mouse tracking for shift selection * refactor: remove deprecated ActionButtons * style: unify button colors and update tooltips in IncomingChanges and OutgoingChanges components * feat: add auto-pull feature with toggle in settings and backend support * fix: update auto-pull implementation to use integer values * feat: implement auto-pull functionality in remote status update * file: improve value formatting for new files * fix: change logger level to DEBUG and add debug message for profile import attempts * refactor: remove logging statements and streamline exception handling in format compiler * feat: enhance format import process with detailed logging and error handling * feat: enhance profile import process with detailed logging and error handling * refactor: remove non error logging statements for profile compilation * feat: enhance logging for memory-based format import with detailed success and error messages * feat: add logging for language settings and compiled profile data in profile import * feat: add dedicated logging for importarr with separate log file and configuration * feat: add logging API with functions to fetch logs, search, and filter by level * feat: add logs tab to settings page with LogContainer component * feat: add LogContainer and LogViewer components for enhanced log management * fix: dynamic vertical height for log viewer * fix: reduce log file size and increase backup count for improved log management * fix: enhance error logging with exception type and full traceback for better debugging * fix: use mapped cutoff name for profile conversion to ensure correct quality mapping * fix: add validation for git repository existence before syncing * fix: implement delete constraints check before item deletion to prevent breaking references * fix: enhance delete constraints check with improved logging and name normalization * fix: add protection against deletion of required custom formats in delete constraints check * feat: implement ANSI color parsing in LogViewer for improved log readability * feat: enhance ViewChanges component with improved key parsing and rendering of changes * refactor: improve styling and structure of ResolveConflicts component for better readability and usability * fix: improve error handling and response for arr config saving * feat: extend arr configuration with additional fields and sync methods * feat: add DataSelectorModal component for selecting data to sync * feat: enhance ArrModal and DataSelectorModal with improved layout and data display * feat: update ArrContainer to use new API import and include additional arrConfig fields * feat: enhance ArrCard component with sync details and improved layout * feat: add AddButton component with custom positioning and animations * feat: replace Add New Card section with AddButton component for improved UX * feat: reposition AddButton in ArrContainer for better visibility * feat: replace AddNewCard with AddButton in RegexPage for improved UX * feat: replace AddNewCard with AddButton in FormatPage for improved UX * feat: replace AddNewCard with AddButton in ProfilePage for improved UX
404 lines
14 KiB
Python
404 lines
14 KiB
Python
# git/__init__.py
|
|
from flask import Blueprint, request, jsonify
|
|
from .status.status import get_git_status
|
|
from .status.commit_history import get_git_commit_history
|
|
from .branches.manager import Branch_Manager
|
|
from .operations.manager import GitOperations
|
|
from .repo.unlink import unlink_repository
|
|
from .repo.clone import clone_repository
|
|
from ..db import save_settings, get_settings
|
|
from ..config.config import config
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
bp = Blueprint('git', __name__, url_prefix='/git')
|
|
|
|
REPO_PATH = config.DB_DIR
|
|
branch_manager = Branch_Manager(REPO_PATH)
|
|
git_operations = GitOperations(REPO_PATH)
|
|
|
|
|
|
@bp.route('/clone', methods=['POST'])
|
|
def handle_clone_repository():
|
|
try:
|
|
new_settings = request.json
|
|
logger.info(f"Received new settings: {new_settings}")
|
|
|
|
if 'gitRepo' not in new_settings:
|
|
logger.error("Missing required field: gitRepo")
|
|
return jsonify({"error": "Missing required field: gitRepo"}), 400
|
|
|
|
success, message = clone_repository(new_settings['gitRepo'], REPO_PATH)
|
|
|
|
if success:
|
|
# Store repository URL in database
|
|
save_settings({'gitRepo': new_settings['gitRepo']})
|
|
logger.info("Settings updated and repository cloned successfully")
|
|
return jsonify({
|
|
"message":
|
|
"Repository cloned and settings updated successfully"
|
|
}), 200
|
|
else:
|
|
logger.error(f"Failed to clone repository: {message}")
|
|
return jsonify({"error": message}), 400
|
|
|
|
except Exception as e:
|
|
logger.exception("Unexpected error in clone_repository")
|
|
return jsonify({"error": f"Failed to clone repository: {str(e)}"}), 500
|
|
|
|
|
|
@bp.route('/status', methods=['GET'])
|
|
def get_status():
|
|
logger.debug("Received request for git status")
|
|
success, message = get_git_status(REPO_PATH)
|
|
|
|
if isinstance(message, str) and "No git repository" in message:
|
|
return jsonify({'success': True, 'data': None}), 200
|
|
|
|
if success:
|
|
logger.debug("Successfully retrieved git status")
|
|
return jsonify({'success': True, 'data': message}), 200
|
|
else:
|
|
logger.error(f"Failed to retrieve git status: {message}")
|
|
return jsonify({'success': False, 'error': message}), 400
|
|
|
|
|
|
@bp.route('/branch', methods=['POST'])
|
|
def create_branch():
|
|
branch_name = request.json.get('name')
|
|
base_branch = request.json.get('base', 'main')
|
|
logger.debug(
|
|
f"Received request to create branch {branch_name} from {base_branch}")
|
|
success, result = branch_manager.create(branch_name, base_branch)
|
|
if success:
|
|
logger.debug(f"Successfully created branch: {branch_name}")
|
|
return jsonify({'success': True, **result}), 200
|
|
else:
|
|
logger.error(f"Failed to create branch: {result}")
|
|
if 'merging' in result.get('error', '').lower():
|
|
return jsonify({'success': False, 'error': result}), 409
|
|
return jsonify({'success': False, 'error': result}), 400
|
|
|
|
|
|
@bp.route('/branches', methods=['GET'])
|
|
def get_branches():
|
|
logger.debug("Received request for branches")
|
|
success, result = branch_manager.get_all()
|
|
if success:
|
|
logger.debug("Successfully retrieved branches")
|
|
return jsonify({'success': True, 'data': result}), 200
|
|
else:
|
|
logger.error(f"Failed to retrieve branches: {result}")
|
|
return jsonify({'success': False, 'error': result}), 400
|
|
|
|
|
|
@bp.route('/checkout', methods=['POST'])
|
|
def checkout_branch():
|
|
branch_name = request.json.get('branch')
|
|
logger.debug(f"Received request to checkout branch: {branch_name}")
|
|
success, result = branch_manager.checkout(branch_name)
|
|
if success:
|
|
logger.debug(f"Successfully checked out branch: {branch_name}")
|
|
return jsonify({'success': True, **result}), 200
|
|
else:
|
|
logger.error(f"Failed to checkout branch: {result}")
|
|
if 'merging' in result.get('error', '').lower():
|
|
return jsonify({'success': False, 'error': result}), 409
|
|
return jsonify({'success': False, 'error': result}), 400
|
|
|
|
|
|
@bp.route('/branch/<branch_name>', methods=['DELETE'])
|
|
def delete_branch(branch_name):
|
|
logger.debug(f"Received request to delete branch: {branch_name}")
|
|
success, result = branch_manager.delete(branch_name)
|
|
if success:
|
|
logger.debug(f"Successfully deleted branch: {branch_name}")
|
|
return jsonify({'success': True, **result}), 200
|
|
else:
|
|
logger.error(f"Failed to delete branch: {result}")
|
|
if 'merging' in result.get('error', '').lower():
|
|
return jsonify({'success': False, 'error': result}), 409
|
|
return jsonify({'success': False, 'error': result}), 400
|
|
|
|
|
|
@bp.route('/branch/push', methods=['POST'])
|
|
def push_branch():
|
|
data = request.json
|
|
logger.debug(f"Received request to push branch: {data}")
|
|
branch_name = data.get('branch')
|
|
if not branch_name:
|
|
return jsonify({
|
|
"success": False,
|
|
"error": "Branch name is required"
|
|
}), 400
|
|
|
|
success, result = branch_manager.push(branch_name)
|
|
if success:
|
|
return jsonify({"success": True, "message": result}), 200
|
|
else:
|
|
if isinstance(result, str):
|
|
return jsonify({"success": False, "error": result}), 400
|
|
return jsonify({
|
|
"success": False,
|
|
"error": result.get('error', 'Unknown error occurred')
|
|
}), 400
|
|
|
|
|
|
@bp.route('/commit', methods=['POST'])
|
|
def commit_files():
|
|
files = request.json.get('files', [])
|
|
user_commit_message = request.json.get('commit_message', "Commit changes")
|
|
logger.debug(f"Received request to commit files: {files}")
|
|
|
|
commit_message = generate_commit_message(user_commit_message, files)
|
|
success, message = git_operations.commit(files, commit_message)
|
|
|
|
if success:
|
|
logger.debug("Successfully committed files")
|
|
return jsonify({'success': True, 'message': message}), 200
|
|
else:
|
|
logger.error(f"Error committing files: {message}")
|
|
return jsonify({'success': False, 'error': message}), 400
|
|
|
|
|
|
@bp.route('/push', methods=['POST'])
|
|
def push_files():
|
|
logger.debug("Received request to push changes")
|
|
success, message = git_operations.push()
|
|
|
|
if success:
|
|
logger.debug("Successfully pushed changes")
|
|
return jsonify({'success': True, 'message': message}), 200
|
|
else:
|
|
logger.error(f"Error pushing changes: {message}")
|
|
return jsonify({'success': False, 'error': message}), 400
|
|
|
|
|
|
@bp.route('/revert', methods=['POST'])
|
|
def revert_file():
|
|
file_path = request.json.get('file_path')
|
|
if not file_path:
|
|
return jsonify({
|
|
'success': False,
|
|
'error': "File path is required."
|
|
}), 400
|
|
success, message = git_operations.revert(file_path)
|
|
if success:
|
|
return jsonify({'success': True, 'message': message}), 200
|
|
else:
|
|
logger.error(f"Error reverting file: {message}")
|
|
return jsonify({'success': False, 'error': message}), 400
|
|
|
|
|
|
@bp.route('/revert-all', methods=['POST'])
|
|
def revert_all():
|
|
success, message = git_operations.revert_all()
|
|
if success:
|
|
return jsonify({'success': True, 'message': message}), 200
|
|
else:
|
|
logger.error(f"Error reverting all changes: {message}")
|
|
return jsonify({'success': False, 'error': message}), 400
|
|
|
|
|
|
@bp.route('/file', methods=['DELETE'])
|
|
def delete_file():
|
|
file_path = request.json.get('file_path')
|
|
if not file_path:
|
|
return jsonify({
|
|
'success': False,
|
|
'error': "File path is required."
|
|
}), 400
|
|
success, message = git_operations.delete(file_path)
|
|
if success:
|
|
return jsonify({'success': True, 'message': message}), 200
|
|
else:
|
|
logger.error(f"Error deleting file: {message}")
|
|
return jsonify({'success': False, 'error': message}), 400
|
|
|
|
|
|
@bp.route('/pull', methods=['POST'])
|
|
def pull_branch():
|
|
branch_name = request.json.get('branch')
|
|
success, response = git_operations.pull(branch_name)
|
|
|
|
# Handle different response types
|
|
if isinstance(response, dict):
|
|
if response.get('state') == 'resolve':
|
|
# Merge conflict is now a success case with state='resolve'
|
|
return jsonify({
|
|
'success': True,
|
|
'state': 'resolve',
|
|
'message': response['message'],
|
|
'details': response['details']
|
|
}), 200
|
|
elif response.get('state') == 'error':
|
|
# Handle error states
|
|
return jsonify({
|
|
'success': False,
|
|
'state': 'error',
|
|
'message': response['message'],
|
|
'details': response.get('details', {})
|
|
}), 409 if response.get('type') in [
|
|
'merge_conflict', 'uncommitted_changes'
|
|
] else 400
|
|
elif response.get('state') == 'complete':
|
|
# Normal success case
|
|
return jsonify({
|
|
'success': True,
|
|
'state': 'complete',
|
|
'message': response['message'],
|
|
'details': response.get('details', {})
|
|
}), 200
|
|
|
|
# Fallback for string responses or unexpected formats
|
|
if success:
|
|
return jsonify({
|
|
'success': True,
|
|
'state': 'complete',
|
|
'message': response
|
|
}), 200
|
|
return jsonify({
|
|
'success': False,
|
|
'state': 'error',
|
|
'message': str(response)
|
|
}), 400
|
|
|
|
|
|
@bp.route('/stage', methods=['POST'])
|
|
def handle_stage_files():
|
|
files = request.json.get('files', [])
|
|
success, message = git_operations.stage(files)
|
|
if success:
|
|
return jsonify({'success': True, 'message': message}), 200
|
|
else:
|
|
return jsonify({'success': False, 'error': message}), 400
|
|
|
|
|
|
@bp.route('/unstage', methods=['POST'])
|
|
def handle_unstage_files():
|
|
files = request.json.get('files', [])
|
|
success, message = git_operations.unstage(files)
|
|
if success:
|
|
return jsonify({'success': True, 'message': message}), 200
|
|
else:
|
|
return jsonify({'success': False, 'error': message}), 400
|
|
|
|
|
|
@bp.route('/unlink', methods=['POST'])
|
|
def unlink():
|
|
data = request.get_json()
|
|
remove_files = data.get('removeFiles', False)
|
|
success, message = unlink_repository(REPO_PATH, remove_files)
|
|
if success:
|
|
return jsonify({'success': True, 'message': message}), 200
|
|
else:
|
|
return jsonify({'success': False, 'error': message}), 400
|
|
|
|
|
|
def generate_commit_message(user_message, files):
|
|
return user_message
|
|
|
|
|
|
@bp.route('/resolve', methods=['POST'])
|
|
def resolve_conflicts():
|
|
logger.debug("Received request to resolve conflicts")
|
|
resolutions = request.json.get('resolutions')
|
|
|
|
if not resolutions:
|
|
return jsonify({
|
|
'success': False,
|
|
'error': "Resolutions are required"
|
|
}), 400
|
|
|
|
result = git_operations.resolve(resolutions)
|
|
|
|
if result.get('success'):
|
|
logger.debug("Successfully resolved conflicts")
|
|
return jsonify(result), 200
|
|
else:
|
|
logger.error(f"Error resolving conflicts: {result.get('error')}")
|
|
return jsonify(result), 400
|
|
|
|
|
|
@bp.route('/merge/finalize', methods=['POST'])
|
|
def finalize_merge():
|
|
"""
|
|
Route to finalize a merge after all conflicts have been resolved.
|
|
Expected to be called only after all conflicts are resolved and changes are staged.
|
|
"""
|
|
logger.debug("Received request to finalize merge")
|
|
|
|
result = git_operations.finalize_merge()
|
|
|
|
if result.get('success'):
|
|
logger.debug(
|
|
f"Successfully finalized merge with files: {result.get('committed_files', [])}"
|
|
)
|
|
return jsonify({
|
|
'success': True,
|
|
'message': result.get('message'),
|
|
'committed_files': result.get('committed_files', [])
|
|
}), 200
|
|
else:
|
|
logger.error(f"Error finalizing merge: {result.get('error')}")
|
|
return jsonify({'success': False, 'error': result.get('error')}), 400
|
|
|
|
|
|
@bp.route('/merge/abort', methods=['POST'])
|
|
def abort_merge():
|
|
logger.debug("Received request to abort merge")
|
|
success, message = git_operations.abort_merge()
|
|
if success:
|
|
logger.debug("Successfully aborted merge")
|
|
return jsonify({'success': True, 'message': message}), 200
|
|
else:
|
|
logger.error(f"Error aborting merge: {message}")
|
|
return jsonify({'success': False, 'error': message}), 400
|
|
|
|
|
|
@bp.route('/commits', methods=['GET'])
|
|
def get_commit_history():
|
|
logger.debug("Received request for commit history")
|
|
branch = request.args.get('branch') # Optional branch parameter
|
|
success, result = get_git_commit_history(REPO_PATH, branch)
|
|
|
|
if success:
|
|
logger.debug("Successfully retrieved commit history")
|
|
return jsonify({'success': True, 'data': result}), 200
|
|
else:
|
|
logger.error(f"Failed to retrieve commit history: {result}")
|
|
return jsonify({'success': False, 'error': result}), 400
|
|
|
|
|
|
@bp.route('/autopull', methods=['GET', 'POST'])
|
|
def handle_auto_pull():
|
|
try:
|
|
if request.method == 'GET':
|
|
settings = get_settings()
|
|
return jsonify({
|
|
'success':
|
|
True,
|
|
'enabled':
|
|
bool(int(settings.get('auto_pull_enabled', 0)))
|
|
}), 200
|
|
|
|
# POST handling
|
|
data = request.json
|
|
enabled = data.get('enabled')
|
|
if enabled is None:
|
|
return jsonify({
|
|
'success': False,
|
|
'error': 'enabled field is required'
|
|
}), 400
|
|
|
|
save_settings({'auto_pull_enabled': 1 if enabled else 0})
|
|
logger.info(
|
|
f"Auto-pull has been {'enabled' if enabled else 'disabled'}")
|
|
return jsonify({'success': True}), 200
|
|
|
|
except Exception as e:
|
|
logger.error(f"Error handling auto pull setting: {str(e)}")
|
|
return jsonify({'success': False, 'error': str(e)}), 500
|