kopia lustrzana https://github.com/Langenfeld/py-gitea
fix: remove mutable argument in team creation function
rodzic
65c763ae66
commit
ead89d325b
|
@ -1,11 +1,35 @@
|
|||
import logging
|
||||
from datetime import datetime
|
||||
from typing import List, Tuple, Dict, Sequence, Optional, Union, Set
|
||||
|
||||
from dataclasses import dataclass, fields
|
||||
from .baseapiobject import ReadonlyApiObject, ApiObject
|
||||
from .exceptions import *
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class RepoUnits:
|
||||
code: str = "none"
|
||||
issues: str = "none"
|
||||
ext_issues: str = "none"
|
||||
wiki: str = "none"
|
||||
pulls: str = "none"
|
||||
releases: str = "none"
|
||||
ext_wiki: str = "none"
|
||||
|
||||
def to_dict(self) -> dict[str, str]:
|
||||
"""Return the correctly prefixed (added "repo.") representation for gitea Repository runit Rights"""
|
||||
return {
|
||||
f"repo.{field.name}": getattr(self, field.name) for field in fields(self)
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, unit_dict: dict[str, str]) -> "RepoUnits":
|
||||
"""Parse all known repo units from the dictionary returned by the api"""
|
||||
return RepoUnits(
|
||||
**{k[5:]: v for k, v in unit_dict.items() if k[5:] in fields(cls)}
|
||||
)
|
||||
|
||||
|
||||
class Organization(ApiObject):
|
||||
"""see https://try.gitea.io/api/swagger#/organization/orgGetAll"""
|
||||
|
||||
|
@ -119,10 +143,12 @@ class Organization(ApiObject):
|
|||
setattr(t, "_organization", self)
|
||||
return teams
|
||||
|
||||
def get_team(self, name, ignore_case : bool = False) -> "Team":
|
||||
def get_team(self, name, ignore_case: bool = False) -> "Team":
|
||||
teams = self.get_teams()
|
||||
for team in teams:
|
||||
if (not ignore_case and team.name == name) or (ignore_case and team.name.lower() == name.lower()):
|
||||
if (not ignore_case and team.name == name) or (
|
||||
ignore_case and team.name.lower() == name.lower()
|
||||
):
|
||||
return team
|
||||
raise NotFoundException("Team not existent in organization.")
|
||||
|
||||
|
@ -916,7 +942,8 @@ class Team(ApiObject):
|
|||
return hash(self.organization) ^ hash(self.id)
|
||||
|
||||
_fields_to_parsers = {
|
||||
"organization": lambda gitea, o: Organization.parse_response(gitea, o)
|
||||
"organization": lambda gitea, o: Organization.parse_response(gitea, o),
|
||||
"units_map": lambda gitea, o: RepoUnits.from_dict(o),
|
||||
}
|
||||
|
||||
_patchable_fields = {
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
import logging
|
||||
import json
|
||||
from typing import List, Dict, Union
|
||||
|
||||
from immutabledict import immutabledict
|
||||
import requests
|
||||
import urllib3
|
||||
|
||||
from .apiobject import User, Organization, Repository, Team
|
||||
from .apiobject import User, Organization, Repository, Team, RepoUnits
|
||||
from .exceptions import NotFoundException, ConflictException, AlreadyExistsException
|
||||
|
||||
|
||||
|
@ -352,15 +351,7 @@ class Gitea:
|
|||
"repo.releases",
|
||||
"repo.ext_wiki",
|
||||
),
|
||||
units_map: Dict[str, str] = {
|
||||
"repo.code": "none",
|
||||
"repo.issues": "none",
|
||||
"repo.ext_issues": "none",
|
||||
"repo.wiki": "none",
|
||||
"repo.pulls": "none",
|
||||
"repo.releases": "none",
|
||||
"repo.ext_wiki": "none",
|
||||
},
|
||||
units_map: "RepoUnits" = RepoUnits(),
|
||||
):
|
||||
"""Creates a Team.
|
||||
|
||||
|
@ -379,7 +370,7 @@ class Gitea:
|
|||
"can_create_org_repo": can_create_org_repo,
|
||||
"includes_all_repositories": includes_all_repositories,
|
||||
"units": units,
|
||||
"units_map": units_map,
|
||||
"units_map": units_map.to_dict(),
|
||||
},
|
||||
)
|
||||
if "id" in result:
|
||||
|
|
Ładowanie…
Reference in New Issue