Skip to content

Commit

Permalink
feat: implement usage mode switch
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Rose <[email protected]>
  • Loading branch information
matty-rose committed Nov 27, 2021
1 parent fd0f058 commit ad70c8c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Config struct {
func New(config Config) (Generator, error) {
switch config.Format {
case "markdown":
return markdownGenerator{}, nil
return markdownGenerator{config}, nil
}

return nil, errors.New("unsupported format")
Expand Down
5 changes: 4 additions & 1 deletion pkg/generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ import (
func TestInvalidFormat(t *testing.T) {
t.Parallel()

g, err := generator.New(generator.Config{Format: "invalid"})
var mode generator.UsageMode = generator.Remote

config := generator.Config{Format: "invalid", ExampleUsageMode: &mode}
g, err := generator.New(config)

assert.Nil(t, g)
assert.Error(t, err)
Expand Down
16 changes: 11 additions & 5 deletions pkg/generator/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import (
"github.com/matty-rose/gha-docs/pkg/types"
)

type markdownGenerator struct{}
type markdownGenerator struct {
config Config
}

func (mdg markdownGenerator) Generate(action *types.CompositeAction) string {
doc := document.NewMarkdownDocument()
Expand Down Expand Up @@ -124,10 +126,14 @@ func (mdg markdownGenerator) generateExternalActionTable(act *types.CompositeAct
func (mdg markdownGenerator) generateExampleUsageBlock(act *types.CompositeAction, doc *document.MarkdownDocument) {
doc.WriteCodeBlockMarkerWithFormat("yaml")
doc.WriteTextLn(fmt.Sprintf("- name: %s", act.Name))
// TODO: Some way of getting actual owner/repo name here?
// TODO: Add config option for action location - remote or local, and for local change
// `uses` to be a path
doc.WriteTextLn(" uses: owner/repo@latest")

switch *mdg.config.ExampleUsageMode {
case Remote:
// TODO: Some way of getting actual owner/repo name here?
doc.WriteTextLn(" uses: owner/repo@latest")
case Local:
doc.WriteTextLn(" uses: ./path/to/action.yml")
}

if len(act.Inputs) == 0 {
doc.WriteCodeBlockMarker()
Expand Down
3 changes: 2 additions & 1 deletion pkg/generator/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import (
)

func newMarkdownConfig() generator.Config {
return generator.Config{Format: "markdown"}
mode := generator.Remote
return generator.Config{Format: "markdown", ExampleUsageMode: &mode}
}

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

0 comments on commit ad70c8c

Please sign in to comment.