Make Gitea auth token optional
For e.g. testing when running with `--dry-run`, the token may not be necessary.master
parent
5f8db2fa47
commit
8126e5de21
12
updatebot.py
12
updatebot.py
|
@ -166,7 +166,7 @@ Project = Union[
|
|||
|
||||
class RepoConfig(pydantic.BaseModel):
|
||||
url: str
|
||||
token_file: Path
|
||||
token_file: Optional[Path] = None
|
||||
branch: str = 'master'
|
||||
|
||||
@functools.cached_property
|
||||
|
@ -176,16 +176,18 @@ class RepoConfig(pydantic.BaseModel):
|
|||
return urllib.parse.urlunsplit(urlparts)
|
||||
|
||||
@functools.cached_property
|
||||
def auth_token(self) -> str:
|
||||
def auth_token(self) -> Optional[str]:
|
||||
if self.token_file:
|
||||
return self.token_file.read_text().strip()
|
||||
|
||||
def get_git_url(self) -> str:
|
||||
session = _get_session()
|
||||
headers = {}
|
||||
if token := self.auth_token:
|
||||
headers['Authorization'] = f'Bearer {token}'
|
||||
r = session.get(
|
||||
self.repo_api_url,
|
||||
headers={
|
||||
'Authorization': f'token {self.auth_token}',
|
||||
},
|
||||
headers=headers,
|
||||
)
|
||||
data = r.json()
|
||||
if ssh_url := data.get('ssh_url'):
|
||||
|
|
Loading…
Reference in New Issue