mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 11:11:53 +00:00
refactor: Address code review feedback
- Extract duplicate label checking into addUniqueLabel helper - Improve comments explaining trigger filtering logic - Clarify which triggers are shown in Quick Reference vs detailed sections Co-authored-by: snomiao <7323030+snomiao@users.noreply.github.com>
This commit is contained in:
@@ -41,6 +41,15 @@ const PREFIX_DESCRIPTIONS: Record<string, string> = {
|
|||||||
'version-': 'Version management'
|
'version-': 'Version management'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a label to the list if it's not already present
|
||||||
|
*/
|
||||||
|
function addUniqueLabel(labels: string[], label: string): void {
|
||||||
|
if (!labels.includes(label)) {
|
||||||
|
labels.push(label)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract label triggers from workflow content
|
* Extract label triggers from workflow content
|
||||||
*/
|
*/
|
||||||
@@ -58,9 +67,7 @@ function extractLabelTriggers(content: string, workflowData: any): string[] {
|
|||||||
/github\.event\.label\.name\s*==\s*['"]([^'"]+)['"]/gi
|
/github\.event\.label\.name\s*==\s*['"]([^'"]+)['"]/gi
|
||||||
)
|
)
|
||||||
for (const match of labelNameMatches) {
|
for (const match of labelNameMatches) {
|
||||||
if (!labels.includes(match[1])) {
|
addUniqueLabel(labels, match[1])
|
||||||
labels.push(match[1])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for contains(github.event.pull_request.labels.*.name, 'label-name') pattern
|
// Check for contains(github.event.pull_request.labels.*.name, 'label-name') pattern
|
||||||
@@ -68,19 +75,18 @@ function extractLabelTriggers(content: string, workflowData: any): string[] {
|
|||||||
/contains\(github\.event\.pull_request\.labels\.\*\.name,\s*['"]([^'"]+)['"]\)/gi
|
/contains\(github\.event\.pull_request\.labels\.\*\.name,\s*['"]([^'"]+)['"]\)/gi
|
||||||
)
|
)
|
||||||
for (const match of containsLabelMatches) {
|
for (const match of containsLabelMatches) {
|
||||||
if (!labels.includes(match[1])) {
|
addUniqueLabel(labels, match[1])
|
||||||
labels.push(match[1])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for startsWith or contains patterns with label names
|
// Check for startsWith patterns with comment commands (e.g., /update-playwright)
|
||||||
|
// These are included as they can trigger workflows through PR comments
|
||||||
const labelCommentMatches = content.matchAll(
|
const labelCommentMatches = content.matchAll(
|
||||||
/startsWith\(github\.event\.comment\.body,\s*['"]([^'"]+)['"]\)/gi
|
/startsWith\(github\.event\.comment\.body,\s*['"]([^'"]+)['"]\)/gi
|
||||||
)
|
)
|
||||||
for (const match of labelCommentMatches) {
|
for (const match of labelCommentMatches) {
|
||||||
const command = match[1]
|
const command = match[1]
|
||||||
if (command && !labels.includes(command)) {
|
if (command) {
|
||||||
labels.push(command)
|
addUniqueLabel(labels, command)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,7 +321,8 @@ function generateQuickReference(grouped: WorkflowsByPrefix): string {
|
|||||||
const labelMap = new Map<string, string[]>()
|
const labelMap = new Map<string, string[]>()
|
||||||
for (const workflow of labelWorkflows) {
|
for (const workflow of labelWorkflows) {
|
||||||
for (const label of workflow.labelTriggers) {
|
for (const label of workflow.labelTriggers) {
|
||||||
// Skip comment-based triggers (like /update-playwright)
|
// Filter out comment-based triggers (commands starting with /) from Quick Reference
|
||||||
|
// These are still shown in detailed workflow sections with full context
|
||||||
if (label.startsWith('/')) {
|
if (label.startsWith('/')) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -335,7 +342,7 @@ function generateQuickReference(grouped: WorkflowsByPrefix): string {
|
|||||||
const sortedLabels = Array.from(labelMap.keys()).sort()
|
const sortedLabels = Array.from(labelMap.keys()).sort()
|
||||||
for (const label of sortedLabels) {
|
for (const label of sortedLabels) {
|
||||||
const descriptions = labelMap.get(label)!
|
const descriptions = labelMap.get(label)!
|
||||||
// Use the first description, or combine if multiple
|
// Use the first description, or note if multiple workflows share the same label
|
||||||
const description =
|
const description =
|
||||||
descriptions.length === 1
|
descriptions.length === 1
|
||||||
? descriptions[0]
|
? descriptions[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user