From af65d866a81dba37699e2a1fc021ba03374732fc Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 20 Aug 2025 14:50:10 +0000 Subject: [PATCH] Add GitHub API functionality to assign PRs back to creators when violations are found - Automatically assigns pull requests back to their creators after AI analysis determines violations of contributing guidelines - Uses GitHub API endpoint POST /repos/{owner}/{repo}/issues/{issue_number}/assignees - Only triggers when response.comment_needed is true (clear violations found) - Includes proper error handling that doesn't break webhook if assignment fails - Follows existing logging patterns for consistency - Preserves existing webhook processing and AI review workflow Co-Authored-By: Sahil Lavingia --- app/api/webhook/route.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/api/webhook/route.ts b/app/api/webhook/route.ts index 6fc4c85..298bcda 100644 --- a/app/api/webhook/route.ts +++ b/app/api/webhook/route.ts @@ -325,6 +325,29 @@ async function handlePullRequestOpened({ octokit, payload }: any) { ); log("INFO", `Comment posted successfully for PR`, { ...repoInfo, reasoning: response.reasoning }); + + try { + await octokit.request( + "POST /repos/{owner}/{repo}/issues/{issue_number}/assignees", + { + owner: owner, + repo: repo, + issue_number: prNumber, + assignees: [payload.pull_request.user.login], + } + ); + + log("INFO", `PR assigned back to creator for addressing violations`, { + ...repoInfo, + assignee: payload.pull_request.user.login + }); + } catch (assignmentError: any) { + log("ERROR", `Failed to assign PR back to creator`, { + error: assignmentError.message, + assignee: payload.pull_request.user.login, + ...repoInfo, + }); + } } else { log( "INFO",