Skip to content

Commit ef35196

Browse files
chore: add template file scripts/list-chromium-gl-repos.py [skip ci]
1 parent af3f6c4 commit ef35196

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

scripts/list-chromium-gl-repos.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env python3
2+
"""
3+
List all projects under openos-project/Chromium_Browser_OS_Deving.
4+
Falls back to trying the group by ID if path lookup fails.
5+
Also checks token identity and accessible groups.
6+
"""
7+
import os, json, urllib.request, urllib.error
8+
9+
token = os.environ["GITLAB_TOKEN"]
10+
api = os.environ.get("GL_API", "https://gitlab.com/api/v4")
11+
12+
def gl_get(path):
13+
req = urllib.request.Request(f"{api}{path}",
14+
headers={"PRIVATE-TOKEN": token, "User-Agent": "fork-sync-all"})
15+
try:
16+
with urllib.request.urlopen(req) as r:
17+
return json.load(r), r.status
18+
except urllib.error.HTTPError as e:
19+
return {"_error": e.code, "_body": e.read().decode()[:300]}, e.code
20+
21+
def fmt(b):
22+
if b >= 1073741824: return f"{b/1073741824:.1f}G"
23+
if b >= 1048576: return f"{b/1048576:.1f}M"
24+
if b >= 1024: return f"{b/1024:.1f}K"
25+
return f"{b}B"
26+
27+
# 1. Who is this token?
28+
print("=== Token identity ===")
29+
user, _ = gl_get("/user")
30+
if "_error" not in user:
31+
print(f" User: {user.get('username')} ({user.get('name')})")
32+
print(f" Scopes: check token settings")
33+
else:
34+
print(f" Error: {user}")
35+
36+
# 2. List top-level groups accessible to this token
37+
print("\n=== Accessible groups (top-level) ===")
38+
groups, _ = gl_get("/groups?per_page=50&top_level_only=true")
39+
if isinstance(groups, list):
40+
for g in groups:
41+
print(f" {g['full_path']} (id={g['id']})")
42+
else:
43+
print(f" Error: {groups}")
44+
45+
# 3. Try to access openos-project group
46+
print("\n=== openos-project subgroups ===")
47+
subs, _ = gl_get("/groups/openos-project/subgroups?per_page=50")
48+
if isinstance(subs, list):
49+
for g in subs:
50+
print(f" {g['full_path']} (id={g['id']})")
51+
else:
52+
print(f" Error: {subs}")
53+
54+
# 4. Try Chromium group by various path encodings
55+
print("\n=== Chromium group lookup attempts ===")
56+
for path in [
57+
"/groups/openos-project%2FChromium_Browser_OS_Deving",
58+
"/groups/openos-project%2Fchromium_browser_os_deving",
59+
"/groups?search=Chromium_Browser",
60+
]:
61+
data, status = gl_get(path)
62+
if isinstance(data, list):
63+
print(f" Search results for {path}:")
64+
for g in data[:5]:
65+
print(f" {g.get('full_path')} (id={g.get('id')})")
66+
elif "_error" not in data:
67+
print(f" Found: {data.get('full_path')} (id={data.get('id')})")
68+
else:
69+
print(f" {path}: HTTP {data['_error']}")

0 commit comments

Comments
 (0)