From ea39ac385c67d4f9d680dd0c63a6557716a4c0ad Mon Sep 17 00:00:00 2001 From: Gerrit Date: Mon, 26 Feb 2024 12:50:13 +0100 Subject: [PATCH] Debug again. --- go.mod | 2 + .../github/actions/aggregate_releases.go | 9 ++++- pkg/webhooks/github/actions/issues_handler.go | 4 +- .../github/actions/issues_handler_test.go | 38 +++++++++---------- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/go.mod b/go.mod index 9df9515..2dba70d 100644 --- a/go.mod +++ b/go.mod @@ -25,6 +25,8 @@ require ( sigs.k8s.io/yaml v1.4.0 ) +require github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc + require ( github.com/Microsoft/go-winio v0.6.1 // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect diff --git a/pkg/webhooks/github/actions/aggregate_releases.go b/pkg/webhooks/github/actions/aggregate_releases.go index b9c2775..3f4d2fc 100644 --- a/pkg/webhooks/github/actions/aggregate_releases.go +++ b/pkg/webhooks/github/actions/aggregate_releases.go @@ -11,6 +11,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/atedja/go-multilock" + "github.com/davecgh/go-spew/spew" v3 "github.com/google/go-github/v57/github" "github.com/metal-stack/metal-lib/pkg/pointer" "github.com/metal-stack/metal-robot/pkg/clients" @@ -246,14 +247,18 @@ func isReleaseFreeze(ctx context.Context, client *v3.Client, number int, owner, return true, fmt.Errorf("unable to list pull request comments: %w", err) } + spew.Dump(comments) + for _, comment := range comments { comment := comment - if ok := searchForCommandInComment(pointer.SafeDeref(comment.Body), IssueCommentReleaseFreeze); ok { + spew.Dump(comment) + + if ok := searchForCommandInBody(pointer.SafeDeref(comment.Body), IssueCommentReleaseFreeze); ok { return true, nil } - if ok := searchForCommandInComment(pointer.SafeDeref(comment.Body), IssueCommentReleaseUnfreeze); ok { + if ok := searchForCommandInBody(pointer.SafeDeref(comment.Body), IssueCommentReleaseUnfreeze); ok { return false, nil } } diff --git a/pkg/webhooks/github/actions/issues_handler.go b/pkg/webhooks/github/actions/issues_handler.go index 202c3a6..7fc4e3b 100644 --- a/pkg/webhooks/github/actions/issues_handler.go +++ b/pkg/webhooks/github/actions/issues_handler.go @@ -84,7 +84,7 @@ func (r *IssuesAction) HandleIssueComment(ctx context.Context, p *IssuesActionPa return nil } - if ok := searchForCommandInComment(p.Comment, IssueCommentBuildFork); ok { + if ok := searchForCommandInBody(p.Comment, IssueCommentBuildFork); ok { err := r.buildForkPR(ctx, p) if err != nil { return err @@ -138,7 +138,7 @@ func (r *IssuesAction) buildForkPR(ctx context.Context, p *IssuesActionParams) e return nil } -func searchForCommandInComment(comment string, want IssueCommentCommand) bool { +func searchForCommandInBody(comment string, want IssueCommentCommand) bool { for _, line := range strings.Split(comment, "\n") { line = strings.TrimSpace(line) diff --git a/pkg/webhooks/github/actions/issues_handler_test.go b/pkg/webhooks/github/actions/issues_handler_test.go index bc14cdd..71d0841 100644 --- a/pkg/webhooks/github/actions/issues_handler_test.go +++ b/pkg/webhooks/github/actions/issues_handler_test.go @@ -6,34 +6,34 @@ import ( "github.com/google/go-cmp/cmp" ) -func Test_searchForCommandInComment(t *testing.T) { +func Test_searchForCommandInBody(t *testing.T) { tests := []struct { - name string - comment string - search IssueCommentCommand - want bool + name string + body string + search IssueCommentCommand + want bool }{ { - name: "find in single line", - comment: "/freeze", - search: IssueCommentReleaseFreeze, - want: true, + name: "find in single line", + body: "/freeze", + search: IssueCommentReleaseFreeze, + want: true, }, { - name: "no match", - comment: "/foo", - search: IssueCommentReleaseFreeze, - want: false, + name: "no match", + body: "/foo", + search: IssueCommentReleaseFreeze, + want: false, }, { - name: "find with strip", - comment: " /freeze ", - search: IssueCommentReleaseFreeze, - want: true, + name: "find with strip", + body: " /freeze ", + search: IssueCommentReleaseFreeze, + want: true, }, { name: "find in multi line", - comment: `Release is frozen now. + body: `Release is frozen now. /freeze `, search: IssueCommentReleaseFreeze, @@ -42,7 +42,7 @@ func Test_searchForCommandInComment(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got := searchForCommandInComment(tt.comment, tt.search) + got := searchForCommandInBody(tt.body, tt.search) if diff := cmp.Diff(got, tt.want); diff != "" { t.Errorf("diff: %s", diff) }