Skip to content

Commit

Permalink
Merge pull request #388 from hugo-syn/dev-containsExpression
Browse files Browse the repository at this point in the history
make ContainsExpression(s string) public
  • Loading branch information
rhysd authored Feb 9, 2024
2 parents 0ae9462 + 0ecb675 commit 0b34b0f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ type String struct {
Pos *Pos
}

func containsExpression(s string) bool {
func ContainsExpression(s string) bool {
i := strings.Index(s, "${{")
return i >= 0 && i < strings.Index(s, "}}")
}

// ContainsExpression returns whether the string contains at least one ${{ }} expression.
func (s *String) ContainsExpression() bool {
return containsExpression(s.Value)
return ContainsExpression(s.Value)
}

func isExprAssigned(s string) bool {
Expand Down
2 changes: 1 addition & 1 deletion reusable_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (c *LocalReusableWorkflowCache) writeCache(key string, val *ReusableWorkflo
//
// Calling this method is thread-safe.
func (c *LocalReusableWorkflowCache) FindMetadata(spec string) (*ReusableWorkflowMetadata, error) {
if c.proj == nil || !strings.HasPrefix(spec, "./") || containsExpression(spec) {
if c.proj == nil || !strings.HasPrefix(spec, "./") || ContainsExpression(spec) {
return nil, nil
}

Expand Down
4 changes: 2 additions & 2 deletions rule_runner_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (rule *RuleRunnerLabel) tryToGetLabelsInMatrix(label *String, m *Matrix) []
if m.Rows != nil {
if row, ok := m.Rows[prop]; ok {
for _, v := range row.Values {
if s, ok := v.(*RawYAMLString); ok && !containsExpression(s.Value) {
if s, ok := v.(*RawYAMLString); ok && !ContainsExpression(s.Value) {
labels = append(labels, &String{s.Value, false, s.Pos()})
}
}
Expand All @@ -271,7 +271,7 @@ func (rule *RuleRunnerLabel) tryToGetLabelsInMatrix(label *String, m *Matrix) []
for _, combi := range m.Include.Combinations {
if combi.Assigns != nil {
if assign, ok := combi.Assigns[prop]; ok {
if s, ok := assign.Value.(*RawYAMLString); ok && !containsExpression(s.Value) {
if s, ok := assign.Value.(*RawYAMLString); ok && !ContainsExpression(s.Value) {
labels = append(labels, &String{s.Value, false, s.Pos()})
}
}
Expand Down

0 comments on commit 0b34b0f

Please sign in to comment.