160 lines
6.6 KiB
Python
160 lines
6.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
The 'Repository Transformation' tab for the main application notebook.
|
|
|
|
This tab provides a powerful, one-time tool to permanently transform a local
|
|
repository to match a target corporate identity. This includes rewriting
|
|
Git history and renaming the repository on the local filesystem and on the
|
|
local Gitea server.
|
|
"""
|
|
|
|
import tkinter as tk
|
|
from tkinter import ttk
|
|
from typing import Callable, Optional
|
|
|
|
from gitutility.gui.tooltip import Tooltip
|
|
|
|
|
|
class TransformationTab(ttk.Frame):
|
|
"""
|
|
GUI for the Repository Transformation workflow.
|
|
"""
|
|
|
|
def __init__(self, master: tk.Misc, **kwargs):
|
|
"""
|
|
Initializes the Transformation tab.
|
|
|
|
Args:
|
|
master: The parent widget (the ttk.Notebook).
|
|
**kwargs: Dictionary of callbacks from the main controller.
|
|
"""
|
|
super().__init__(master, padding=(10, 10))
|
|
|
|
# Store the callbacks
|
|
self.transform_repository_callback = kwargs.get("transform_repository_cb")
|
|
self.configure_gitea_callback = kwargs.get("configure_gitea_cb")
|
|
|
|
# --- Tkinter Variables for this tab's widgets ---
|
|
self.target_repo_name_var = tk.StringVar()
|
|
self.target_author_name_var = tk.StringVar()
|
|
self.target_author_email_var = tk.StringVar()
|
|
self.automate_gitea_var = tk.BooleanVar(value=False)
|
|
|
|
self.columnconfigure(0, weight=1)
|
|
self._create_widgets()
|
|
|
|
def _create_widgets(self) -> None:
|
|
"""Creates and arranges all widgets for this tab."""
|
|
|
|
# --- Section 1: Target Corporate Identity ---
|
|
identity_frame = ttk.LabelFrame(
|
|
self,
|
|
text="Target Corporate Identity",
|
|
padding=(10, 10)
|
|
)
|
|
identity_frame.grid(row=0, column=0, sticky="ew", padx=5, pady=5)
|
|
identity_frame.columnconfigure(1, weight=1)
|
|
|
|
identity_desc = (
|
|
"Define the identity of the target corporate repository. The currently selected "
|
|
"local repository will be transformed to match these details."
|
|
)
|
|
ttk.Label(identity_frame, text=identity_desc, wraplength=500, justify=tk.LEFT).grid(
|
|
row=0, column=0, columnspan=2, sticky="w", pady=(0, 10)
|
|
)
|
|
|
|
ttk.Label(identity_frame, text="Target Repository Name:").grid(
|
|
row=1, column=0, sticky="w", padx=5, pady=2
|
|
)
|
|
self.repo_name_entry = ttk.Entry(identity_frame, textvariable=self.target_repo_name_var)
|
|
self.repo_name_entry.grid(row=1, column=1, sticky="ew", padx=5, pady=2)
|
|
Tooltip(self.repo_name_entry, "The exact name of the repository on the corporate server (e.g., S1005403_RisCC).")
|
|
|
|
ttk.Label(identity_frame, text="Target Author Name:").grid(
|
|
row=2, column=0, sticky="w", padx=5, pady=2
|
|
)
|
|
self.author_name_entry = ttk.Entry(identity_frame, textvariable=self.target_author_name_var)
|
|
self.author_name_entry.grid(row=2, column=1, sticky="ew", padx=5, pady=2)
|
|
Tooltip(self.author_name_entry, "The corporate user ID required as the author/committer (e.g., VALLONGOL).")
|
|
|
|
ttk.Label(identity_frame, text="Target Author Email:").grid(
|
|
row=3, column=0, sticky="w", padx=5, pady=2
|
|
)
|
|
self.author_email_entry = ttk.Entry(identity_frame, textvariable=self.target_author_email_var)
|
|
self.author_email_entry.grid(row=3, column=1, sticky="ew", padx=5, pady=2)
|
|
Tooltip(self.author_email_entry, "The corporate email address required for commits.")
|
|
|
|
# --- Section 2: Gitea Automation ---
|
|
gitea_frame = ttk.LabelFrame(
|
|
self, text="Gitea Automation (Optional)", padding=(10, 10)
|
|
)
|
|
gitea_frame.grid(row=1, column=0, sticky="ew", padx=5, pady=10)
|
|
|
|
self.automate_gitea_check = ttk.Checkbutton(
|
|
gitea_frame,
|
|
text="Automatically create repository on local Gitea and push",
|
|
variable=self.automate_gitea_var
|
|
)
|
|
self.automate_gitea_check.pack(side=tk.LEFT, padx=5)
|
|
Tooltip(self.automate_gitea_check, "If checked, the tool will use the Gitea API to create the new repository and push the transformed history.")
|
|
|
|
self.configure_gitea_button = ttk.Button(
|
|
gitea_frame,
|
|
text="Configure Gitea...",
|
|
command=self.configure_gitea_callback
|
|
)
|
|
self.configure_gitea_button.pack(side=tk.RIGHT, padx=5)
|
|
Tooltip(self.configure_gitea_button, "Set the URL and API Token for your local Gitea server.")
|
|
|
|
# --- Section 3: Transformation Action ---
|
|
action_frame = ttk.LabelFrame(
|
|
self,
|
|
text="Transformation Action",
|
|
padding=(10, 10)
|
|
)
|
|
action_frame.grid(row=2, column=0, sticky="ew", padx=5, pady=(15, 5))
|
|
action_frame.columnconfigure(0, weight=1)
|
|
|
|
action_desc = (
|
|
"WARNING: This is a highly destructive operation that will permanently modify your local repository and "
|
|
"create a new one on your local Gitea server. Always work on a copy or ensure you have a backup."
|
|
)
|
|
warning_label = ttk.Label(action_frame, text=action_desc, wraplength=500, justify=tk.LEFT, foreground="red")
|
|
warning_label.pack(pady=(0, 10))
|
|
|
|
self.transform_button = ttk.Button(
|
|
action_frame,
|
|
text="Transform and Rename Repository",
|
|
command=self._on_transform_repo
|
|
)
|
|
self.transform_button.pack(pady=10)
|
|
Tooltip(self.transform_button, "Begin the automated repository transformation process.")
|
|
|
|
def set_action_widgets_state(self, state: str) -> None:
|
|
"""
|
|
Sets the state of all action widgets in this tab.
|
|
"""
|
|
widgets = [
|
|
self.repo_name_entry,
|
|
self.author_name_entry,
|
|
self.author_email_entry,
|
|
self.automate_gitea_check,
|
|
self.configure_gitea_button,
|
|
self.transform_button,
|
|
]
|
|
for widget in widgets:
|
|
if widget and widget.winfo_exists():
|
|
widget.config(state=state)
|
|
|
|
def _on_transform_repo(self):
|
|
"""
|
|
Internal handler for the 'Transform' button. Gathers data and calls the callback.
|
|
"""
|
|
if callable(self.transform_repository_callback):
|
|
target_details = {
|
|
"repo_name": self.target_repo_name_var.get().strip(),
|
|
"author_name": self.target_author_name_var.get().strip(),
|
|
"author_email": self.target_author_email_var.get().strip(),
|
|
"automate_gitea": self.automate_gitea_var.get()
|
|
}
|
|
self.transform_repository_callback(target_details) |