Skip to content

Commit

Permalink
remove ErMptTFCCommand checking
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 6, 2023
1 parent 41f4a5d commit a125af8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 30 deletions.
24 changes: 0 additions & 24 deletions pkg/comment_actions/parsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,14 @@ 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
}

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
}

opts := &CommentOpts{
TriggerOpts: &tfc_trigger.TFCTriggerOptions{},
}
Expand Down
7 changes: 1 addition & 6 deletions pkg/comment_actions/parsing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,11 @@ func TestParseCommentCommand(t *testing.T) {
Command: "plan",
},
}, nil, "simple plan with version"},
{"tfc plan -w -v 1.1.8",
nil,
ErrNotTFCCommand,
"not a valid command",
},
}

for _, tc := range tcs {
t.Run(tc.testName, func(t *testing.T) {
opts, err := ParseCommentCommand(tc.noteBody)
opts, err := ParseCommentCommand(tc.noteBody)
assert.Equal(t, tc.expectedOpts, opts, tc.testName)
assert.ErrorIs(t, err, tc.e, tc.testName)
})
Expand Down

0 comments on commit a125af8

Please sign in to comment.