uEdition-Editor 2.0.0b7__py3-none-any.whl → 2.0.0b9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of uEdition-Editor might be problematic. Click here for more details.

@@ -3,4 +3,4 @@
3
3
  # SPDX-License-Identifier: MIT
4
4
  """About this package."""
5
5
 
6
- __version__ = "2.0.0b7"
6
+ __version__ = "2.0.0b9"
@@ -34,6 +34,7 @@ class APIStatusGit(BaseModel):
34
34
 
35
35
  enabled: bool
36
36
  default_branch: str | None = None
37
+ protect_default_branch: bool | None = None
37
38
 
38
39
 
39
40
  class APIStatus(BaseModel):
@@ -61,6 +62,7 @@ def api() -> dict:
61
62
  Repository(init_settings.base_path, flags=RepositoryOpenFlag.NO_SEARCH)
62
63
  api_status["git"]["enabled"] = True
63
64
  api_status["git"]["default_branch"] = init_settings.git.default_branch
65
+ api_status["git"]["protect_default_branch"] = init_settings.git.protect_default_branch
64
66
  except GitError:
65
67
  pass
66
68
  return api_status
@@ -147,12 +147,14 @@ async def merge_from_default(
147
147
  Signature(current_user["name"], current_user["sub"]),
148
148
  extra_parents=[default_branch_head.id],
149
149
  )
150
+ await cron.insecure_track_branches()
150
151
 
151
152
 
152
153
  @router.delete("/{branch_id}", status_code=204)
153
154
  async def delete_branch(
154
155
  branch_id: str,
155
156
  current_user: Annotated[dict, Depends(get_current_user)], # noqa:ARG001
157
+ local_delete: Annotated[bool, Header(alias="x-ueditor-delete-local-only")] = False, # noqa:FBT002
156
158
  ) -> None:
157
159
  """Delete the given branch locally and remotely."""
158
160
  async with BranchContextManager(branch_id) as repo:
@@ -160,7 +162,7 @@ async def delete_branch(
160
162
  if init_settings.git.default_branch == branch_id:
161
163
  raise HTTPException(422, detail=[{"msg": "you cannot delete the default branch"}])
162
164
  repo.checkout(repo.branches[init_settings.git.default_branch])
163
- if init_settings.git.remote_name in list(repo.remotes.names()):
165
+ if init_settings.git.remote_name in list(repo.remotes.names()) and not local_delete:
164
166
  if repo.branches[branch_id].upstream is not None:
165
167
  repo.remotes[init_settings.git.remote_name].push(
166
168
  [f":refs/heads/{branch_id}"], callbacks=RemoteRepositoryCallbacks()
@@ -384,6 +384,16 @@ async def create_file(
384
384
  ) -> None:
385
385
  """Create a new file in the repo."""
386
386
  try:
387
+ if init_settings.git.protect_default_branch and init_settings.git.default_branch == branch_id:
388
+ raise HTTPException(
389
+ 422,
390
+ detail=[
391
+ {
392
+ "loc": ["path", "path"],
393
+ "msg": "this branch is protected",
394
+ }
395
+ ],
396
+ )
387
397
  async with BranchContextManager(branch_id) as repo:
388
398
  if new_type in ("file", "folder"):
389
399
  full_path = os.path.abspath(os.path.join(init_settings.base_path, *path.split("/")))
@@ -724,6 +734,16 @@ async def update_file(
724
734
  ) -> None:
725
735
  """Update the file in the repo."""
726
736
  try:
737
+ if init_settings.git.protect_default_branch and init_settings.git.default_branch == branch_id:
738
+ raise HTTPException(
739
+ 422,
740
+ detail=[
741
+ {
742
+ "loc": ["path", "path"],
743
+ "msg": "this branch is protected",
744
+ }
745
+ ],
746
+ )
727
747
  async with BranchContextManager(branch_id) as repo:
728
748
  ueditor_settings = get_ueditor_settings()
729
749
  full_path = os.path.abspath(os.path.join(init_settings.base_path, *path.split("/")))
@@ -783,6 +803,16 @@ async def delete_file(
783
803
  ) -> None:
784
804
  """Delete a file in the repo."""
785
805
  try:
806
+ if init_settings.git.protect_default_branch and init_settings.git.default_branch == branch_id:
807
+ raise HTTPException(
808
+ 422,
809
+ detail=[
810
+ {
811
+ "loc": ["path", "path"],
812
+ "msg": "this branch is protected",
813
+ }
814
+ ],
815
+ )
786
816
  async with BranchContextManager(branch_id) as repo:
787
817
  full_path = os.path.abspath(os.path.join(init_settings.base_path, *path.split("/")))
788
818
  if full_path.startswith(os.path.abspath(init_settings.base_path)):
uedition_editor/cron.py CHANGED
@@ -16,11 +16,18 @@ from uedition_editor.state import local_branches, remote_branches
16
16
  logger = logging.getLogger(__name__)
17
17
 
18
18
 
19
+ def format_remote_branch_title(title: str) -> str:
20
+ """Format the remote branch name as a title."""
21
+ if "/" in title:
22
+ return de_slugify(title[title.find("/") + 1 :])
23
+ return title
24
+
25
+
19
26
  async def insecure_track_branches():
20
27
  """
21
28
  Track the status of all git branches.
22
29
 
23
- Use only when the uedition_lock is already completed.
30
+ Use only when the uedition_lock is already aquired.
24
31
  """
25
32
  remote_branches.clear()
26
33
  local_branches.clear()
@@ -37,9 +44,10 @@ async def insecure_track_branches():
37
44
  if init_settings.git.remote_name in list(repo.remotes.names()):
38
45
  if repo.branches[branch_name].upstream is not None:
39
46
  pull_branch(repo, branch_name)
40
- diff = repo.diff(
41
- repo.revparse_single(init_settings.git.default_branch),
47
+ merge_base = repo.merge_base(
48
+ repo.revparse_single(init_settings.git.default_branch).id, repo.revparse_single(branch_name).id
42
49
  )
50
+ diff = repo.diff(merge_base, repo.revparse_single(init_settings.git.default_branch))
43
51
  local_branches.append(
44
52
  {
45
53
  "id": branch_name,
@@ -49,7 +57,7 @@ async def insecure_track_branches():
49
57
  )
50
58
  for branch_name in repo.branches.remote:
51
59
  if repo.branches[branch_name].remote_name == init_settings.git.remote_name and "HEAD" not in branch_name:
52
- remote_branches.append({"id": branch_name, "title": de_slugify(branch_name)})
60
+ remote_branches.append({"id": branch_name, "title": format_remote_branch_title(branch_name)})
53
61
  logger.debug("Tracking complete")
54
62
  except GitError as ge:
55
63
  logger.error(ge)