mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
[git_auth] Fix type checking
Bug: b/351071334 Change-Id: Icc54c7b0b4783cea80dda9fda9ac2c7086bd14fe Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5742438 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Reviewed-by: Yiwei Zhang <yiwzhang@google.com> Commit-Queue: Allen Li <ayatane@chromium.org>
This commit is contained in:
15
git_auth.py
15
git_auth.py
@@ -55,7 +55,7 @@ class ConfigChanger(object):
|
||||
self.mode: ConfigMode = mode
|
||||
|
||||
self._remote_url: str = remote_url
|
||||
self._set_config_func: Callable[..., str] = set_config_func
|
||||
self._set_config_func: Callable[..., None] = set_config_func
|
||||
|
||||
@functools.cached_property
|
||||
def _shortname(self) -> str:
|
||||
@@ -84,13 +84,20 @@ class ConfigChanger(object):
|
||||
# This is determined either from the branch or repo config.
|
||||
#
|
||||
# Example: chromium-review.googlesource.com
|
||||
gerrit_host: str = cl.GetGerritHost()
|
||||
gerrit_host = cl.GetGerritHost()
|
||||
# This depends on what the user set for their remote.
|
||||
# There are a couple potential variations for the same host+repo.
|
||||
#
|
||||
# Example:
|
||||
# https://chromium.googlesource.com/chromium/tools/depot_tools.git
|
||||
remote_url: str = cl.GetRemoteUrl()
|
||||
remote_url = cl.GetRemoteUrl()
|
||||
|
||||
if gerrit_host is None or remote_url is None:
|
||||
raise Exception(
|
||||
'Error Git auth settings inferring from environment:'
|
||||
f' {gerrit_host=} {remote_url=}')
|
||||
assert gerrit_host is not None
|
||||
assert remote_url is not None
|
||||
|
||||
return cls(
|
||||
mode=cls._infer_mode(cwd, gerrit_host),
|
||||
@@ -102,7 +109,7 @@ class ConfigChanger(object):
|
||||
"""Infer default mode to use."""
|
||||
if not newauth.Enabled():
|
||||
return ConfigMode.NO_AUTH
|
||||
email: str = scm.GIT.GetConfig(cwd, 'user.email', default='')
|
||||
email: str = scm.GIT.GetConfig(cwd, 'user.email') or ''
|
||||
if gerrit_util.ShouldUseSSO(gerrit_host, email):
|
||||
return ConfigMode.NEW_AUTH_SSO
|
||||
return ConfigMode.NEW_AUTH
|
||||
|
||||
@@ -28,6 +28,7 @@ import sys
|
||||
import tempfile
|
||||
import textwrap
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
import uuid
|
||||
@@ -856,7 +857,7 @@ class Settings(object):
|
||||
'"git cl config".')
|
||||
return self.tree_status_url
|
||||
|
||||
def GetViewVCUrl(self):
|
||||
def GetViewVCUrl(self) -> str:
|
||||
if not self.viewvc_url:
|
||||
self.viewvc_url = self._GetConfig('rietveld.viewvc-url')
|
||||
return self.viewvc_url
|
||||
@@ -2238,7 +2239,7 @@ class Changelist(object):
|
||||
# Still raise exception so that stack trace is printed.
|
||||
raise
|
||||
|
||||
def GetGerritHost(self):
|
||||
def GetGerritHost(self) -> Optional[str]:
|
||||
# Populate self._gerrit_host
|
||||
self.GetCodereviewServer()
|
||||
|
||||
@@ -2259,7 +2260,7 @@ class Changelist(object):
|
||||
return None
|
||||
return urllib.parse.urlparse(remote_url).netloc
|
||||
|
||||
def _GetGerritHostFromRemoteUrl(self):
|
||||
def _GetGerritHostFromRemoteUrl(self) -> str:
|
||||
url = urllib.parse.urlparse(self.GetRemoteUrl())
|
||||
parts = url.netloc.split('.')
|
||||
|
||||
@@ -2275,7 +2276,7 @@ class Changelist(object):
|
||||
|
||||
return '.'.join(parts)
|
||||
|
||||
def GetCodereviewServer(self):
|
||||
def GetCodereviewServer(self) -> str:
|
||||
if not self._gerrit_server:
|
||||
# If we're on a branch then get the server potentially associated
|
||||
# with that branch.
|
||||
|
||||
Reference in New Issue
Block a user