-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #337 from giselles-ai/fix-github-webhook-command-p…
…arsing Fix GitHub command parsing with robust line ending
- Loading branch information
Showing
2 changed files
with
65 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,29 @@ | ||
export interface Command { | ||
callSign: string; | ||
instruction: string; | ||
content: string; | ||
} | ||
|
||
export function parseCommand(text: string) { | ||
const lines = text.trim().split("\r\n"); | ||
export function parseCommand(text: string): Command | null { | ||
// Normalize line breaks and split into lines | ||
const normalizedText = text.replace(/\r\n|\r|\n/g, "\n"); | ||
const lines = normalizedText.trim().split("\n"); | ||
|
||
const commandLine = lines[0]; | ||
const commandMatch = commandLine.match(/^\/giselle\s+([^\]]+)/); | ||
const commandMatch = commandLine.match(/^\/giselle\s+([^\n]+)/); | ||
if (!commandMatch) { | ||
return null; | ||
} | ||
|
||
// Extract callSign (first word) and remaining content | ||
const parts = commandMatch[1].trim().split(/\s+/); | ||
const callSign = parts[0]; | ||
const firstLineContent = parts.slice(1).join(" "); | ||
|
||
// Combine remaining content | ||
const content = [firstLineContent, ...lines.slice(1)].join("\n").trim(); | ||
|
||
return { | ||
callSign: commandMatch[1], | ||
content: lines.slice(1).join("\n").trim(), | ||
callSign, | ||
content, | ||
}; | ||
} |