Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore][chloggen] Clean up terminology for unreleased directory #368

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions chloggen/cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ func setupTestDir(t *testing.T, entries []*chlog.Entry) chlog.Context {
ctx := chlog.New(t.TempDir())

// Create a known dummy changelog which may be updated by the test
changelogBytes, err := os.ReadFile(filepath.Join("testdata", "CHANGELOG.md"))
changelogBytes, err := os.ReadFile(filepath.Join("testdata", chlog.DefaultChangelogMD))
require.NoError(t, err)
require.NoError(t, os.WriteFile(ctx.ChangelogMD, changelogBytes, os.FileMode(0755)))

require.NoError(t, os.Mkdir(ctx.UnreleasedDir, os.FileMode(0755)))
require.NoError(t, os.Mkdir(ctx.ChloggenDir, os.FileMode(0755)))

// Copy the entry template, for tests that ensure it is not deleted
templateInRootDir := chlog.New("testdata").TemplateYAML
Expand All @@ -123,6 +123,6 @@ func writeEntryYAML(ctx chlog.Context, filename string, entry *chlog.Entry) erro
if err != nil {
return err
}
path := filepath.Join(ctx.UnreleasedDir, filename)
path := filepath.Join(ctx.ChloggenDir, filename)
return os.WriteFile(path, entryBytes, os.FileMode(0755))
}
2 changes: 1 addition & 1 deletion chloggen/cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var newCmd = &cobra.Command{
}

func initialize(ctx chlog.Context, filename string) error {
path := filepath.Join(ctx.UnreleasedDir, cleanFileName(filename))
path := filepath.Join(ctx.ChloggenDir, cleanFileName(filename))
var pathWithExt string
switch ext := filepath.Ext(path); ext {
case ".yaml":
Expand Down
2 changes: 1 addition & 1 deletion chloggen/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func initConfig() {
if chloggenDir == "" {
chloggenDir = ".chloggen"
}
chlogCtx = chlog.New(chlog.RepoRoot(), chlog.WithUnreleasedDir(chloggenDir))
chlogCtx = chlog.New(chlog.RepoRoot(), chlog.WithChloggenDir(chloggenDir))
}

func init() {
Expand Down
2 changes: 1 addition & 1 deletion chloggen/cmd/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestUpdateE2E(t *testing.T) {

require.Equal(t, string(expectedBytes), string(actualBytes))

remainingYAMLs, err := filepath.Glob(filepath.Join(ctx.UnreleasedDir, "*.yaml"))
remainingYAMLs, err := filepath.Glob(filepath.Join(ctx.ChloggenDir, "*.yaml"))
require.NoError(t, err)
if tc.dry {
require.Equal(t, 1+len(tc.entries), len(remainingYAMLs))
Expand Down
4 changes: 2 additions & 2 deletions chloggen/cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var validateCmd = &cobra.Command{
}

func validate(ctx chlog.Context) error {
if _, err := os.Stat(ctx.UnreleasedDir); err != nil {
if _, err := os.Stat(ctx.ChloggenDir); err != nil {
return err
}

Expand All @@ -45,6 +45,6 @@ func validate(ctx chlog.Context) error {
return err
}
}
fmt.Printf("PASS: all files in %s/ are valid\n", ctx.UnreleasedDir)
fmt.Printf("PASS: all files in %s/ are valid\n", ctx.ChloggenDir)
return nil
}
28 changes: 14 additions & 14 deletions chloggen/internal/chlog/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,34 @@ import (
)

const (
changelogMD = "CHANGELOG.md"
unreleasedDir = ".chloggen"
templateYAML = "TEMPLATE.yaml"
DefaultChangelogMD = "CHANGELOG.md"
DefaultChloggenDir = ".chloggen"
DefaultTemplateYAML = "TEMPLATE.yaml"
)

// Context enables tests by allowing them to work in an test directory
type Context struct {
rootDir string
ChangelogMD string
UnreleasedDir string
TemplateYAML string
rootDir string
ChangelogMD string
ChloggenDir string
TemplateYAML string
}

type Option func(*Context)

func WithUnreleasedDir(unreleasedDir string) Option {
func WithChloggenDir(chloggenDir string) Option {
return func(ctx *Context) {
ctx.UnreleasedDir = filepath.Join(ctx.rootDir, unreleasedDir)
ctx.TemplateYAML = filepath.Join(ctx.rootDir, unreleasedDir, templateYAML)
ctx.ChloggenDir = filepath.Join(ctx.rootDir, chloggenDir)
ctx.TemplateYAML = filepath.Join(ctx.rootDir, chloggenDir, DefaultTemplateYAML)
}
}

func New(rootDir string, options ...Option) Context {
ctx := Context{
rootDir: rootDir,
ChangelogMD: filepath.Join(rootDir, changelogMD),
UnreleasedDir: filepath.Join(rootDir, unreleasedDir),
TemplateYAML: filepath.Join(rootDir, unreleasedDir, templateYAML),
rootDir: rootDir,
ChangelogMD: filepath.Join(rootDir, DefaultChangelogMD),
ChloggenDir: filepath.Join(rootDir, DefaultChloggenDir),
TemplateYAML: filepath.Join(rootDir, DefaultChloggenDir, DefaultTemplateYAML),
}
for _, op := range options {
op(&ctx)
Expand Down
18 changes: 9 additions & 9 deletions chloggen/internal/chlog/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ func TestNew(t *testing.T) {
root := "/tmp"
ctx := New(root)
assert.Equal(t, root, ctx.rootDir)
assert.Equal(t, filepath.Join(root, unreleasedDir), ctx.UnreleasedDir)
assert.Equal(t, filepath.Join(root, changelogMD), ctx.ChangelogMD)
assert.Equal(t, filepath.Join(root, unreleasedDir, templateYAML), ctx.TemplateYAML)
assert.Equal(t, filepath.Join(root, DefaultChloggenDir), ctx.ChloggenDir)
assert.Equal(t, filepath.Join(root, DefaultChangelogMD), ctx.ChangelogMD)
assert.Equal(t, filepath.Join(root, DefaultChloggenDir, DefaultTemplateYAML), ctx.TemplateYAML)
}

func TestWithUnreleasedDir(t *testing.T) {
func TestWithChloggenDir(t *testing.T) {
root := "/tmp"
unreleased := ".test"
ctx := New(root, WithUnreleasedDir(unreleased))
chloggenDir := ".test"
ctx := New(root, WithChloggenDir(chloggenDir))
assert.Equal(t, root, ctx.rootDir)
assert.Equal(t, filepath.Join(root, unreleased), ctx.UnreleasedDir)
assert.Equal(t, filepath.Join(root, changelogMD), ctx.ChangelogMD)
assert.Equal(t, filepath.Join(root, unreleased, templateYAML), ctx.TemplateYAML)
assert.Equal(t, filepath.Join(root, chloggenDir), ctx.ChloggenDir)
assert.Equal(t, filepath.Join(root, DefaultChangelogMD), ctx.ChangelogMD)
assert.Equal(t, filepath.Join(root, chloggenDir, DefaultTemplateYAML), ctx.TemplateYAML)
}

func TestRepoRoot(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions chloggen/internal/chlog/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (e Entry) String() string {
}

func ReadEntries(ctx Context) ([]*Entry, error) {
entryYAMLs, err := filepath.Glob(filepath.Join(ctx.UnreleasedDir, "*.yaml"))
entryYAMLs, err := filepath.Glob(filepath.Join(ctx.ChloggenDir, "*.yaml"))
if err != nil {
return nil, err
}
Expand All @@ -118,7 +118,7 @@ func ReadEntries(ctx Context) ([]*Entry, error) {
}

func DeleteEntries(ctx Context) error {
entryYAMLs, err := filepath.Glob(filepath.Join(ctx.UnreleasedDir, "*.yaml"))
entryYAMLs, err := filepath.Glob(filepath.Join(ctx.ChloggenDir, "*.yaml"))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion chloggen/internal/chlog/entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestEntry(t *testing.T) {

func TestReadDeleteEntries(t *testing.T) {
tempDir := t.TempDir()
entriesDir := filepath.Join(tempDir, ".chloggen")
entriesDir := filepath.Join(tempDir, DefaultChloggenDir)
require.NoError(t, os.Mkdir(entriesDir, os.ModePerm))

entryA := Entry{
Expand Down