zt-devops-cli 0.1.6__tar.gz → 0.1.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zt-devops-cli
3
- Version: 0.1.6
3
+ Version: 0.1.8
4
4
  Summary: DevOps 平台迭代管理 CLI
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "zt-devops-cli"
7
- version = "0.1.6"
7
+ version = "0.1.8"
8
8
  description = "DevOps 平台迭代管理 CLI"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -89,12 +89,12 @@ def open_login_page(page) -> bool:
89
89
 
90
90
  return False
91
91
 
92
- def get_cookies_from_browser() -> dict:
92
+ def get_cookies_from_browser(headless) -> dict:
93
93
  """通过 Playwright 从浏览器获取 cookie"""
94
- print("正在打开浏览器,请登录...")
94
+ print("正在启动浏览器(无头模式),请登录...")
95
95
 
96
96
  with sync_playwright() as p:
97
- browser = p.chromium.launch(headless=False)
97
+ browser = p.chromium.launch(headless=headless)
98
98
  context = browser.new_context()
99
99
  page = context.new_page()
100
100
 
@@ -103,9 +103,16 @@ def get_cookies_from_browser() -> dict:
103
103
 
104
104
  # 尝试自动登录
105
105
  if not open_login_page(page):
106
- print("自动登陆失败. 请在浏览器中完成登录,登录成功后会自动继续...")
107
-
108
- print("登陆中.检测关键 cookie 出现")
106
+ print(
107
+ "自动登录失败。无头模式下无法手动操作页面,请设置环境变量 "
108
+ "ZT_SSO_USERNAME ZT_SSO_PASSWORD 后重试。"
109
+ )
110
+ browser.close()
111
+ raise RuntimeError(
112
+ "无头模式需要 ZT_SSO_USERNAME / ZT_SSO_PASSWORD 环境变量以完成自动登录。"
113
+ )
114
+
115
+ print("等待登录完成...")
109
116
  page.wait_for_function(
110
117
  f"""() => {{
111
118
  const cookies = document.cookie;
@@ -149,10 +156,10 @@ def get_cookies_from_browser() -> dict:
149
156
 
150
157
  return cookie_dict
151
158
 
152
- def login() -> dict:
159
+ def login(headless) -> dict:
153
160
  """手动登录 - 强制打开浏览器重新获取 cookie"""
154
- print("正在打开浏览器,请重新登录...")
155
- cookies = get_cookies_from_browser()
161
+ print("正在启动浏览器(无头模式),请重新登录...")
162
+ cookies = get_cookies_from_browser(headless)
156
163
  save_cookies(cookies)
157
164
  print("登录成功,cookie 已缓存!")
158
165
  return cookies
@@ -102,10 +102,14 @@ def cli(ctx, project, output_format):
102
102
 
103
103
 
104
104
  @cli.command("login")
105
- def cmd_login():
106
- """登录 - 打开浏览器重新获取 cookie"""
107
- login()
108
-
105
+ @click.option(
106
+ "--headed",
107
+ is_flag=True,
108
+ help="显示浏览器窗口,用于无环境变量时的手动登录",
109
+ )
110
+ def cmd_login(headed):
111
+ """登录 - 打开浏览器重新获取 cookie(默认无头;需手动登录时请传 --headed)"""
112
+ login(headless=not headed)
109
113
 
110
114
  @cli.group()
111
115
  def sprint():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zt-devops-cli
3
- Version: 0.1.6
3
+ Version: 0.1.8
4
4
  Summary: DevOps 平台迭代管理 CLI
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
File without changes
File without changes