809339fee3
CI/CD Pipeline / PR Build API Image (push) Has been skipped
CI/CD Pipeline / PR Build Web Image (push) Has been skipped
CI/CD Pipeline / PR Build Worker Image (push) Has been skipped
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / Frontend Lint (push) Successful in 38s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 29s
CI/CD Pipeline / Build Production API Image (push) Has been skipped
CI/CD Pipeline / Build Production Web Image (push) Has been skipped
CI/CD Pipeline / Build Production Worker Image (push) Has been skipped
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Validate Code Quality And Tests (push) Successful in 2m12s
CI/CD Pipeline / Unit Tests (push) Successful in 2m27s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 3m32s
CI/CD Pipeline / Build Staging API Image (push) Successful in 8m11s
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Build Staging Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (push) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (push) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (push) Has been cancelled
54 lines
1.4 KiB
Python
Executable File
54 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""检查指定commit的CI status状态。
|
|
|
|
用法: python3 check_ci_status.py <token> <repo> <sha> <context>
|
|
返回: 打印状态 (success/failure/pending/error)
|
|
"""
|
|
|
|
import json
|
|
import sys
|
|
import urllib.error
|
|
import urllib.request
|
|
|
|
|
|
def main():
|
|
if len(sys.argv) != 5:
|
|
print("pending")
|
|
return
|
|
|
|
token = sys.argv[1]
|
|
repo = sys.argv[2]
|
|
sha = sys.argv[3]
|
|
target_context = sys.argv[4]
|
|
|
|
api_url = f"https://git.xiaoxiajianji.com/api/v1/repos/{repo}/commits/{sha}/statuses?per_page=100"
|
|
req = urllib.request.Request(api_url, headers={"Authorization": f"token {token}"})
|
|
|
|
try:
|
|
with urllib.request.urlopen(req, timeout=30) as resp:
|
|
statuses = json.loads(resp.read().decode())
|
|
except Exception:
|
|
print("pending")
|
|
return
|
|
|
|
# 筛选目标context,按时间倒序取最新的
|
|
matching = [s for s in statuses if s.get("context") == target_context]
|
|
if not matching:
|
|
# 找不到说明CI还没开始写状态,返回pending继续等待
|
|
print("pending")
|
|
return
|
|
|
|
# Gitea statuses API按时间正序返回,必须取最新的一条
|
|
latest = max(matching, key=lambda s: s.get("created_at", ""))
|
|
status = latest.get("status", "pending")
|
|
|
|
# skipped 视为通过(条件跳过的任务不需要等)
|
|
if status == "skipped":
|
|
print("success")
|
|
else:
|
|
print(status)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|