d6e47cb2cf
Auto Merge PRs (main) / Auto Merge on CI Green + Approved (main) (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 15s
Auto Approve CI PRs / Auto Approve on CI Green (pull_request) Successful in 18s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Successful in 1m49s
CI/CD Pipeline / Build & Push Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Build Production Runtime Images (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
#!/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
|
|
|
|
# API返回按时间倒序,第一个就是最新的
|
|
for s in statuses:
|
|
if s.get("context") == target_context:
|
|
status = s.get("status", "pending")
|
|
# skipped 视为通过(条件跳过的任务不需要等)
|
|
if status == "skipped":
|
|
print("success")
|
|
else:
|
|
print(status)
|
|
return
|
|
|
|
# 找不到这个context也视为通过(该workflow没触发=不需要检查)
|
|
print("success")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|