mirror of
https://github.com/hustcer/deepseek-review.git
synced 2026-05-13 05:16:05 +08:00
fix: Fix include & exclude pattern matching error (#122)
* fix: Fix include & exclude pattern matching error * ci skip * code refactor
This commit is contained in:
23
nu/review.nu
23
nu/review.nu
@@ -295,7 +295,7 @@ export def get-diff [
|
||||
print $'(ansi g)Nothing to review.(ansi reset)'; exit $ECODE.SUCCESS
|
||||
}
|
||||
let awk_bin = (prepare-awk)
|
||||
let outdated_awk = $'You may using an (ansi r)outdated awk version(ansi reset), please upgrade to the latest version or use gawk latest instead.'
|
||||
let outdated_awk = $'If you are using an (ansi r)outdated awk version(ansi reset), please upgrade to the latest version or use gawk latest instead.'
|
||||
if ($include | is-not-empty) {
|
||||
let patterns = $include | split row ','
|
||||
$content = $content | try { ^$awk_bin (generate-include-regex $patterns) } catch { print $outdated_awk; exit $ECODE.OUTDATED }
|
||||
@@ -409,15 +409,30 @@ export def hr-line [
|
||||
if $blank_line { char nl | print -n }
|
||||
}
|
||||
|
||||
# Convert glob patterns to regex patterns
|
||||
# Pass in *.nu directly as a regular expression does not work, because * in
|
||||
# a regular expression needs to be attached to the previous pattern, the correct
|
||||
# form should be .* So we should convert each glob pattern to a regex pattern:
|
||||
# 1. Convert * to .*
|
||||
# 2. Convert ? to . (optional, as needed)
|
||||
# 3. Convert / to \/
|
||||
def glob-to-regex [patterns: list<string>] {
|
||||
$patterns
|
||||
| each { |pat|
|
||||
$pat | str replace "*" ".*" | str replace "?" "." | str replace "/" "\\/"
|
||||
}
|
||||
| str join "|"
|
||||
}
|
||||
|
||||
# Generate the awk include regex pattern string for the specified patterns
|
||||
export def generate-include-regex [patterns: list<string>] {
|
||||
let pattern = $patterns | each {|pat| $pat | str replace '/' '\/' } | str join '|'
|
||||
let pattern = glob-to-regex $patterns
|
||||
$"/^diff --git/{p=/^diff --git a\\/($pattern)/}p"
|
||||
}
|
||||
|
||||
# Generate the awk exclude regex pattern string for the specified patterns
|
||||
def generate-exclude-regex [patterns: list<string>] {
|
||||
let pattern = $patterns | each {|pat| $pat | str replace '/' '\/' } | str join '|'
|
||||
export def generate-exclude-regex [patterns: list<string>] {
|
||||
let pattern = glob-to-regex $patterns
|
||||
$"/^diff --git/{p=/^diff --git a\\/($pattern)/}!p"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user