Skip to content

Commit

Permalink
handle multiline comments
Browse files Browse the repository at this point in the history
Signed-off-by: mikeee <[email protected]>
  • Loading branch information
mikeee committed Oct 8, 2023
1 parent 21fd3e0 commit e1697f3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .github/workflows/dapr-bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ func NewBot(ghClient *github.Client) *Bot {
func (b *Bot) HandleEvent(ctx context.Context, event Event) (res string, err error) {
commentBody := event.IssueCommentEvent.Comment.GetBody()

command := strings.Split(commentBody, " ")[0]
// split the comment after any potential new lines
newline := strings.Split(strings.ReplaceAll(commentBody, "\r\n", "\n"), "\n")[0]

command := strings.Split(newline, " ")[0]

if command[0] != '/' {
return "no command found", err
}
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/dapr-bot/bot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ func TestHandleEvent(t *testing.T) {
assert.NotEmpty(t, res)
})

t.Run("handle valid (longer body) event", func(t *testing.T) {
tc := testClient{
resp: &github.Response{Response: &http.Response{StatusCode: http.StatusOK}},
}
testBot.issueClient = &tc
ctx := context.Background()
var testEventCopy Event
errC := copier.CopyWithOption(&testEventCopy, &testEvent, copier.Option{DeepCopy: true})
if errC != nil {
t.Error(errC)
}
testEventCopy.IssueCommentEvent.Comment.Body = github.String("/assign \r \ntest body")
res, err := testBot.HandleEvent(ctx, testEventCopy)
assert.NoError(t, err)
assert.NotEmpty(t, res)
})

t.Run("handle unable to assign", func(t *testing.T) {
tc := testClient{
resp: &github.Response{Response: &http.Response{StatusCode: http.StatusNotFound}},
Expand Down

0 comments on commit e1697f3

Please sign in to comment.