@@ -18,7 +18,7 @@ import { resolveRuntimeHost } from "./host.js";
1818import { prettifyMarkdown } from "./pretty.js" ;
1919import { arrayify } from "./cleaners.js" ;
2020import { assert } from "./assert.js" ;
21- import { logError , logVerbose } from "./util.js" ;
21+ import { logError , logVerbose , logWarn } from "./util.js" ;
2222import { shellRemoveAsciiColors } from "./shell.js" ;
2323import { isGlobMatch } from "./glob.js" ;
2424import { concurrentLimit } from "./concurrency.js" ;
@@ -507,6 +507,66 @@ export async function githubCreateIssueComment(
507507 return r ;
508508}
509509
510+ // Function to generate a title for a GitHub issue
511+ async function generateIssueTitle (
512+ script : PromptScript ,
513+ body : string ,
514+ ) : Promise < string > {
515+ // For now, create a simple title based on the script and first line of body
516+ const firstLine = body . split ( '\n' ) [ 0 ] ?. trim ( ) ;
517+ const shortContent = firstLine ? firstLine . substring ( 0 , 60 ) : '' ;
518+
519+ if ( shortContent ) {
520+ return `${ script . id } : ${ shortContent } ` ;
521+ }
522+
523+ return `Generated by ${ script . id } ` ;
524+ }
525+
526+ // https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#create-an-issue
527+ export async function githubCreateIssue (
528+ script : PromptScript ,
529+ info : GithubConnectionInfo ,
530+ title : string ,
531+ body : string ,
532+ options ?: CancellationOptions & { stats ?: GenerationStats } ,
533+ ) : Promise < { created : boolean ; statusText : string ; html_url ?: string ; issue_number ?: number } > {
534+ const { cancellationToken, stats } = options ?? { } ;
535+ const { repository, token } = info ;
536+
537+ if ( ! repository ) {
538+ dbg ( `missing repository, cannot create issue` ) ;
539+ return { created : false , statusText : "missing repository" } ;
540+ }
541+ if ( ! token ) {
542+ dbg ( `missing github token, cannot create issue` ) ;
543+ return { created : false , statusText : "missing github token" } ;
544+ }
545+
546+ try {
547+ // Create the GitHub client and create the issue
548+ const client = new GitHubClient ( info ) ;
549+ const issue = await client . createIssue ( title , prettifyMarkdown ( dedent ( body ) ) ) ;
550+
551+ const r = {
552+ created : true ,
553+ statusText : "Created" ,
554+ html_url : issue . html_url ,
555+ issue_number : issue . number ,
556+ } ;
557+
558+ logVerbose ( `GitHub issue created at ${ r . html_url } ` ) ;
559+ return r ;
560+ } catch ( error ) {
561+ const errorMsg = errorMessage ( error ) ;
562+ logError ( `GitHub issue creation failed: ${ errorMsg } ` ) ;
563+ return {
564+ created : false ,
565+ statusText : errorMsg ,
566+ } ;
567+ }
568+ }
569+
510570async function githubCreatePullRequestReview (
511571 script : PromptScript ,
512572 info : Pick <
0 commit comments