Skip to content

Commit

Permalink
escape tfc command check for -e --allow_empty_runn
Browse files Browse the repository at this point in the history
Signed-off-by: Ken Ng <[email protected]>
  • Loading branch information
wernken-ng committed Sep 5, 2023
1 parent 5eb0f84 commit 41f4a5d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion pkg/comment_actions/parsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,34 @@ type CommentArgs struct {
Rest []string
}

func Contains(s []string, str string) bool {
existedOnce := false
for _, v := range s {
if v == str {
existedOnce = true
}
}

return existedOnce
}

func ParseCommentCommand(noteBody string) (*CommentOpts, error) {
comment := strings.TrimSpace(strings.ToLower(noteBody))
words := strings.Fields(comment)
escapeKeyword := []string{"-e", "--allow_empty_run"}

if len(words) == 0 {
return nil, ErrNoNotePassed
}

if len(words)%2 != 0 {
isEscaped := false
for _, a := range escapeKeyword {
if Contains(words, a) {
isEscaped = true
}
}

if len(words)%2 != 0 && !isEscaped {
log.Debug().Str("comment", comment[0:10]).Msg("not a tfc command")
return nil, ErrNotTFCCommand
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/tfc_api/api_driven_runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c *TFCClient) CreateRunFromSource(ctx context.Context, opts *ApiRunOptions
tfVersion = tfe.String(opts.TFVersion)
tfPlanOnly = tfe.Bool(true)
}

if opts.AllowEmptyRun {
tfAllowEmptyApply = tfe.Bool(true)
}
Expand Down

0 comments on commit 41f4a5d

Please sign in to comment.