|
88 | 88 | } |
89 | 89 | } |
90 | 90 |
|
91 | | - if (cliCoreFiles.length > 0 && !currentLabels.has('allow-cli-core-change')) { |
| 91 | + // A CODEOWNER's own PR is already maintainer-approved; owners come from the |
| 92 | + // base branch so the PR cannot add its author. Mirrors scripts/pr/change-policy.ts. |
| 93 | + let codeOwners = new Set() |
| 94 | + try { |
| 95 | + const { data } = await github.rest.repos.getContent({ owner, repo, path: '.github/CODEOWNERS', ref: context.payload.pull_request.base.ref }) |
| 96 | + const text = Buffer.from(data.content || '', 'base64').toString('utf8') |
| 97 | + codeOwners = new Set(text.split(/\r?\n/) |
| 98 | + .map((line) => line.replace(/#.*$/, '').trim()) |
| 99 | + .filter(Boolean) |
| 100 | + .flatMap((line) => line.split(/\s+/).slice(1)) |
| 101 | + .filter((token) => /^@[A-Za-z0-9-]+$/.test(token)) |
| 102 | + .map((token) => token.slice(1).toLowerCase())) |
| 103 | + } catch (error) { |
| 104 | + core.warning(`Could not read base CODEOWNERS: ${error.message}`) |
| 105 | + } |
| 106 | + const authorIsCodeOwner = codeOwners.has(String(context.payload.pull_request.user?.login || '').toLowerCase()) |
| 107 | + const cliCoreApproved = currentLabels.has('allow-cli-core-change') || authorIsCodeOwner |
| 108 | +
|
| 109 | + if (cliCoreFiles.length > 0 && !cliCoreApproved) { |
92 | 110 | areas.add('needs-maintainer-approval') |
93 | 111 | } |
94 | 112 |
|
@@ -221,9 +239,11 @@ jobs: |
221 | 239 |
|
222 | 240 | const marker = '<!-- pr-quality-triage -->' |
223 | 241 | const areaText = [...areas].filter((label) => label.startsWith('area:')).sort().join(', ') || 'none' |
224 | | - const approvalText = cliCoreFiles.length > 0 && !currentLabels.has('allow-cli-core-change') |
| 242 | + const approvalText = cliCoreFiles.length > 0 && !cliCoreApproved |
225 | 243 | ? 'Blocked by policy until a maintainer applies `allow-cli-core-change` and approves the PR.' |
226 | | - : 'No CLI-core policy block detected.' |
| 244 | + : cliCoreFiles.length > 0 && authorIsCodeOwner && !currentLabels.has('allow-cli-core-change') |
| 245 | + ? 'CLI-core change authored by a CODEOWNER; no override label needed.' |
| 246 | + : 'No CLI-core policy block detected.' |
227 | 247 | const missingTestText = missingTestSignals.length > 0 && !currentLabels.has('allow-missing-tests') |
228 | 248 | ? 'Blocked by policy until a maintainer applies `allow-missing-tests` or matching tests are added.' |
229 | 249 | : 'No missing-test policy block detected.' |
|
0 commit comments