github: use regexp2 for advanced regex

Signed-off-by: unilock <unilock@fennet.rentals>
This commit is contained in:
unilock
2024-04-16 07:04:13 -04:00
parent 979b606b1e
commit 7207d4c6a4
4 changed files with 11 additions and 5 deletions

View File

@@ -9,6 +9,7 @@ import (
"path/filepath"
"regexp"
"github.com/dlclark/regexp2"
"github.com/packwiz/packwiz/core"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -120,7 +121,7 @@ func getLatestRelease(slug string, branch string) (Release, error) {
}
func installRelease(repo Repo, release Release, regex string, pack core.Pack) error {
expr := regexp.MustCompile(regex)
expr := regexp2.MustCompile(regex, 0)
if len(release.Assets) == 0 {
return errors.New("release doesn't have any assets attached")
@@ -129,7 +130,8 @@ func installRelease(repo Repo, release Release, regex string, pack core.Pack) er
var files []Asset
for _, v := range release.Assets {
if expr.MatchString(v.Name) {
bl, _ := expr.MatchString(v.Name)
if bl {
files = append(files, v)
}
}

View File

@@ -3,9 +3,9 @@ package github
import (
"errors"
"fmt"
"regexp"
"strings"
"github.com/dlclark/regexp2"
"github.com/mitchellh/mapstructure"
"github.com/packwiz/packwiz/core"
)
@@ -53,7 +53,7 @@ func (u ghUpdater) CheckUpdate(mods []*core.Mod, pack core.Pack) ([]core.UpdateC
continue
}
expr := regexp.MustCompile(data.Regex)
expr := regexp2.MustCompile(data.Regex, 0)
if len(newRelease.Assets) == 0 {
results[i] = core.UpdateCheck{Error: errors.New("new release doesn't have any assets")}
@@ -63,7 +63,8 @@ func (u ghUpdater) CheckUpdate(mods []*core.Mod, pack core.Pack) ([]core.UpdateC
var newFiles []Asset
for _, v := range newRelease.Assets {
if expr.MatchString(v.Name) {
bl, _ := expr.MatchString(v.Name)
if bl {
newFiles = append(newFiles, v)
}
}