@@ -3,6 +3,7 @@ import { JSDOM } from "jsdom";
33import fs , { readFile } from "fs/promises" ;
44import path from "path" ;
55import { fileURLToPath } from "url" ;
6+ import { execSync , spawnSync } from "child_process" ;
67
78const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
89
@@ -11,6 +12,7 @@ const OPENROUTER_API_KEY = process.env.OPENROUTER_API_KEY;
1112const REPO_OWNER = process . env . GITHUB_REPOSITORY_OWNER || "owner" ;
1213const REPO_NAME = process . env . GITHUB_REPOSITORY ?. split ( "/" ) [ 1 ] || "cppdoc" ;
1314const LABEL = "migrate-cppref-page" ;
15+ const MODEL_NAME = "google/gemini-2.5-flash" ;
1416
1517if ( ! GITHUB_TOKEN ) {
1618 console . error ( "Missing GITHUB_TOKEN" ) ;
@@ -91,7 +93,7 @@ async function convertToMDX(html: string, title: string, url: string): Promise<s
9193 "X-Title" : "CppDoc Migration Bot" ,
9294 } ,
9395 body : JSON . stringify ( {
94- model : "google/gemini-2.5-flash" ,
96+ model : MODEL_NAME ,
9597 messages : [
9698 { role : "system" , content : prompt } ,
9799 {
@@ -227,9 +229,9 @@ async function createPullRequest(issue: { number: number; title: string }, fileP
227229 const pageName = page ? page . replace ( ".html" , "" ) : "unknown" ;
228230 const prTitle = `feat: migrate ${ pageName } from cppref [#${ issue . number } ]` ;
229231 const commitMessage = prTitle ;
230- const prBody = `自动迁移自 ${ url }
231-
232- [编辑 ${ getRelativePath ( url ) } ](https://github.com/cppdoc-cc/cppdoc/edit/ ${ branchName } / ${ getRelativePath ( url ) } )
232+ const prBody = `> 由 ${ MODEL_NAME } 自 ${ url } 自动迁移
233+ >
234+ > 📝 [编辑此页面]( ${ getRelativePath ( url ) } )
233235
234236<small>Close #${ issue . number } </small>
235237` ;
@@ -329,6 +331,12 @@ async function main() {
329331 console . log ( ` 写入 ${ filePath } ` ) ;
330332 await writeMDXFile ( filePath , mdx , title ) ;
331333
334+ console . log ( ` 尝试构建...` ) ;
335+ const res = spawnSync ( `npm run build` , { stdio : "inherit" } ) ;
336+ if ( res . status !== 0 ) {
337+ throw new Error ( "构建失败,可能生成的MDX有问题:" + res . stderr ?. toString ( ) ) ;
338+ }
339+
332340 console . log ( ` 创建PR...` ) ;
333341 const prNumber = await createPullRequest ( issue , filePath , url ) ;
334342
0 commit comments