Skip to content

Commit c75b11e

Browse files
authored
Merge pull request #197 from gofiber/codex/2025-08-24-17-02-38
2 parents 089373c + c066ed6 commit c75b11e

File tree

5 files changed

+529
-3
lines changed

5 files changed

+529
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ fiber migrate --to 3.0.0
164164
-f, --force Force migration even if already on the version
165165
-s, --skip_go_mod Skip running go mod tidy, download and vendor
166166
--hash string Commit hash for Fiber version
167+
--third-party strings Refresh third-party modules (contrib,storage,template). Provide a comma-separated list and optionally append @<commit> to pin a commit
167168
-v, --verbose Enable verbose output
168169
-h, --help help for migrate
169170
```

cmd/migrate.go

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/spf13/cobra"
1717
"golang.org/x/mod/module"
1818

19+
"github.com/gofiber/cli/cmd/internal"
1920
"github.com/gofiber/cli/cmd/internal/migrations"
2021
)
2122

@@ -25,6 +26,7 @@ func newMigrateCmd() *cobra.Command {
2526
var force bool
2627
var skipGoMod bool
2728
var verbose bool
29+
var thirdParty []string
2830

2931
cmd := &cobra.Command{
3032
Use: "migrate",
@@ -36,15 +38,29 @@ func newMigrateCmd() *cobra.Command {
3638
cmd.Flags().BoolVarP(&skipGoMod, "skip_go_mod", "s", false, "Skip running go mod tidy, download and vendor")
3739
cmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose output")
3840
cmd.Flags().StringVar(&targetHash, "hash", "", "Commit hash for Fiber version")
41+
cmd.Flags().StringSliceVar(&thirdParty, "third-party", nil, "Refresh third-party modules (contrib,storage,template). Use a comma-separated list like --third-party=contrib,storage and append @<commit> to pin a commit")
3942

4043
cmd.RunE = func(cmd *cobra.Command, _ []string) error {
44+
tps := make([]ThirdPartyParam, 0, len(thirdParty))
45+
for _, tp := range thirdParty {
46+
parts := strings.SplitN(tp, "@", 2)
47+
p := ThirdPartyParam{Name: parts[0]}
48+
if len(parts) == 2 {
49+
p.Hash = parts[1]
50+
}
51+
if p.Name != "" {
52+
tps = append(tps, p)
53+
}
54+
}
55+
4156
return migrateRunE(cmd, MigrateOptions{
4257
CurrentVersionFile: currentVersionFile,
4358
TargetVersionS: targetVersionS,
4459
TargetHash: targetHash,
4560
Force: force,
4661
SkipGoMod: skipGoMod,
4762
Verbose: verbose,
63+
ThirdParty: tps,
4864
})
4965
}
5066

@@ -57,11 +73,17 @@ type MigrateOptions struct {
5773
CurrentVersionFile string
5874
TargetVersionS string
5975
TargetHash string
76+
ThirdParty []ThirdPartyParam
6077
Force bool
6178
SkipGoMod bool
6279
Verbose bool
6380
}
6481

82+
type ThirdPartyParam struct {
83+
Name string
84+
Hash string
85+
}
86+
6587
func migrateRunE(cmd *cobra.Command, opts MigrateOptions) error {
6688
currentVersionS, err := currentVersionFromFile(opts.CurrentVersionFile)
6789
if err != nil {
@@ -84,7 +106,7 @@ func migrateRunE(cmd *cobra.Command, opts MigrateOptions) error {
84106

85107
targetVersion := baseVersion
86108
if opts.TargetHash != "" {
87-
pv, err := pseudoVersionFromHash(baseVersion, opts.TargetHash)
109+
pv, err := pseudoVersionFromHash("gofiber/fiber", baseVersion, opts.TargetHash)
88110
if err != nil {
89111
return fmt.Errorf("pseudo version: %w", err)
90112
}
@@ -121,15 +143,42 @@ func migrateRunE(cmd *cobra.Command, opts MigrateOptions) error {
121143
return fmt.Errorf("migration failed %w", err)
122144
}
123145

146+
tpChanged := false
147+
for _, tp := range opts.ThirdParty {
148+
var (
149+
changed bool
150+
err error
151+
)
152+
switch tp.Name {
153+
case "contrib":
154+
changed, err = refreshContrib(cmd, wd, tp.Hash)
155+
case "storage":
156+
changed, err = refreshStorage(cmd, wd, tp.Hash)
157+
case "template", "templates":
158+
changed, err = refreshTemplates(cmd, wd, tp.Hash)
159+
}
160+
if err != nil {
161+
return fmt.Errorf("refresh %s packages: %w", tp.Name, err)
162+
}
163+
if changed {
164+
tpChanged = true
165+
}
166+
}
167+
if tpChanged && !opts.SkipGoMod {
168+
if err := internal.RunGoMod(wd); err != nil {
169+
return fmt.Errorf("go mod: %w", err)
170+
}
171+
}
172+
124173
msg := fmt.Sprintf("Migration from Fiber %s to %s", migrateFromS, opts.TargetVersionS)
125174
cmd.Println(termenv.String(msg).
126175
Foreground(termenv.ANSIBrightBlue))
127176

128177
return nil
129178
}
130179

131-
func pseudoVersionFromHash(base *semver.Version, hash string) (string, error) {
132-
url := "https://api.github.com/repos/gofiber/fiber/commits/" + hash
180+
func pseudoVersionFromHash(repo string, base *semver.Version, hash string) (string, error) {
181+
url := "https://api.github.com/repos/" + repo + "/commits/" + hash
133182
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
134183
defer cancel()
135184

0 commit comments

Comments
 (0)