Handle Gitea all token scope

This commit is contained in:
mpabi
2026-04-27 19:55:32 +02:00
parent 8c6f713de5
commit e60b7c9148
2 changed files with 15 additions and 3 deletions
+11 -3
View File
@@ -65,6 +65,11 @@ SCOPE_FIELDS = [
("u", "user"),
]
SCOPE_CATEGORY_ALIASES = {
"organization": ["organization", "org"],
"repository": ["repository", "repo"],
}
ORG_PERMISSION_FIELDS = [
("o", "owner"),
("a", "admin"),
@@ -1559,13 +1564,16 @@ def api_get_json(api_url: str, token_value: str, user_name: str = "", basic: boo
def scope_mask(scopes: list[str]) -> str:
scope_set = {scope.lower() for scope in scopes}
scope_set = {scope.strip().lower() for scope in scopes if scope.strip()}
if "all" in scope_set:
return "w" * len(SCOPE_FIELDS)
values = []
for _, category in SCOPE_FIELDS:
if f"write:{category}" in scope_set:
category_names = SCOPE_CATEGORY_ALIASES.get(category, [category])
if any(f"write:{category_name}" in scope_set for category_name in category_names):
values.append("w")
elif f"read:{category}" in scope_set:
elif any(f"read:{category_name}" in scope_set for category_name in category_names):
values.append("r")
else:
values.append("-")