mirror of
https://github.com/packwiz/packwiz.git
synced 2025-11-19 01:24:32 +01:00
feat: add branch support for github mods
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -18,9 +17,6 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var modSiteRegex = regexp.MustCompile("modrinth\\.com/mod/([^/]+)/?$")
|
||||
var versionSiteRegex = regexp.MustCompile("modrinth\\.com/mod/([^/]+)/version/([^/]+)/?$")
|
||||
|
||||
// installCmd represents the install command
|
||||
var installCmd = &cobra.Command{
|
||||
Use: "install [mod]",
|
||||
@@ -134,7 +130,7 @@ func fetchMod(slug string) (Mod, error) {
|
||||
func installMod(mod Mod, pack core.Pack) error {
|
||||
fmt.Printf("Found mod %s: '%s'.\n", mod.Title, mod.Description)
|
||||
|
||||
latestVersion, err := getLatestVersion(mod.Slug, pack)
|
||||
latestVersion, err := getLatestVersion(mod.Slug, pack, "")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get latest version: %v", err)
|
||||
}
|
||||
@@ -145,7 +141,7 @@ func installMod(mod Mod, pack core.Pack) error {
|
||||
return installVersion(mod, latestVersion, pack)
|
||||
}
|
||||
|
||||
func getLatestVersion(slug string, pack core.Pack) (ModReleases, error) {
|
||||
func getLatestVersion(slug string, pack core.Pack, branch string) (ModReleases, error) {
|
||||
var modReleases []ModReleases
|
||||
var release ModReleases
|
||||
|
||||
@@ -171,6 +167,11 @@ func getLatestVersion(slug string, pack core.Pack) (ModReleases, error) {
|
||||
if err != nil {
|
||||
return release, err
|
||||
}
|
||||
for _, r := range modReleases {
|
||||
if r.TargetCommitish == branch {
|
||||
return r, nil
|
||||
}
|
||||
}
|
||||
|
||||
return modReleases[0], nil
|
||||
}
|
||||
@@ -200,8 +201,9 @@ func installVersion(mod Mod, version ModReleases, pack core.Pack) error {
|
||||
updateMap := make(map[string]map[string]interface{})
|
||||
|
||||
updateMap["github"], err = ghUpdateData{
|
||||
ModID: mod.ID,
|
||||
ModID: mod.Slug,
|
||||
InstalledVersion: version.TagName,
|
||||
Branch: version.TargetCommitish,
|
||||
}.ToMap()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user