Jcloud Settings增加Git Username和Git Access Token,App source支持gitea私有库克隆

This commit is contained in:
jingrow 2025-08-22 00:25:52 +08:00
parent 99fa89a1a0
commit 9892c569ac
4 changed files with 68 additions and 14 deletions

View File

@ -262,8 +262,18 @@ def branches(owner, name, installation=None):
def get_auth_headers(installation_id: str | None = None) -> "dict[str, str]":
settings = jingrow.get_single("Jcloud Settings")
git_service_type = settings.get("git_service_type") or "gitea"
if git_service_type.lower() == "gitea":
git_access_token = settings.get_password("git_access_token")
if git_access_token:
return {"Authorization": f"token {git_access_token}"}
if git_service_type.lower() == "github" and installation_id:
if token := get_access_token(installation_id):
return {"Authorization": f"token {token}"}
return {}

View File

@ -237,25 +237,55 @@ class AppSource(Document):
)
def get_auth_headers(self) -> dict:
settings = jingrow.get_single("Jcloud Settings")
git_service_type = settings.get("git_service_type") or "gitea"
if git_service_type.lower() == "gitea":
git_access_token = settings.get_password("git_access_token")
if git_access_token:
return {"Authorization": f"token {git_access_token}"}
if git_service_type.lower() == "github" and self.github_installation_id:
return get_auth_headers(self.github_installation_id)
return {}
def get_access_token(self) -> Optional[str]:
if self.github_installation_id:
settings = jingrow.get_single("Jcloud Settings")
git_service_type = settings.get("git_service_type") or "gitea"
if git_service_type.lower() == "gitea":
git_access_token = settings.get_password("git_access_token")
if git_access_token:
return git_access_token
if git_service_type.lower() == "github" and self.github_installation_id:
return get_access_token(self.github_installation_id)
return jingrow.get_value("Jcloud Settings", None, "github_access_token")
return settings.get_password("github_access_token")
def get_repo_url(self) -> str:
if not self.github_installation_id:
settings = jingrow.get_single("Jcloud Settings")
if not settings:
return self.repository_url
git_service_type = settings.get("git_service_type") or "gitea"
if git_service_type.lower() == "gitea":
gite_username = settings.get("gite_username")
git_access_token = settings.get_password("git_access_token")
if gite_username and git_access_token:
return f"http://{gite_username}:{git_access_token}@git.jingrow.com/{self.repository_owner}/{self.repository}"
if git_service_type.lower() == "github" and self.github_installation_id:
token = get_access_token(self.github_installation_id)
if token is None:
# Do not edit without updating deploy_notifications.py
raise Exception("App installation token could not be fetched", self.app)
return f"https://x-access-token:{token}@git.jingrow.com/{self.repository_owner}/{self.repository}"
return self.repository_url
def get_gitea_commit_info(self, commit_hash: None | str = None) -> tuple[str, dict, bool]:
"""专门处理Gitea API响应的函数"""
try:

View File

@ -204,8 +204,10 @@
"infrastructure_tab",
"git_section",
"git_service_type",
"gite_username",
"column_break_jhbn",
"git_url",
"git_access_token",
"agent_section",
"agent_repository_owner",
"agent_sentry_dsn",
@ -1597,11 +1599,21 @@
"fieldname": "west_api_password",
"fieldtype": "Password",
"label": "West Api Password"
},
{
"fieldname": "gite_username",
"fieldtype": "Data",
"label": "Gite Username"
},
{
"fieldname": "git_access_token",
"fieldtype": "Password",
"label": "Git Access Token"
}
],
"issingle": 1,
"links": [],
"modified": "2025-07-31 17:10:00.443783",
"modified": "2025-08-21 23:47:53.416916",
"modified_by": "Administrator",
"module": "Jcloud",
"name": "Jcloud Settings",

View File

@ -80,8 +80,10 @@ class JcloudSettings(Document):
enforce_storage_limits: DF.Check
free_credits_cny: DF.Currency
free_credits_usd: DF.Currency
git_access_token: DF.Password | None
git_service_type: DF.Literal["gitea", "github"]
git_url: DF.Data | None
gite_username: DF.Data | None
github_access_token: DF.Data | None
github_app_client_id: DF.Data | None
github_app_client_secret: DF.Data | None