@@ -1264,6 +1264,7 @@ async function githubWebhook(request, env, ctx) {
12641264 ingress,
12651265 } ) ;
12661266 if ( ! queued ) return json ( { error : "exact_review_queue_not_configured" } , 503 ) ;
1267+ await acknowledgePullRequestEnqueue ( { env, ctx, decision : exactReviewDecision } ) ;
12671268 if ( sourceAuthoritySeq !== null ) {
12681269 await completeExactReviewSourceAuthority (
12691270 env ,
@@ -2444,18 +2445,63 @@ async function enqueueExactReview({
24442445 return body ;
24452446}
24462447
2447- async function createFastAckComment ( { token, repo, itemNumber, sourceCommentId } ) {
2448- const existingId = await pruneFastAckComments ( { token, repo, itemNumber, sourceCommentId } ) ;
2448+ async function acknowledgePullRequestEnqueue ( { env, ctx, decision } ) {
2449+ if (
2450+ decision . itemKind !== "pull_request" ||
2451+ ! [ "opened" , "ready_for_review" ] . includes ( decision . sourceAction )
2452+ ) {
2453+ return null ;
2454+ }
2455+ const credentials = githubAppCredentials ( env ) ;
2456+ if ( ! credentials || ! Number . isInteger ( decision . installationId ) || decision . installationId <= 0 ) {
2457+ return null ;
2458+ }
2459+ const appJwt = await signGithubAppJwt ( credentials . issuer , credentials . privateKey ) ;
2460+ const token = await createGithubAppTokenFor ( {
2461+ appJwt,
2462+ installationId : decision . installationId ,
2463+ label : decision . targetRepo ,
2464+ repositories : [ repoName ( decision . targetRepo ) ] ,
2465+ permissions : { issues : "write" , pull_requests : "read" } ,
2466+ } ) ;
2467+ const ackMarker = pullRequestFastAckMarker ( decision . itemNumber , decision . sourceAction ) ;
2468+ const statusCommentId = await createFastAckCommentOnce ( {
2469+ token,
2470+ repo : decision . targetRepo ,
2471+ itemNumber : decision . itemNumber ,
2472+ ackMarker,
2473+ ackBody : renderPullRequestFastAckComment ( ackMarker ) ,
2474+ } ) ;
2475+ settleFastAckComments ( {
2476+ token,
2477+ repo : decision . targetRepo ,
2478+ itemNumber : decision . itemNumber ,
2479+ ackMarker,
2480+ delaysMs : fastAckSettleDelaysMs ( env . CLAWSWEEPER_FAST_ACK_SETTLE_DELAYS_MS ) ,
2481+ waitUntil : ctx ?. waitUntil ?. bind ( ctx ) ,
2482+ } ) ;
2483+ return statusCommentId ;
2484+ }
2485+
2486+ async function createFastAckComment ( {
2487+ token,
2488+ repo,
2489+ itemNumber,
2490+ sourceCommentId = undefined ,
2491+ ackMarker = fastAckMarker ( sourceCommentId ) ,
2492+ ackBody = renderFastAckComment ( sourceCommentId ) ,
2493+ } ) {
2494+ const existingId = await pruneFastAckComments ( { token, repo, itemNumber, ackMarker } ) ;
24492495 if ( existingId ) return existingId ;
24502496 const payload = await githubTokenJson ( {
24512497 token,
24522498 path : `/repos/${ repo } /issues/${ itemNumber } /comments` ,
24532499 method : "POST" ,
2454- body : { body : renderFastAckComment ( sourceCommentId ) } ,
2500+ body : { body : ackBody } ,
24552501 errorLabel : "ClawSweeper ack comment" ,
24562502 } ) ;
24572503 return (
2458- ( await pruneFastAckComments ( { token, repo, itemNumber, sourceCommentId } ) ) ||
2504+ ( await pruneFastAckComments ( { token, repo, itemNumber, ackMarker } ) ) ||
24592505 Number ( payload . id ) ||
24602506 null
24612507 ) ;
@@ -2465,14 +2511,15 @@ function settleFastAckComments({
24652511 token,
24662512 repo,
24672513 itemNumber,
2468- sourceCommentId,
2514+ sourceCommentId = undefined ,
2515+ ackMarker = fastAckMarker ( sourceCommentId ) ,
24692516 delaysMs = DEFAULT_FAST_ACK_SETTLE_DELAYS_MS ,
24702517 waitUntil,
24712518} ) {
24722519 const cleanup = async ( ) => {
24732520 for ( const delayMs of delaysMs ) {
24742521 await sleep ( delayMs ) ;
2475- await pruneFastAckComments ( { token, repo, itemNumber, sourceCommentId } ) ;
2522+ await pruneFastAckComments ( { token, repo, itemNumber, ackMarker } ) ;
24762523 }
24772524 } ;
24782525 const promise = cleanup ( ) . catch ( ( error ) => {
@@ -2489,19 +2536,26 @@ function fastAckSettleDelaysMs(value) {
24892536 return delays . length > 0 ? delays : DEFAULT_FAST_ACK_SETTLE_DELAYS_MS ;
24902537}
24912538
2492- async function createFastAckCommentOnce ( { token, repo, itemNumber, sourceCommentId } ) {
2493- const key = fastAckKey ( { repo, itemNumber, sourceCommentId } ) ;
2539+ async function createFastAckCommentOnce ( {
2540+ token,
2541+ repo,
2542+ itemNumber,
2543+ sourceCommentId = undefined ,
2544+ ackMarker = fastAckMarker ( sourceCommentId ) ,
2545+ ackBody = renderFastAckComment ( sourceCommentId ) ,
2546+ } ) {
2547+ const key = fastAckKey ( { repo, itemNumber, ackMarker } ) ;
24942548 const pending = inFlightFastAcks . get ( key ) ;
24952549 if ( pending ) return pending ;
2496- const next = createFastAckComment ( { token, repo, itemNumber, sourceCommentId } ) . finally ( ( ) => {
2550+ const next = createFastAckComment ( { token, repo, itemNumber, ackMarker , ackBody } ) . finally ( ( ) => {
24972551 inFlightFastAcks . delete ( key ) ;
24982552 } ) ;
24992553 inFlightFastAcks . set ( key , next ) ;
25002554 return next ;
25012555}
25022556
2503- function fastAckKey ( { repo, itemNumber, sourceCommentId } ) {
2504- return `${ String ( repo ) . toLowerCase ( ) } :${ itemNumber } :${ sourceCommentId } ` ;
2557+ function fastAckKey ( { repo, itemNumber, ackMarker } ) {
2558+ return `${ String ( repo ) . toLowerCase ( ) } :${ itemNumber } :${ ackMarker } ` ;
25052559}
25062560
25072561function sleep ( delayMs ) {
@@ -2511,8 +2565,14 @@ function sleep(delayMs) {
25112565 } ) ;
25122566}
25132567
2514- async function pruneFastAckComments ( { token, repo, itemNumber, sourceCommentId } ) {
2515- const comments = await listFastAckComments ( { token, repo, itemNumber, sourceCommentId } ) ;
2568+ async function pruneFastAckComments ( {
2569+ token,
2570+ repo,
2571+ itemNumber,
2572+ sourceCommentId = undefined ,
2573+ ackMarker = fastAckMarker ( sourceCommentId ) ,
2574+ } ) {
2575+ const comments = await listFastAckComments ( { token, repo, itemNumber, ackMarker } ) ;
25162576 if ( ! comments . length ) return null ;
25172577 const hasStatusComment = comments . some ( isStatusBearingFastAckComment ) ;
25182578 comments . sort ( compareFastAckKeepPriority ) ;
@@ -2569,9 +2629,8 @@ function compareCommentsByCreatedAt(left, right) {
25692629 ) ;
25702630}
25712631
2572- async function listFastAckComments ( { token, repo, itemNumber, sourceCommentId } ) {
2632+ async function listFastAckComments ( { token, repo, itemNumber, ackMarker } ) {
25732633 const comments = [ ] ;
2574- const marker = fastAckMarker ( sourceCommentId ) ;
25752634 const since = encodeURIComponent ( new Date ( Date . now ( ) - 24 * 60 * 60 * 1000 ) . toISOString ( ) ) ;
25762635 for ( let page = 1 ; page <= 5 ; page += 1 ) {
25772636 const payload = await githubTokenJson ( {
@@ -2584,7 +2643,7 @@ async function listFastAckComments({ token, repo, itemNumber, sourceCommentId })
25842643 if ( ! Array . isArray ( payload ) ) return comments ;
25852644 for ( const comment of payload ) {
25862645 if (
2587- String ( objectValue ( comment ) . body || "" ) . includes ( marker ) &&
2646+ String ( objectValue ( comment ) . body || "" ) . includes ( ackMarker ) &&
25882647 isClawsweeperGithubWebhookSender ( objectValue ( objectValue ( comment ) . user ) )
25892648 ) {
25902649 comments . push ( comment ) ;
@@ -2609,6 +2668,20 @@ function fastAckMarker(sourceCommentId) {
26092668 return `<!-- clawsweeper-command-ack:${ sourceCommentId } -->` ;
26102669}
26112670
2671+ function pullRequestFastAckMarker ( itemNumber , sourceAction ) {
2672+ return `<!-- clawsweeper-pr-ack:${ sourceAction } item=${ itemNumber } -->` ;
2673+ }
2674+
2675+ function renderPullRequestFastAckComment ( ackMarker ) {
2676+ return [
2677+ ackMarker ,
2678+ "🦞👀" ,
2679+ "ClawSweeper picked this up." ,
2680+ "" ,
2681+ "Pull request review queued. I will update this pull request when review starts." ,
2682+ ] . join ( "\n" ) ;
2683+ }
2684+
26122685async function addIssueCommentReaction ( { token, repo, commentId, content } ) {
26132686 await githubTokenJson ( {
26142687 token,
0 commit comments