Skip to content

Commit

Permalink
Debug again.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed Feb 26, 2024
1 parent bbda194 commit ea39ac3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions pkg/webhooks/github/actions/aggregate_releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/webhooks/github/actions/issues_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
38 changes: 19 additions & 19 deletions pkg/webhooks/github/actions/issues_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down

0 comments on commit ea39ac3

Please sign in to comment.