22# Copyright (c) 2025 by Brockmann Consult GmbH
33# Permissions are hereby granted under the terms of the MIT License:
44# https://opensource.org/licenses/MIT.
5-
65import copy
76import logging
87from datetime import datetime
@@ -63,7 +62,9 @@ def publish_files(
6362 pr_title : str ,
6463 pr_body : str ,
6564 base_branch : str = "main" ,
66- sync_strategy : str = "merge" , # 'ff' | 'rebase' | 'merge'
65+ sync_strategy : Literal [
66+ "ff" , "rebase" , "merge"
67+ ] = "merge" , # 'ff' | 'rebase' | 'merge'
6768 ) -> str :
6869 """Publish multiple files to a new branch and open a PR.
6970
@@ -73,16 +74,29 @@ def publish_files(
7374 commit_message: Commit message for all changes.
7475 pr_title: Title of the pull request.
7576 pr_body: Description/body of the pull request.
76- base_branch: base branch, default main
77- sync_strategy: git sync strategy
77+ base_branch: Base branch to branch from and open the PR against (default: "main")
78+ sync_strategy: How to sync local with the remote base before pushing:
79+ - "ff": Fast-forward only (no merge commits; fails if FF not possible).
80+ - "rebase": Rebase local changes onto the updated base branch.
81+ - "merge": Create a merge commit (default).
7882
7983 Returns:
8084 URL of the created pull request.
85+
86+ Raises:
87+ ValueError: If an unsupported sync_strategy is provided.
8188 """
89+
90+ if sync_strategy not in {"ff" , "rebase" , "merge" }:
91+ raise ValueError (
92+ f'Invalid sync_strategy="{ sync_strategy } ". '
93+ 'Accepted values are "ff", "rebase", "merge".'
94+ )
95+
8296 try :
8397 # Ensure local clone and remotes are ready
8498 self .github_automation .clone_sync_repository ()
85- # *** Sync fork with upstream before creating the branch/committing ***
99+ # Sync fork with upstream before creating the branch/committing
86100 self .github_automation .sync_fork_with_upstream (
87101 base_branch = base_branch , strategy = sync_strategy
88102 )
@@ -134,15 +148,15 @@ def __init__(
134148 self .collection_id = ""
135149 self .workflow_title = ""
136150
137- # Paths to configuration files, may be optional
151+ # Paths to configuration files, can be optional
138152 self .dataset_config_path = dataset_config_path
139153 self .workflow_config_path = workflow_config_path
140154
141155 # Config dicts (loaded lazily)
142156 self .dataset_config : dict [str , Any ] = {}
143157 self .workflow_config : dict [str , Any ] = {}
144158
145- # Values that may be set from configs (lazy)
159+ # Values that may be set from configs
146160 self .collection_id : str | None = None
147161 self .workflow_title : str | None = None
148162 self .workflow_id : str | None = None
0 commit comments