From 45af81772ccee3f3b8b23e2c78ec20131bb1f6d1 Mon Sep 17 00:00:00 2001 From: Ronen Lubin Date: Sun, 18 Feb 2024 16:10:40 +0200 Subject: [PATCH] test pr --- atlasaction/action.go | 16 ++++++++++++++-- .../migrations_destructive/20230925192914.sql | 1 + .../testdata/migrations_destructive/atlas.sum | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/atlasaction/action.go b/atlasaction/action.go index 13cd3953..aaf50024 100644 --- a/atlasaction/action.go +++ b/atlasaction/action.go @@ -285,13 +285,13 @@ func (g *githubAPI) addSuggestions(act *githubactions.Action, payload *atlasexec filePath := path.Join(payload.Env.Dir, file.Name) for _, report := range file.Reports { for _, s := range report.SuggestedFixes { - if err := g.commentSuggestion(event.PullRequestNumber, ghContext.SHA, filePath, s); err != nil { + if err := g.commentSuggestion(event.PullRequestNumber, event.SHA, filePath, s); err != nil { return err } } for _, d := range report.Diagnostics { for _, s := range d.SuggestedFixes { - if err := g.commentSuggestion(event.PullRequestNumber, ghContext.SHA, filePath, s); err != nil { + if err := g.commentSuggestion(event.PullRequestNumber, event.SHA, filePath, s); err != nil { return err } } @@ -420,6 +420,7 @@ func (g *githubAPI) commentSuggestion(prID int, commitID, filePath string, sugge if err != nil { return err } + fmt.Println("body sent:", string(buf)) url := fmt.Sprintf("%v/repos/%v/pulls/%v/comments", g.baseURL, g.repo, prID) req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(buf)) if err != nil { @@ -466,11 +467,22 @@ type githubTriggerEvent struct { HeadCommit struct { URL string `mapstructure:"url"` } `mapstructure:"head_commit"` + SHA string `mapstructure:"sha"` PullRequestNumber int `mapstructure:"number"` } func triggerEvent(ghContext *githubactions.GitHubContext) (*githubTriggerEvent, error) { var event githubTriggerEvent + pr := ghContext.Event["pull_request"] + if pr != nil { + prMap, ok := pr.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("failed to convert pull_request to map[string]interface{}") + } + for k, v := range prMap { + fmt.Printf("%s: %v\n", k, v) + } + } if err := mapstructure.Decode(ghContext.Event, &event); err != nil { return nil, fmt.Errorf("failed to parse push event: %v", err) } diff --git a/atlasaction/testdata/migrations_destructive/20230925192914.sql b/atlasaction/testdata/migrations_destructive/20230925192914.sql index 853c1ad6..f5abfe79 100644 --- a/atlasaction/testdata/migrations_destructive/20230925192914.sql +++ b/atlasaction/testdata/migrations_destructive/20230925192914.sql @@ -1 +1,2 @@ +-- drop table t1; drop table t1; diff --git a/atlasaction/testdata/migrations_destructive/atlas.sum b/atlasaction/testdata/migrations_destructive/atlas.sum index 94a06804..455e7a4e 100644 --- a/atlasaction/testdata/migrations_destructive/atlas.sum +++ b/atlasaction/testdata/migrations_destructive/atlas.sum @@ -1,3 +1,3 @@ -h1:jw+3IjeTY+1ngJYKRc/Ddq8hJkBWpVRnF8qS61zspJg= +h1:H/F2w8bIg7dfvQR4lLFOLhf+bZLwlCAPXMBVJb1VKLc= 20230922132634_init.sql h1:Q+dJaaJDja1u1qEni6E0SfC4dMXhHgW2F1ybAtgcgeE= -20230925192914.sql h1:2YTCgLJQ5t3t71z3zGGRNSaWBItjTXF9zEcQICGIZkc= +20230925192914.sql h1:45yfGQkVGdeGJNj/MEF9xtJdvtW2dWnpvMIhsVjIkiA=