|
| 1 | +import { Probot } from "probot"; |
| 2 | + |
| 3 | +import { |
| 4 | + findRunningSessionForPR, |
| 5 | + getDevinSessionDetail, |
| 6 | + isDevinSessionWorking, |
| 7 | +} from "../devin/index.js"; |
| 8 | +import { createOrUpdateCheck, ProbotContext } from "../lib/github-checks.js"; |
| 9 | + |
| 10 | +const CHECK_NAME = "Devin"; |
| 11 | + |
| 12 | +export function registerDevinStatusHandler(app: Probot): void { |
| 13 | + app.on( |
| 14 | + [ |
| 15 | + "pull_request.opened", |
| 16 | + "pull_request.synchronize", |
| 17 | + "pull_request.reopened", |
| 18 | + ], |
| 19 | + async (context) => { |
| 20 | + const pr = context.payload.pull_request; |
| 21 | + const owner = context.payload.repository.owner.login; |
| 22 | + const repo = context.payload.repository.name; |
| 23 | + const headSha = pr.head.sha; |
| 24 | + const prUrl = pr.html_url; |
| 25 | + |
| 26 | + context.log.info( |
| 27 | + `[Devin] PR ${context.payload.action} for ${owner}/${repo}#${pr.number}`, |
| 28 | + ); |
| 29 | + |
| 30 | + try { |
| 31 | + await checkDevinSession(context, owner, repo, headSha, prUrl); |
| 32 | + } catch (error) { |
| 33 | + context.log.error(`[Devin] Failed to check Devin session: ${error}`); |
| 34 | + } |
| 35 | + }, |
| 36 | + ); |
| 37 | +} |
| 38 | + |
| 39 | +async function checkDevinSession( |
| 40 | + context: ProbotContext, |
| 41 | + owner: string, |
| 42 | + repo: string, |
| 43 | + headSha: string, |
| 44 | + prUrl: string, |
| 45 | +): Promise<void> { |
| 46 | + const session = await findRunningSessionForPR(prUrl); |
| 47 | + if (!session) { |
| 48 | + return; |
| 49 | + } |
| 50 | + |
| 51 | + const detail = await getDevinSessionDetail(session.session_id); |
| 52 | + if (!isDevinSessionWorking(detail)) { |
| 53 | + return; |
| 54 | + } |
| 55 | + |
| 56 | + await createOrUpdateCheck(context, { |
| 57 | + owner, |
| 58 | + repo, |
| 59 | + name: CHECK_NAME, |
| 60 | + head_sha: headSha, |
| 61 | + status: "in_progress", |
| 62 | + output: { |
| 63 | + title: "Devin is working", |
| 64 | + summary: `Devin session ${session.session_id} is currently working on this PR.`, |
| 65 | + }, |
| 66 | + }); |
| 67 | +} |
0 commit comments