Skip to content

Commit 2acdff3

Browse files
author
Alex Boten
authored
[chloggen] use current directory as repo root (open-telemetry#130)
This change allows chloggen to find the `unreleased` folder in the current directory, rather than expecting it to be in the module's directory. Also added a validation check for the filename on `new` command.
1 parent 01366cb commit 2acdff3

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

chloggen/context.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package main
1616

1717
import (
1818
"fmt"
19+
"os"
1920
"path/filepath"
2021
"runtime"
2122
)
@@ -44,10 +45,15 @@ func newChlogContext(rootDir string) chlogContext {
4445
var defaultCtx = newChlogContext(repoRoot())
4546

4647
func repoRoot() string {
47-
return filepath.Dir(thisDir())
48+
dir, err := os.Getwd()
49+
if err != nil {
50+
// This is not expected, but just in case
51+
fmt.Println("FAIL: Could not determine current working directory")
52+
}
53+
return dir
4854
}
4955

50-
func thisDir() string {
56+
func moduleDir() string {
5157
_, filename, _, ok := runtime.Caller(0)
5258
if !ok {
5359
// This is not expected, but just in case

chloggen/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ func main() {
5454
fmt.Printf("FAIL: new: %v\n", err)
5555
os.Exit(1)
5656
}
57+
if len(*filename) == 0 {
58+
fmt.Printf("FAIL: new: 'filename' is required\n")
59+
}
5760
if err := initialize(defaultCtx, *filename); err != nil {
5861
fmt.Printf("FAIL: new: %v\n", err)
5962
os.Exit(1)
@@ -118,7 +121,7 @@ func validate(ctx chlogContext) error {
118121
return err
119122
}
120123
}
121-
fmt.Printf("PASS: all files in ./%s/ are valid\n", ctx.unreleasedDir)
124+
fmt.Printf("PASS: all files in %s/ are valid\n", ctx.unreleasedDir)
122125
return nil
123126
}
124127

chloggen/summary.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func generateSummary(version string, entries []*Entry) (string, error) {
6161
}
6262

6363
func (s summary) String() (string, error) {
64-
summaryTmpl := filepath.Join(thisDir(), "summary.tmpl")
64+
summaryTmpl := filepath.Join(moduleDir(), "summary.tmpl")
6565

6666
tmpl := template.Must(
6767
template.

0 commit comments

Comments
 (0)