Skip to content

Commit eadb0e6

Browse files
authored
PR dashboard: fix missing workflow failure tracking issues section (#18472)
1 parent 787e9fc commit eadb0e6

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

.github/scripts/pull-request-dashboard.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import argparse
2222
import json
23+
import os
2324
import re
2425
import subprocess
2526
import sys
@@ -98,14 +99,16 @@
9899
# ---------------------------------------------------------------- gh helpers
99100

100101

101-
def gh_api(path: str, paginate: bool = False) -> Any:
102+
def gh_api(path: str, paginate: bool = False, token: str | None = None) -> Any:
102103
cmd = ["gh", "api", "-H", "Accept: application/vnd.github+json"]
103104
if paginate:
104105
cmd += ["--paginate", "--slurp"]
105106
cmd.append(path)
107+
env = {**os.environ, "GH_TOKEN": token} if token else None
106108
proc = subprocess.run(
107109
cmd, capture_output=True, text=True, check=False,
108110
encoding="utf-8", errors="replace",
111+
env=env,
109112
)
110113
if proc.returncode != 0:
111114
raise RuntimeError(f"gh api {path} failed: {proc.stderr.strip()}")
@@ -219,14 +222,22 @@ def detect_repo() -> str:
219222

220223

221224
def load_reviewer_set(org: str) -> set[str]:
225+
# Reading org team membership requires a token with org:read scope.
226+
# The default Actions GITHUB_TOKEN can't do this, so use OTELBOT_TOKEN
227+
# (a GitHub App installation token) when present; fall back to the
228+
# default GH_TOKEN otherwise (useful for local runs with a user token).
229+
token = os.environ.get("OTELBOT_TOKEN") or None
222230
reviewers: set[str] = set()
223231
for slug in APPROVER_TEAM_SLUGS:
224-
members = gh_api(f"/orgs/{org}/teams/{slug}/members?per_page=100", paginate=True)
232+
members = gh_api(
233+
f"/orgs/{org}/teams/{slug}/members?per_page=100",
234+
paginate=True, token=token,
235+
)
225236
reviewers.update(m["login"] for m in members)
226237
if not reviewers:
227238
raise RuntimeError(
228239
f"no reviewers found in teams {APPROVER_TEAM_SLUGS}; "
229-
f"the GH_TOKEN must have org:read permission"
240+
f"the token must have org:read permission"
230241
)
231242
return {r.lower() for r in reviewers}
232243

.github/workflows/pr-review-dashboard.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ jobs:
3232

3333
- name: Generate dashboard
3434
env:
35-
# Use the otelbot app token so the script can read approver/maintainer
36-
# team membership via /orgs/.../teams/.../members (the default
37-
# GITHUB_TOKEN cannot read org team membership).
38-
GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}
35+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
# needed for reading approver team membership (org:read)
37+
OTELBOT_TOKEN: ${{ steps.otelbot-token.outputs.token }}
3938
COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }}
4039
run: |
4140
python3 .github/scripts/pull-request-dashboard.py \

0 commit comments

Comments
 (0)