Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions tools/ai-docs-sync/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ at startup, so child processes never inherit them.
9. `report`: logs the result, and ends the run (moving the cursor) when nothing survived.
10. `publish`: renders the commit message, PR title and PR body, pushes the rolling branch,
opens or updates the PR, requests `reviewers` (users and teams in separate calls, so the
Actions token, which cannot see teams, still requests the users; a failed request logs a
warning and the run carries on), sets the commit status and moves the cursor.
Actions token, which cannot see teams, still requests the users; the PR author, who is the
`DOCS_SYNC_TOKEN` user when one is set, is left out since GitHub refuses that request; a failed
request logs a warning and the run carries on), sets the commit status and moves the cursor.

Every affected doc is written; there is no per-run cap.

Expand Down
2 changes: 1 addition & 1 deletion tools/ai-docs-sync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ At `.github/docs-sync.yml`, read from the **target branch**. Only `doc_paths` is
| `label` | Label on the rolling PR. Default `docs-sync`. |
| `format_check` | `off` (default) or `strict`, which runs your prettier and needs `setup_command`. |
| `setup_command` | Shell run before prettier, e.g. `corepack enable && pnpm install --frozen-lockfile`. |
| `reviewers` | Users (`@login`) and teams (`@org/team`, same org as the repo) asked to review the rolling PR each time it is opened or updated. Default none. |
| `reviewers` | Users (`@login`) and teams (`@org/team`, same org as the repo) asked to review the rolling PR each time it is opened or updated. The PR author is skipped. Default none. |

```yaml
doc_paths:
Expand Down
7 changes: 7 additions & 0 deletions tools/ai-docs-sync/src/publish.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ export function commitMessage({ scope, from, to, target, files, deleted = [], ca
return lines.join('\n') + '\n';
}

// GitHub refuses (422) a review request naming the PR author, failing the whole call. With a
// personal DOCS_SYNC_TOKEN the author is that token's user, who may also be a configured reviewer.
export function reviewRequestFor(reviewRequest, author) {
const a = String(author ?? '').toLowerCase();
return { ...reviewRequest, reviewers: (reviewRequest.reviewers ?? []).filter((r) => r.toLowerCase() !== a) };
}

export const prTitle = ({ scope, target, to }) => `docs(${scope}): sync docs with ${target} (up to ${short7(to)})`;
const MARKER_RE = /<!-- ai-docs-sync (\{[\s\S]*?\}) -->/;

Expand Down
8 changes: 5 additions & 3 deletions tools/ai-docs-sync/src/stages/publish.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { BOT_EMAIL, BOT_NAME } from '../git.mjs';
import { unifiedDiff } from '../linediff.mjs';
import { narrativeOutline } from '../narrative.mjs';
import { renderPrBody } from '../pr-body.mjs';
import { commitMessage, commitScope, lastRunFor, prTitle, regenerateFrom } from '../publish.mjs';
import { commitMessage, commitScope, lastRunFor, prTitle, regenerateFrom, reviewRequestFor } from '../publish.mjs';

export async function publish(ctx) {
const { DRY_RUN, REPO, RUN_URL, TARGET_BRANCH, capped, carried, carryBase, cfg, commits, count, decisions, delPlan, dropped, findOpenPr, from, gh, ghCommit, git, head, heldBack, isNewDoc, kept, keptDeletes, keptPaths, linked, log, moveCursor, openPr, packed, prevRuns, prs, pushUrl, pushWithToken, remoteSha, reviewer, reviewerRemoved, staleCarried, tombstones, treeEntry, usage, warn } = ctx;
Expand Down Expand Up @@ -142,8 +142,10 @@ export async function publish(ctx) {
}
}
// On every publish, so a reviewer who already reviewed is asked again. One call per field: a
// token that cannot see org teams then still requests the users.
for (const [field, names] of Object.entries(cfg.reviewRequest)) {
// token that cannot see org teams then still requests the users. The PR author is left out.
const author = pr.user?.login;
if (author && cfg.reviewRequest.reviewers.some((r) => r.toLowerCase() === author.toLowerCase())) log(`Not requesting ${author}: they authored the PR`);
for (const [field, names] of Object.entries(reviewRequestFor(cfg.reviewRequest, author))) {
if (!names.length) continue;
try {
await gh(`/repos/${REPO}/pulls/${pr.number}/requested_reviewers`, { method: 'POST', body: { [field]: names } });
Expand Down
9 changes: 8 additions & 1 deletion tools/ai-docs-sync/test/publish.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { MARKER_MAX_CHARS, PR_BODY_MAX } from '../src/config.mjs';
import { BOT_EMAIL, gitAuthEnv } from '../src/git.mjs';
import { narrativeOutline } from '../src/narrative.mjs';
import { blobUrl, renderPrBody } from '../src/pr-body.mjs';
import { commitMessage, commitScope, lastRunFor, parseMarker, prTitle, regenerateFrom, renderMarker } from '../src/publish.mjs';
import { commitMessage, commitScope, lastRunFor, parseMarker, prTitle, regenerateFrom, renderMarker, reviewRequestFor } from '../src/publish.mjs';

describe('publishing helpers', () => {
test('commit scope, subject and body follow the fixed template', () => {
Expand All @@ -21,6 +21,13 @@ describe('publishing helpers', () => {
assert.equal(prTitle({ scope: 'web', target: 'develop', to: 'c'.repeat(40) }), 'docs(web): sync docs with develop (up to ccccccc)');
});

test('the review request leaves out the PR author, case-insensitively', () => {
const req = { reviewers: ['alice', 'JulesFiliot'], team_reviewers: ['web'] };
assert.deepEqual(reviewRequestFor(req, 'julesfiliot'), { reviewers: ['alice'], team_reviewers: ['web'] });
assert.deepEqual(reviewRequestFor(req, 'github-actions[bot]'), req);
assert.deepEqual(reviewRequestFor(req, undefined), req);
});

test('the push credential is an env-only extraheader that disables stored credentials', () => {
const env = gitAuthEnv('tok');
assert.equal(env.GIT_CONFIG_KEY_0, 'http.https://github.com/.extraheader');
Expand Down
Loading