Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions src/github/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
import * as core from '@actions/core';
import { toErrorMessage } from '../utils/error.js';
import { parseFlags } from '../utils/flags.js';
import { ParseError } from '../utils/errors.js';
import { promises as fs } from 'fs';
import { getEventType, extractText } from './github.js';
Expand Down Expand Up @@ -75,16 +76,13 @@ export async function processEvent(
): Promise<ProcessedEvent | null> {
if (config.directPrompt) {
let prompt = config.directPrompt;
let includeFixBuild = false;
let includeFetch = false;
if (prompt.split(/\s+/).includes('--fix-build')) {
includeFixBuild = true;
prompt = prompt.replace(/--fix-build\b/, '').trim();
}
if (prompt.split(/\s+/).includes('--fetch')) {
includeFetch = true;
prompt = prompt.replace(/--fetch\b/, '').trim();
}
const { flags: directFlags, rest: promptRest } = parseFlags(
prompt,
['fix-build', 'fetch'],
);
const includeFixBuild = directFlags['fix-build'];
const includeFetch = directFlags['fetch'];
prompt = promptRest;
core.info('Direct prompt provided. Bypassing GitHub event trigger.');
return {
type: 'codex',
Expand Down Expand Up @@ -145,18 +143,19 @@ export async function processEvent(
}

let args = text.replace(trigger, '').trim();
const includeFullHistory = args.split(/\s+/).includes('--full-history');
args = args.replace(/--full-history\b/, '').trim();
const createIssues = args.split(/\s+/).includes('--create-issues');
args = args.replace(/--create-issues\b/, '').trim();
const noPr = args.split(/\s+/).includes('--no-pr');
args = args.replace(/--no-pr\b/, '').trim();
// --fix-build: fetch latest failed CI build logs and include as context
const includeFixBuild = args.split(/\s+/).includes('--fix-build');
args = args.replace(/--fix-build\b/, '').trim();
const includeFetch = args.split(/\s+/).includes('--fetch');
args = args.replace(/--fetch\b/, '').trim();
let userPrompt = args;
const { flags, rest: promptRest } = parseFlags(args, [
'full-history',
'create-issues',
'no-pr',
'fix-build',
'fetch',
]);
const includeFullHistory = flags['full-history'];
const createIssues = flags['create-issues'];
const noPr = flags['no-pr'];
const includeFixBuild = flags['fix-build'];
const includeFetch = flags['fetch'];
let userPrompt = promptRest;

let title: string | undefined;
if ('issue' in agentEvent.github) {
Expand Down
40 changes: 40 additions & 0 deletions src/utils/flags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export interface ParsedFlags {
/**
* Map of flag names to boolean indicating presence.
*/
flags: Record<string, boolean>;
/**
* Remaining input string after removing flags.
*/
rest: string;
}

/**
* Parses the input string for boolean flags and returns the remaining content.
*
* @param input - The input string containing flags and content.
* @param flagNames - Array of flag names (without leading dashes) to parse.
* @returns An object with flags map and remaining content string.
*/
export function parseFlags(
input: string,
flagNames: string[],
): ParsedFlags {
const tokens = input.split(/\s+/).filter(Boolean);
const flags: Record<string, boolean> = {};
flagNames.forEach((name) => {
flags[name] = false;
});
const restTokens: string[] = [];
for (const token of tokens) {
if (token.startsWith('--')) {
const name = token.slice(2);
if (flagNames.includes(name)) {
flags[name] = true;
continue;
}
}
restTokens.push(token);
}
return { flags, rest: restTokens.join(' ') };
}