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

Return ConventionalCommit content in public interface #36

Open
lewismiddleton opened this issue Jul 14, 2024 · 0 comments · May be fixed by #37
Open

Return ConventionalCommit content in public interface #36

lewismiddleton opened this issue Jul 14, 2024 · 0 comments · May be fixed by #37

Comments

@lewismiddleton
Copy link

When using this package, I found that the return type of the Parse method didn't give me access to any of the attributes on the ConventionalCommit object.

Minimal Reproducer
package main

import (
	"fmt"

	"github.com/leodido/go-conventionalcommits"
	"github.com/leodido/go-conventionalcommits/parser"
)

// Example from https://github.com/leodido/go-conventionalcommits/blob/2713df998a1596207af6090215be9cbe2fd651be/parser/example_test.go#L81
func main() {
	i := []byte(`fix: correct minor typos in code

see the issue [0] for details
on typos fixed.

[0]: https://issue

Reviewed-by: Z
Refs #133`)
	opts := []conventionalcommits.MachineOption{
		parser.WithTypes(conventionalcommits.TypesConventional),
	}
	m, _ := parser.NewMachine(opts...).Parse(i)

	// fmt.Printf("%+v", m)
	fmt.Println(m.Description)
}

When running with the code above, I get:

./main.go:27:16: m.Description undefined (type conventionalcommits.Message has no field or method Description)

If you comment out the line referencing the Description and dump the object you get:

&{Type:fix Description:correct minor typos in code Scope:<nil> Exclamation:false Body:0x140001181b8 Footers:map[refs:[133] reviewed-by:[Z]] TypeConfig:1}⏎                                                                                        

I think this is because the Parse method returns a Message object instead of a ConventionalCommit

Even though the attributes get specified in the object, the type system isn't aware that those properties are available.

I think the fix for this is changing the return types to be the more specific *conventionalcommits.ConventionalCommit. This shouldn't lose any functionality because the ConventionalCommit struct implements the Message interface (it took me a quick reference to how interfaces work to figure this out)

@lewismiddleton lewismiddleton linked a pull request Jul 14, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant