Skip to content

Commit

Permalink
Use superset of tags and categories plus deprecation notices
Browse files Browse the repository at this point in the history
  • Loading branch information
sourishkrout committed Sep 16, 2024
1 parent 2f6f670 commit 2676c5d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion internal/config/autoconfig/autoconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ func getProjectFilters(c *config.Config) ([]project.Filter, error) {
filters = append(filters, project.Filter(func(t project.Task) (bool, error) {
env := config.FilterBlockEnv{
Background: t.CodeBlock.Background(),
Tags: t.CodeBlock.Tags(),
// TODO(adamb): implement this in the code block.
// CloseTerminalOnSuccess: t.CodeBlock.CloseTerminalOnSuccess(),
Cwd: t.CodeBlock.Cwd(),
Expand All @@ -181,6 +180,7 @@ func getProjectFilters(c *config.Config) ([]project.Filter, error) {
Language: t.CodeBlock.Language(),
Name: t.CodeBlock.Name(),
PromptEnv: t.CodeBlock.PromptEnv(),
Tags: t.CodeBlock.Tags(),
}
return filter.Evaluate(env)
}))
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type FilterDocumentEnv struct {
// Without it, all variables start with capitalized letters.
type FilterBlockEnv struct {
Background bool `expr:"background"`
Tags []string `expr:"tags"`
CloseTerminalOnSuccess bool `expr:"close_terminal_on_success"`
Cwd string `expr:"cwd"`
ExcludeFromRunAll bool `expr:"exclude_from_run_all"`
Expand All @@ -43,6 +42,7 @@ type FilterBlockEnv struct {
Language string `expr:"language"`
Name string `expr:"name"`
PromptEnv bool `expr:"prompt_env"`
Tags []string `expr:"tags"`
}

type filterDocumentWithExtraEnv struct {
Expand Down
1 change: 1 addition & 0 deletions pkg/api/proto/runme/parser/v1/parser.proto
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ message Frontmatter {
string cwd = 2;
bool skip_prompts = 3;
FrontmatterRunme runme = 4;
// Deprecated category in favor of Tag
string category = 5;
string terminal_rows = 6;
string tag = 7;
Expand Down
16 changes: 10 additions & 6 deletions pkg/document/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,19 @@ func (b *CodeBlock) Background() bool {
}

func (b *CodeBlock) Tags() []string {
tag, ok := b.Attributes()["category"]
if !ok {
tag, ok = b.Attributes()["tag"]
var superset []string

categories, ok := b.Attributes()["category"]
if ok {
superset = append(superset, strings.Split(categories, ",")...)
}

if !ok {
return nil
tags, ok := b.Attributes()["tags"]
if ok {
superset = append(superset, strings.Split(tags, ",")...)
}
return strings.Split(tag, ",")

return superset
}

func (b *CodeBlock) Clone() *CodeBlock {
Expand Down
12 changes: 12 additions & 0 deletions pkg/document/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ func TestBlock_Clone(t *testing.T) {
block.value[0] = 'a'
assert.NotEqual(t, block.value[0], clone.value[0])
}

func TestBlock_Tags(t *testing.T) {
t.Run("Superset including legacy categories", func(t *testing.T) {
block := &CodeBlock{
attributes: map[string]string{
"category": "cat1,cat2",
"tags": "tag1,tag2",
},
}
assert.Equal(t, []string{"cat1", "cat2", "tag1", "tag2"}, block.Tags())
})
}
15 changes: 8 additions & 7 deletions pkg/document/frontmatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ func (m *RunmeMetadata) IsEmpty() bool {
}

type Frontmatter struct {
Runme *RunmeMetadata `yaml:"runme,omitempty"`
Shell string `yaml:"shell"`
Cwd string `yaml:"cwd"`
Category string `yaml:"category"`
Tag string `yaml:"tag"`
TerminalRows string `yaml:"terminalRows"`
SkipPrompts bool `yaml:"skipPrompts,omitempty"`
Runme *RunmeMetadata `yaml:"runme,omitempty"`
Shell string `yaml:"shell"`
Cwd string `yaml:"cwd"`
// Deprecated Category in favor of Tag
Category string `yaml:"category"`
Tag string `yaml:"tag"`
TerminalRows string `yaml:"terminalRows"`
SkipPrompts bool `yaml:"skipPrompts,omitempty"`

format string
raw string // using string to be able to compare using ==
Expand Down

0 comments on commit 2676c5d

Please sign in to comment.