@@ -1050,13 +1050,6 @@ def generate_live_patch(
10501050 web_commit_signoff_required , web_commit_signoff_required
10511051 )
10521052
1053- # FIXME: needed to add this hack to ensure that gh_pages_source_path is also present in
1054- # the modified data as GitHub needs the path as well when the branch is changed.
1055- # this needs to make clean to support making the diff operation generic as possible.
1056- if "gh_pages_source_branch" in modified_repo :
1057- gh_pages_source_path = cast (Repository , coerced_object ).gh_pages_source_path
1058- modified_repo ["gh_pages_source_path" ] = Change (gh_pages_source_path , gh_pages_source_path )
1059-
10601053 # similar fix as above for squash_merge_commit_title and squash_merge_commit_message as well
10611054 squash_merge_commit_title_present = "squash_merge_commit_title" in modified_repo
10621055 squash_merge_commit_message_present = "squash_merge_commit_message" in modified_repo
@@ -1156,6 +1149,26 @@ def generate_live_patch(
11561149 handler ,
11571150 )
11581151
1152+ @staticmethod
1153+ def _include_gh_pages_patch_required_properties (patch : LivePatch [Repository ]) -> LivePatch [Repository ]:
1154+ """
1155+ Ensure that the gh_pages_source_branch and gh_pages_source_path are set when
1156+ the patch contains gh_pages change.
1157+ """
1158+ if patch .changes :
1159+ gh_pages_source_branch_present = "gh_pages_source_branch" in patch .changes
1160+ gh_pages_source_path_present = "gh_pages_source_path" in patch .changes
1161+
1162+ if gh_pages_source_path_present and not gh_pages_source_branch_present :
1163+ gh_pages_source_branch = cast (Repository , patch .current_object ).gh_pages_source_branch
1164+ patch .changes ["gh_pages_source_branch" ] = Change (gh_pages_source_branch , gh_pages_source_branch )
1165+
1166+ if gh_pages_source_branch_present and not gh_pages_source_path_present :
1167+ gh_pages_source_path = cast (Repository , patch .changes ).gh_pages_source_path
1168+ patch .changes ["gh_pages_source_path" ] = Change (gh_pages_source_path , gh_pages_source_path )
1169+
1170+ return patch
1171+
11591172 @classmethod
11601173 async def apply_live_patch (
11611174 cls ,
@@ -1188,18 +1201,7 @@ async def apply_live_patch(
11881201 await provider .delete_repo (org_id , unwrap (patch .current_object ).name )
11891202
11901203 case LivePatchType .CHANGE :
1191- # if the source path is changed, also ensure that the branch is set when
1192- # the branch is not changed. The branch is required by GitHub.
1193- if (
1194- patch .changes
1195- and "gh_pages_source_path" in patch .changes
1196- and "gh_pages_source_branch" not in patch .changes
1197- ):
1198- patch .changes ["gh_pages_source_branch" ] = Change (
1199- unwrap (patch .current_object ).gh_pages_source_branch ,
1200- unwrap (patch .current_object ).gh_pages_source_branch ,
1201- )
1202-
1204+ cls ._include_gh_pages_patch_required_properties (patch )
12031205 expected_object = unwrap (patch .expected_object )
12041206 github_settings = await cls .changes_to_provider (org_id , unwrap (patch .changes ), provider )
12051207
0 commit comments