Skip to content

Commit 73ed665

Browse files
committed
Refactor batch processing and git push functionality + use original output directory and enhance push error handling with detailed output
1 parent aee93f3 commit 73ed665

3 files changed

Lines changed: 25 additions & 13 deletions

File tree

exporters/git/batch_processor.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,20 @@ def process_files_with_git_batch(json_files, output_dir, verbose, predocs):
5555
print(f"Fel vid läsning av {abs_json_file}: {e}")
5656
continue
5757

58-
# Create documents in the cloned repository
59-
make_document(data, output_dir, ["git"], True, verbose, True, predocs, True)
58+
# Create documents in the cloned repository AND save to original output directory
59+
# First convert to absolute path since we changed working directory
60+
original_output_dir = Path(original_cwd) / Path(output_dir).name if not Path(output_dir).is_absolute() else Path(output_dir)
61+
make_document(data, original_output_dir, ["git"], True, verbose, True, predocs, True)
6062

6163
# Push all commits to target repository
6264
if verbose:
6365
print(f"Pushar batch till target repository...")
6466

65-
subprocess.run(['git', 'push', 'origin', unique_branch],
66-
check=True, capture_output=True, timeout=GIT_TIMEOUT)
67-
68-
print(f"Batch pushad till target repository som branch '{unique_branch}'")
67+
from exporters.git.git_utils import push_to_target_repository
68+
if push_to_target_repository(unique_branch, 'origin', verbose):
69+
print(f"Batch pushad till target repository som branch '{unique_branch}'")
70+
else:
71+
print(f"Misslyckades med att pusha batch till target repository")
6972

7073
except subprocess.CalledProcessError as e:
7174
print(f"Fel vid git batch processing: {e}")

exporters/git/git_utils.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,13 +432,20 @@ def push_to_target_repository(branch_name: str, remote_name: str = 'target', ver
432432
if verbose:
433433
print(f"Pushar branch '{branch_name}' till remote '{remote_name}'...")
434434

435-
subprocess.run(['git', 'push', remote_name, branch_name],
436-
check=True, capture_output=True, timeout=GIT_TIMEOUT)
437-
438-
if verbose:
439-
print(f"Lyckades pusha branch '{branch_name}' till {repo_url}")
435+
result = subprocess.run(['git', 'push', remote_name, branch_name],
436+
capture_output=True, text=True, timeout=GIT_TIMEOUT)
440437

441-
return True
438+
if result.returncode == 0:
439+
if verbose:
440+
print(f"Lyckades pusha branch '{branch_name}' till {repo_url}")
441+
return True
442+
else:
443+
print(f"Push misslyckades med exit code {result.returncode}")
444+
if result.stdout:
445+
print(f"Git stdout: {result.stdout}")
446+
if result.stderr:
447+
print(f"Git stderr: {result.stderr}")
448+
return False
442449

443450
except subprocess.CalledProcessError as e:
444451
print(f"Fel vid push till target repository: {e}")

sfs_processor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ def _create_markdown_document(data: Dict[str, Any], output_path: Path, git_mode:
228228
# TODO: markdown_content = convert_tables_in_markdown(markdown_content, verbose)
229229

230230
# Apply temporal processing to handle selex attributes
231-
# TODO: markdown_content = apply_temporal(markdown_content, today, verbose=verbose)
231+
from datetime import datetime
232+
today = datetime.now().strftime('%Y-%m-%d')
233+
markdown_content = apply_temporal(markdown_content, today, verbose=verbose)
232234

233235
# Extract amendments for git logic (if needed)
234236
# TODO: amendments = extract_amendments(data.get('andringsforfattningar', []))

0 commit comments

Comments
 (0)