Skip to content

Commit

Permalink
Merge branch 'main' into 687-json-schema
Browse files Browse the repository at this point in the history
  • Loading branch information
miniscruff authored Feb 8, 2025
2 parents e746ae4 + 697a84f commit 5679cdc
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .changes/unreleased/fixed-20250207-225527.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: fixed
body: Merging when configured to use projects but the changelog path does not yet exist
time: 2025-02-07T22:55:27.570690973-08:00
custom:
Issue: "743"
5 changes: 5 additions & 0 deletions .changes/unreleased/fixed-20250207-231718.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: fixed
body: next version with projects without any releases returns v1.0.0 instead of an error
time: 2025-02-07T23:17:18.461699249-08:00
custom:
Issue: "743"
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ linters-settings:
goconst:
min-len: 5
min-occurrences: 5
gocyclo:
min-complexity: 16
goimports:
local-prefixes: github.com/miniscruff/changie
golint:
Expand All @@ -26,7 +24,6 @@ linters:
- errcheck
- exhaustive
- goconst
- gocyclo
- gofmt
- goimports
- goprintffuncname
Expand Down
10 changes: 8 additions & 2 deletions cmd/merge.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"fmt"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -84,9 +85,14 @@ func (m *Merge) mergeProject(
if m.DryRun {
writer = m.Command.OutOrStdout()
} else {
dirErr := os.MkdirAll(filepath.Dir(changelogPath), core.CreateDirMode)
if dirErr != nil {
return fmt.Errorf("creating changelog file directory: %w", dirErr)
}

changeFile, changeErr := os.Create(changelogPath)
if changeErr != nil {
return changeErr
return fmt.Errorf("creating changelog file: %w", changeErr)
}

defer changeFile.Close()
Expand All @@ -95,7 +101,7 @@ func (m *Merge) mergeProject(

allVersions, err := core.GetAllVersions(cfg, false, project)
if err != nil {
return err
return fmt.Errorf("finding release notes: %w", err)
}

if cfg.HeaderPath != "" {
Expand Down
8 changes: 5 additions & 3 deletions cmd/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func TestMergeVersionsSuccessfullyWithProject(t *testing.T) {
then.WriteFile(t, []byte("first version\n"), cfg.ChangesDir, "a", "v0.1.0.md")
then.WriteFile(t, []byte("second version\n"), cfg.ChangesDir, "a", "v0.2.0.md")
then.WriteFile(t, []byte("version\n"), "a", "VERSION")
then.Nil(t, os.MkdirAll(filepath.Join("a", "thing"), core.CreateDirMode))

cmd := NewMerge(core.NewTemplateCache())

Expand All @@ -98,7 +97,7 @@ first version
then.FileContents(t, "v0.2.0\n", "a", "VERSION")
}

func TestMergeVersionsErrorMissingProjectDir(t *testing.T) {
func TestMergeVersionsSuccessfullyWithProjectAndNoChanges(t *testing.T) {
cfg := mergeTestConfig()
cfg.HeaderPath = ""
cfg.Replacements = nil
Expand All @@ -114,7 +113,10 @@ func TestMergeVersionsErrorMissingProjectDir(t *testing.T) {
cmd := NewMerge(core.NewTemplateCache())

err := cmd.Run(cmd.Command, nil)
then.NotNil(t, err)
then.Nil(t, err)

changeContents := ``
then.FileContents(t, changeContents, "a", "thing", "CHANGELOG.md")
}

func TestMergeVersionsWithUnreleasedChanges(t *testing.T) {
Expand Down
27 changes: 14 additions & 13 deletions cmd/next_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ func TestNextVersionWithPrereleaseAndMeta(t *testing.T) {
then.Equals(t, "v0.1.1-b1+hash", builder.String())
}

func TestNextVersionWithoutAnyChangesIsV1(t *testing.T) {
cfg := nextTestConfig()
then.WithTempDirConfig(t, cfg)

builder := strings.Builder{}

next := NewNext()
next.SetOut(&builder)

err := next.Run(next.Command, []string{"major"})
then.Nil(t, err)
then.Equals(t, "v1.0.0", builder.String())
}

func TestErrorNextVersionBadConfig(t *testing.T) {
then.WithTempDir(t)

Expand Down Expand Up @@ -192,16 +206,3 @@ func TestErrorNextUnableToGetChanges(t *testing.T) {
err := next.Run(next.Command, []string{"auto"})
then.NotNil(t, err)
}

func TestErrorNextUnableToGetVersions(t *testing.T) {
then.WithTempDirConfig(t, nextTestConfig())

next := NewNext()
builder := strings.Builder{}

next.SetOut(&builder)

// no files, means bad read for get versions
err := next.Run(next.Command, []string{"major"})
then.NotNil(t, err)
}
5 changes: 5 additions & 0 deletions core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -60,6 +61,10 @@ func GetAllVersions(
}

fileInfos, err := os.ReadDir(versionsPath)
if err != nil && errors.Is(err, fs.ErrNotExist) {
return allVersions, nil
}

if err != nil {
return allVersions, fmt.Errorf("reading files from '%s': %w", versionsPath, err)
}
Expand Down
14 changes: 2 additions & 12 deletions core/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,24 +155,14 @@ func TestGetLatestReturnsZerosIfNoVersionsExist(t *testing.T) {
then.Equals(t, "v0.0.0", ver.Original())
}

func TestErrorLatestVersionBadReadDir(t *testing.T) {
then.WithTempDir(t)

config := &Config{ChangesDir: "\\."}

ver, err := GetLatestVersion(config, false, "")
then.Equals(t, nil, ver)
then.NotNil(t, err)
}

func TestErrorNextVersionBadReadDir(t *testing.T) {
then.WithTempDir(t)

config := &Config{ChangesDir: "\\."}

ver, err := GetNextVersion(config, "major", nil, nil, nil, "")
then.Equals(t, nil, ver)
then.NotNil(t, err)
then.Equals(t, "v1.0.0", ver.Original())
then.Nil(t, err)
}

func TestErrorNextVersionBadVersion(t *testing.T) {
Expand Down

0 comments on commit 5679cdc

Please sign in to comment.