Dough Git

commit

AAAAAAAAAA

commit
a555aca61dfcf7415ee03996660378cb20a93fbf
author
Clove Twilight <[email protected]>
date
2026-11-16 17:58

diff --git a/README.md b/README.md
index b2c759c..2785c00 100644
--- a/README.md
+++ b/README.md
@@ -54,6 +54,9 @@ done, and nothing is sent to GitHub.
 
 Edit `config/messages.json`. Changes apply on the next action, with no restart.
 
+Once a contributor fixes a change request, the next scan dismisses that review with the rule's
+`reviewDismissal` wording and marks the finding resolved.
+
 ## Unsupported CNAME targets
 
 List hosts in `config/unsupportedCnames.json` as a JSON array, for example
@@ -92,7 +95,8 @@ the other open violations on the same PR.
 1. Add a module in `src/lib/server/rules/` that exports a `Rule`.
 2. Register it in `src/lib/server/rules/index.ts`.
 3. Give it a `severity` from 1 (low) to 3 (high).
-4. A `requestChanges` rule needs a `findLine` and wording in `config/messages.json`.
+4. A `requestChanges` rule needs a `findLine` and wording in `config/messages.json`
+   (`reviewComment`, `reviewSummary` and `reviewDismissal`).
 5. If it needs a new kind of action, add an executor in `src/lib/server/moderation/executors.ts`.
 
 ## Checks
diff --git a/config/messages.json b/config/messages.json
index 733c178..0666215 100644
--- a/config/messages.json
+++ b/config/messages.json
@@ -4,10 +4,12 @@
 	},
 	"unsupportedCname": {
 		"reviewComment": "Your `CNAME` record points at a host that we do not support. Please point it at a supported host, or use another record type such as `A` or `AAAA`.\n\nIf you have requested a CloudFlare Worker, please use a legacy CloudFlare Pages project.",
+		"reviewDismissal": "Thanks, the `CNAME` record is fixed. Dismissing the requested changes.",
 		"reviewSummary": "Please see the inline comment on `CNAME`.\n<sub>This comment was sent with an [automated tool](https://doughmination.gay/automated), and approved by a human. I do not see replies.</sub>"
 	},
 	"noReplyEmail": {
 		"reviewComment": "Your `owner.email` value is a GitHub no-reply email address. We do not allow these on our service. Please update it to a personal email address or remove the `owner.email` field entirely, as it is optional.",
+		"reviewDismissal": "Thanks, `owner.email` is fixed. Dismissing the requested changes.",
 		"reviewSummary": "Please see the inline comment on `owner.email`.\n<sub>This comment was sent with an [automated tool](https://doughmination.gay/automated), and approved by a human. I do not see replies.</sub>"
 	}
 }
diff --git a/src/lib/server/github/client.ts b/src/lib/server/github/client.ts
index 29c1a47..928fca6 100644
--- a/src/lib/server/github/client.ts
+++ b/src/lib/server/github/client.ts
@@ -39,7 +39,7 @@ const rateBuckets = new Map<string, RateBucket>();
 let blockedUntil = 0;
 
 export interface GitHubRequest {
-	method?: 'GET' | 'POST' | 'PATCH';
+	method?: 'GET' | 'POST' | 'PATCH' | 'PUT';
 	path: string;
 	query?: Record<string, string | number>;
 	body?: unknown;
diff --git a/src/lib/server/github/pullRequests.ts b/src/lib/server/github/pullRequests.ts
index ed7e5af..a9bb2e8 100644
--- a/src/lib/server/github/pullRequests.ts
+++ b/src/lib/server/github/pullRequests.ts
@@ -213,6 +213,22 @@ export async function listReviews(number: number): Promise<ApiReview[]> {
 	return response.data;
 }
 
+export async function dismissReview(
+	number: number,
+	reviewId: number,
+	message: string
+): Promise<void> {
+	await githubRequest({
+		method: 'PUT',
+		path: `${getRepoPath()}/pulls/${number}/reviews/${reviewId}/dismissals`,
+		body: {
+			message,
+			event: 'DISMISS'
+		},
+		priority: true
+	});
+}
+
 export async function createChangesRequestedReview(options: {
 	number: number;
 	commitId: string;
diff --git a/src/lib/server/moderation/executors.ts b/src/lib/server/moderation/executors.ts
index 75e8dc0..2d35c7c 100644
--- a/src/lib/server/moderation/executors.ts
+++ b/src/lib/server/moderation/executors.ts
@@ -2,19 +2,23 @@
  * MIT — (c) Doughmination System®
  */
 
-import { setFindingComment } from '../db/findings.ts';
+import { getConfig } from '../config.ts';
+import { listFindingsForPullRequest, setFindingComment, setFindingStatus } from '../db/findings.ts';
 import { markPullRequestClosed } from '../db/pullRequests.ts';
+import { emitFindingEvent } from '../events.ts';
 import { getCommentableLines } from '../github/diff.ts';
 import { GitHubError } from '../github/client.ts';
 import {
 	closePullRequest,
 	createChangesRequestedReview,
 	createIssueComment,
+	dismissReview,
 	getAuthenticatedLogin,
 	listReviews
 } from '../github/pullRequests.ts';
 import { getMessages } from '../messages.ts';
 import { getRule } from '../rules/index.ts';
+import type { Violation } from '../rules/types.ts';
 import type { ActionOutcome, ActionType, FindingRow, PullRequestSummary } from '../types.ts';
 import type { Evaluation } from './evaluate.ts';
 import { retireFindings } from './reconcile.ts';
@@ -140,6 +144,51 @@ async function requestRuleChanges(input: ExecutorInput): Promise<ActionOutcome>
 	};
 }
 
+// Dismisses our change requests once the latest commit no longer has the violation
+export async function dismissFixedChangeRequests(
+	pullRequest: PullRequestSummary,
+	violations: Violation[]
+): Promise<void> {
+	const fixed = listFindingsForPullRequest(pullRequest.number).filter(
+		(finding) =>
+			finding.status === 'actioned' &&
+			getRule(finding.ruleId).actionType === 'requestChanges' &&
+			!violations.some(
+				(violation) =>
+					violation.ruleId === finding.ruleId && violation.filePath === finding.filePath
+			)
+	);
+
+	if (fixed.length === 0 || getConfig().dryRun) {
+		return;
+	}
+
+	const login = await getAuthenticatedLogin();
+	const reviews = await listReviews(pullRequest.number);
+
+	for (const finding of fixed) {
+		const marker = reviewMarker(finding);
+
+		const openReviews = reviews.filter(
+			(review) =>
+				review.user?.login === login &&
+				review.state === 'CHANGES_REQUESTED' &&
+				(review.body ?? '').includes(marker)
+		);
+
+		for (const review of openReviews) {
+			await dismissReview(pullRequest.number, review.id, reviewMessages(finding).reviewDismissal);
+		}
+
+		setFindingStatus(
+			finding.id,
+			'resolved',
+			'The contributor fixed this; the requested changes were dismissed.'
+		);
+		emitFindingEvent('findingChanged', finding.id);
+	}
+}
+
 export const executors: Record<Exclude<ActionType, 'ignore'>, Executor> = {
 	closePr: closeWithPolicyComment,
 	requestChanges: requestRuleChanges
diff --git a/src/lib/server/moderation/pipeline.test.ts b/src/lib/server/moderation/pipeline.test.ts
index 14cd488..aa06441 100644
--- a/src/lib/server/moderation/pipeline.test.ts
+++ b/src/lib/server/moderation/pipeline.test.ts
@@ -32,6 +32,7 @@ interface RecordedWrite {
 	body: {
 		state?: string;
 		event?: string;
+		body?: string;
 		commit_id?: string;
 		comments?: {
 			path: string;
@@ -156,7 +157,22 @@ async function fakeGitHub(input: string | URL | Request, init?: RequestInit): Pr
 	}
 
 	if (pullRequest && path.endsWith('/reviews')) {
-		return jsonResponse([]);
+		const reviews = writes
+			.map((write, index) => ({
+				write,
+				id: index + 1
+			}))
+			.filter(({ write }) => write.method === 'POST' && write.path === path)
+			.map(({ write, id }) => ({
+				id,
+				state: 'CHANGES_REQUESTED',
+				body: write.body.body ?? null,
+				commit_id: write.body.commit_id,
+				html_url: `https://github.com/fake/${id}`,
+				user: { login: 'moderator' }
+			}));
+
+		return jsonResponse(reviews);
 	}
 
 	if (pullRequest) {
@@ -301,6 +317,27 @@ describe('moderation pipeline', () => {
 		assert.equal(fakePullRequests.get(2)?.state, 'open');
 	});
 
+	test('fixing a change request dismisses the review once', async () => {
+		const pullRequest = fakePullRequests.get(2)!;
+
+		pullRequest.sha = 'sha-two-fixed';
+		pullRequest.updatedAt = '2026-11-01T12:00:00Z';
+		pullRequest.json = {
+			owner: { username: 'hidden' },
+			records: { CNAME: 'hidden.github.io' }
+		};
+
+		await scanOnce();
+		await scanOnce();
+
+		const dismissals = writes.filter((write) => write.method === 'PUT');
+
+		assert.equal(dismissals.length, 1);
+		assert.equal(dismissals[0].path, '/pulls/2/reviews/3/dismissals');
+		assert.equal(dismissals[0].body.event, 'DISMISS');
+		assert.equal(findingFor(2).status, 'resolved');
+	});
+
 	test('a fix pushed by the contributor resolves the finding', async () => {
 		const pullRequest = fakePullRequests.get(4)!;
 
diff --git a/src/lib/server/moderation/scanner.ts b/src/lib/server/moderation/scanner.ts
index ddffcf9..8c0db3d 100644
--- a/src/lib/server/moderation/scanner.ts
+++ b/src/lib/server/moderation/scanner.ts
@@ -14,6 +14,7 @@ import { listPullRequests } from '../github/pullRequests.ts';
 import { createLogger, describeError } from '../logger.ts';
 import type { PullRequestSummary } from '../types.ts';
 import { evaluatePullRequest } from './evaluate.ts';
+import { dismissFixedChangeRequests } from './executors.ts';
 import { reconcileFindings, retireFindings } from './reconcile.ts';
 
 const logger = createLogger('scanner');
@@ -100,6 +101,7 @@ async function processPullRequest(pullRequest: PullRequestSummary): Promise<void
 		priority: false
 	});
 
+	await dismissFixedChangeRequests(pullRequest, evaluation.violations);
 	reconcileFindings(pullRequest, evaluation.violations);
 	markPullRequestScanned(pullRequest.number, pullRequest.headSha);