Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/provider/github/parse_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ func (v *Provider) processEvent(ctx context.Context, event *info.Event, eventInt
return nil, fmt.Errorf("no github client has been initialized, " +
"exiting... (hint: did you forget setting a secret on your repo?)")
}
if gitEvent.GetAction() != "created" {
v.Logger.Debugf("only newly created comment is supported, received: %s, skipping", gitEvent.GetAction())
return nil, nil
}
processedEvent, err = v.handleIssueCommentEvent(ctx, gitEvent)
if err != nil {
return nil, err
Expand Down
22 changes: 19 additions & 3 deletions pkg/provider/github/parse_payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

"github.com/google/go-github/v84/github"
"github.com/jonboulle/clockwork"
"go.uber.org/zap"
zapobserver "go.uber.org/zap/zaptest/observer"
"gotest.tools/v3/assert"
"gotest.tools/v3/env"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -462,6 +464,7 @@ func TestParsePayLoad(t *testing.T) {
objectType string
gitopscommentprefix string
wantRepoCRError bool
wantLogSnippet string
}{
{
name: "bad/unknown event",
Expand Down Expand Up @@ -744,6 +747,14 @@ func TestParsePayLoad(t *testing.T) {
},
},
},
{
name: "good/issue_comment_not_from_created_skip",
payloadEventStruct: github.IssueCommentEvent{Action: github.Ptr("deleted")},
eventType: "issue_comment",
triggerTarget: "pull_request",
githubClient: true,
wantLogSnippet: "only newly created comment is supported",
},
{
name: "good/issue comment",
eventType: "issue_comment",
Expand Down Expand Up @@ -1390,11 +1401,12 @@ func TestParsePayLoad(t *testing.T) {
}

stdata, _ := testclient.SeedTestData(t, ctx, tdata)
logger, _ := logger.GetLogger()
observer, logCatcher := zapobserver.New(zap.DebugLevel)
fakelogger := zap.New(observer).Sugar()
run := &params.Run{
Clients: clients.Clients{
PipelineAsCode: stdata.PipelineAsCode,
Log: logger,
Log: fakelogger,
Kube: stdata.Kube,
},
}
Expand Down Expand Up @@ -1477,7 +1489,7 @@ func TestParsePayLoad(t *testing.T) {

gprovider := Provider{
ghClient: ghClient,
Logger: logger,
Logger: fakelogger,
pacInfo: &info.PacOpts{
Settings: settings.Settings{SkipPushEventForPRCommits: tt.skipPushEventForPRCommits},
},
Expand All @@ -1496,6 +1508,10 @@ func TestParsePayLoad(t *testing.T) {
return
}
assert.NilError(t, err)
if tt.wantLogSnippet != "" {
assert.Assert(t, logCatcher.FilterMessageSnippet(tt.wantLogSnippet).Len() > 0,
"expected debug log containing %q but got none", tt.wantLogSnippet)
}
// If shaRet is empty, this is a skip case (push event for PR commit)
// In this case, ret should be nil
if tt.shaRet == "" {
Expand Down
Loading