Skip to content

Commit 9293c6b

Browse files
committed
add missing change impl and tests
1 parent 312c8f5 commit 9293c6b

File tree

7 files changed

+541
-28
lines changed

7 files changed

+541
-28
lines changed

.github/workflows/pr.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ jobs:
149149

150150
- name: Format
151151
run: test -z "$(gofmt -l .)"
152+
shell: bash
152153
working-directory: ./go
153154

154155
- name: Lint

go/cmd/beachball/main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ func main() {
5454
}
5555
changeCmd.Flags().StringVarP(&cli.ChangeType, "type", "t", "", "change type (patch, minor, major, etc.)")
5656
changeCmd.Flags().StringVarP(&cli.Message, "message", "m", "", "change description")
57+
changeCmd.Flags().StringSliceVar(&cli.Package, "package", nil, "specific package(s) to create change files for")
58+
59+
var noCommitFlag bool
60+
changeCmd.Flags().BoolVar(&noCommitFlag, "no-commit", false, "don't commit change files")
61+
62+
var noFetchFlag bool
63+
rootCmd.PersistentFlags().BoolVar(&noFetchFlag, "no-fetch", false, "don't fetch remote branch")
5764

5865
var allFlag, verboseFlag bool
5966
rootCmd.PersistentFlags().BoolVar(&allFlag, "all", false, "include all packages")
@@ -66,6 +73,12 @@ func main() {
6673
if rootCmd.PersistentFlags().Changed("verbose") {
6774
cli.Verbose = boolPtr(verboseFlag)
6875
}
76+
if rootCmd.PersistentFlags().Changed("no-fetch") {
77+
cli.Fetch = boolPtr(!noFetchFlag)
78+
}
79+
if changeCmd.Flags().Changed("no-commit") {
80+
cli.Commit = boolPtr(!noCommitFlag)
81+
}
6982
})
7083

7184
rootCmd.AddCommand(checkCmd, changeCmd)

go/internal/changefile/write_change_files.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ func WriteChangeFiles(options *types.BeachballOptions, changes []types.ChangeFil
2323

2424
var filePaths []string
2525

26-
for _, change := range changes {
26+
if options.GroupChanges {
27+
// Write all changes to a single grouped file
2728
id := uuid.New().String()
28-
sanitized := nonAlphanumRe.ReplaceAllString(change.PackageName, "-")
29-
filename := fmt.Sprintf("%s-%s.json", sanitized, id)
29+
filename := fmt.Sprintf("change-%s.json", id)
3030
filePath := filepath.Join(changePath, filename)
3131

32-
data, err := json.MarshalIndent(change, "", " ")
32+
grouped := types.ChangeInfoMultiple{Changes: changes}
33+
data, err := json.MarshalIndent(grouped, "", " ")
3334
if err != nil {
34-
return fmt.Errorf("failed to marshal change: %w", err)
35+
return fmt.Errorf("failed to marshal grouped changes: %w", err)
3536
}
3637

3738
if err := os.WriteFile(filePath, append(data, '\n'), 0o644); err != nil {
@@ -40,6 +41,25 @@ func WriteChangeFiles(options *types.BeachballOptions, changes []types.ChangeFil
4041

4142
filePaths = append(filePaths, filePath)
4243
fmt.Printf("Wrote change file: %s\n", filename)
44+
} else {
45+
for _, change := range changes {
46+
id := uuid.New().String()
47+
sanitized := nonAlphanumRe.ReplaceAllString(change.PackageName, "-")
48+
filename := fmt.Sprintf("%s-%s.json", sanitized, id)
49+
filePath := filepath.Join(changePath, filename)
50+
51+
data, err := json.MarshalIndent(change, "", " ")
52+
if err != nil {
53+
return fmt.Errorf("failed to marshal change: %w", err)
54+
}
55+
56+
if err := os.WriteFile(filePath, append(data, '\n'), 0o644); err != nil {
57+
return fmt.Errorf("failed to write change file: %w", err)
58+
}
59+
60+
filePaths = append(filePaths, filePath)
61+
fmt.Printf("Wrote change file: %s\n", filename)
62+
}
4363
}
4464

4565
if len(filePaths) > 0 {

go/internal/commands/change.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func Change(parsed types.ParsedOptions) error {
1919
return err
2020
}
2121

22-
if !result.IsChangeNeeded {
22+
if !result.IsChangeNeeded && len(parsed.Options.Package) == 0 {
2323
fmt.Println("No changes detected; no change files are needed.")
2424
return nil
2525
}
@@ -46,8 +46,17 @@ func Change(parsed types.ParsedOptions) error {
4646
}
4747
}
4848

49+
changedPackages := result.ChangedPackages
50+
if len(changedPackages) == 0 && len(options.Package) > 0 {
51+
changedPackages = options.Package
52+
}
53+
54+
if len(changedPackages) == 0 {
55+
return nil
56+
}
57+
4958
var changes []types.ChangeFileInfo
50-
for _, pkg := range result.ChangedPackages {
59+
for _, pkg := range changedPackages {
5160
changes = append(changes, types.ChangeFileInfo{
5261
Type: changeType,
5362
Comment: message,

0 commit comments

Comments
 (0)