Skip to content

Commit 9e084bb

Browse files
authored
Merge pull request #8 from OffchainLabs/improve-ux
Improve ux
2 parents 1b11604 + de9778a commit 9e084bb

File tree

5 files changed

+71
-7
lines changed

5 files changed

+71
-7
lines changed

changelog/changelog.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
var versionRE = regexp.MustCompile(`^#+ \[(v\d+\.\d+\.\d+)\]`)
18-
var sectionRE = regexp.MustCompile(`^### (\w+)\s?$`)
18+
var sectionRE = regexp.MustCompile(`^#{1,6} (\w+)\s?$`)
1919

2020
const preamble = `# Changelog
2121
@@ -242,6 +242,10 @@ func ParseFragment(lines []string, pr string) map[string][]string {
242242
current = section
243243
continue
244244
}
245+
// We don't have a way to categorize a bullet found outside a known section.
246+
if current == "" {
247+
continue
248+
}
245249
bullet := parseBullet(line, pr)
246250
if bullet == "" {
247251
continue
@@ -266,7 +270,7 @@ func ValidSections(sections map[string][]string) error {
266270
if k == sectionIgnored {
267271
continue
268272
}
269-
return fmt.Errorf("invalid section name: %s", k)
273+
return fmt.Errorf("invalid section name in fragment: %s", k)
270274
}
271275
}
272276
return nil

changelog/changelog_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,24 @@ func TestParseBulletOverride(t *testing.T) {
1616
t.Error("parseBullet did not recognize the override")
1717
}
1818
}
19+
20+
func TestSectionRe(t *testing.T) {
21+
cases := []struct {
22+
value string
23+
valid bool
24+
}{
25+
{value: "####### Fixes", valid: false}, // there's no H7
26+
{value: " Fixes", valid: false},
27+
{value: "# Fixes", valid: true},
28+
{value: "## Fixes", valid: true},
29+
{value: "### Fixes", valid: true},
30+
{value: "#### Fixes", valid: true},
31+
{value: "##### Fixes", valid: true},
32+
{value: "###### Fixes", valid: true},
33+
}
34+
for _, c := range cases {
35+
if valid := sectionRE.MatchString(c.value); valid != c.valid {
36+
t.Errorf("sectionRE failed to match %v", c)
37+
}
38+
}
39+
}

cmd/check/main.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,40 @@ type githubConf struct {
1616
FragmentListingEnv string // name of env var containing a list of file fragments
1717
}
1818

19-
func parseArgs(args []string) (*changelog.Config, *githubConf, error) {
19+
func parseArgs(args []string) (c *changelog.Config, envConf *githubConf, err error) {
2020
flags := flag.NewFlagSet("check", flag.ContinueOnError)
21-
c := &changelog.Config{RepoConfig: changelog.RepoConfig{Owner: "prysmaticlabs", Repo: "prysm"}, ReleaseTime: time.Now()}
21+
flags.Usage = func() {
22+
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
23+
flags.PrintDefaults()
24+
fmt.Fprint(flag.CommandLine.Output(), "\n")
25+
}
26+
defer func() {
27+
if err != nil {
28+
flags.Usage()
29+
}
30+
}()
31+
32+
c = &changelog.Config{RepoConfig: changelog.RepoConfig{Owner: "prysmaticlabs", Repo: "prysm"}, ReleaseTime: time.Now()}
2233
flags.StringVar(&c.RepoPath, "repo", "", "Path to the git repository")
2334
flags.StringVar(&c.ChangesDir, "changelog-dir", "changelog", "Path to the directory containing changelog fragments for each commit")
2435
flags.StringVar(&c.RepoConfig.MainRev, "main-rev", "origin/develop", "Main branch tip revision")
2536
flags.StringVar(&c.Branch, "branch", "HEAD", "branch tip revision")
2637
envCfg := &githubConf{}
2738
flags.StringVar(&envCfg.FragmentListingEnv, "fragment-env", "", "Name of the environment variable containing a list of changelog fragments")
2839
flags.Parse(args)
40+
if c.RepoPath == "" {
41+
wd, err := os.Getwd()
42+
if err != nil {
43+
return nil, envCfg, fmt.Errorf("repo flag not set and can't get working directory from syscall, %w", err)
44+
}
45+
c.RepoPath = wd
46+
}
2947
if envCfg.FragmentListingEnv != "" {
3048
return nil, envCfg, nil
3149
}
3250

3351
if c.RepoPath == "" {
34-
return c, nil, fmt.Errorf("repo is required")
52+
return c, nil, fmt.Errorf("-repo flag is required")
3553
}
3654
return c, nil, nil
3755
}
@@ -75,6 +93,9 @@ func checkFragments(envCfg *githubConf) error {
7593
}
7694
lines := strings.Split(string(b), "\n")
7795
parsed := changelog.ParseFragment(lines, "")
96+
if len(parsed) == 0 {
97+
return fmt.Errorf("please check formatting of fragment file at %s, could not find any bullet points within valid sections", p)
98+
}
7899
for k, v := range parsed {
79100
if len(v) == 0 {
80101
delete(parsed, k)

cmd/release/main.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,19 @@ import (
1111
"github.com/OffchainLabs/unclog/changelog"
1212
)
1313

14-
func parseArgs(args []string) (*changelog.Config, error) {
14+
func parseArgs(args []string) (c *changelog.Config, err error) {
1515
flags := flag.NewFlagSet("release", flag.ContinueOnError)
16-
c := &changelog.Config{RepoConfig: changelog.RepoConfig{Owner: "prysmaticlabs", Repo: "prysm"}, ReleaseTime: time.Now()}
16+
flags.Usage = func() {
17+
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
18+
flags.PrintDefaults()
19+
fmt.Fprint(flag.CommandLine.Output(), "\n")
20+
}
21+
defer func() {
22+
if err != nil {
23+
flags.Usage()
24+
}
25+
}()
26+
c = &changelog.Config{RepoConfig: changelog.RepoConfig{Owner: "prysmaticlabs", Repo: "prysm"}, ReleaseTime: time.Now()}
1727
flags.StringVar(&c.RepoPath, "repo", "", "Path to the git repository")
1828
flags.StringVar(&c.ChangesDir, "changelog-dir", "changelog", "Path to the directory containing changelog fragments for each commit")
1929
flags.StringVar(&c.Tag, "tag", "", "New release tag (must already exist in repo)")

log/kasey_improve-ux.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### Added
2+
- Output usage when a required param is missing.
3+
4+
### Fixed
5+
- Bug parsing bullet points outside of valid section, causing a confusing error message.
6+
7+
### Changed
8+
- Relax heading format so that H1-H6 all allowed.

0 commit comments

Comments
 (0)